Skip to content

Commit

Permalink
Better
Browse files Browse the repository at this point in the history
  • Loading branch information
Seggan committed Jan 8, 2024
1 parent de0603d commit 145e9c6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
Clojure, XML edition.

```xml
<fn>[arg]
<println><q tag="+">arg arg</q></println>
</fn>
<xclj>
<defn>x [a]
<println>a</println>
</defn>
<defn>main [arg]
<x>
<q tag="+">arg arg</q>
</x>
</defn>
</xclj>
```

## Semantics Bootcamp
Expand Down Expand Up @@ -39,6 +46,7 @@ Should you need to use a function that cannot be expressed as a valid XML tag na
$ java -jar xclj-uber.jar <input-file> args...
```

The input file should consist of a single function. The `args` will be passed to that function as an evaluated list.
The input file must have an `<xclj>` root tag. The function called must be called `main`.
All arguments are passed to the `main` function as a vector of evaluated strings.

This is a joke project, but if you happen to somehow find it useful, I'd love to hear about it.
9 changes: 6 additions & 3 deletions src/xclj/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

(defn -main [file & args]
(let [input (ByteArrayInputStream. (.getBytes (slurp file)))
xml (clojure.xml/parse input)
clj (first (convertToClojure xml))]
(println (apply (eval clj) (map read-string args)))))
xml (clojure.xml/parse input)]
(when (not= :xclj (:tag xml))
(throw (IllegalArgumentException. "Must have xclj root tag")))
(doseq [form (:content xml)]
(eval (first (convertToClojure form))))
(apply (resolve 'main) (map read-string args))))

0 comments on commit 145e9c6

Please sign in to comment.