Fork me on GitHub
Ingy döt Net01:08:59

Interesting. I just started reading a book about common lisp today. I'll keep that in mind

Ingy döt Net12:08:05

From that link I got to which has a downloadable PDF of On Lisp 🙂


The kinds of macros you're talking about are a bit different than reader macros in that (to my understanding) reader macros operate at the character level. But, they'd similar in that they'd operate at the syntax level not semantically as normal macros do. Maybe one way of thinking about it would be--reader macros extend the reader and normal macros extend the compiler or evaluator.


it introduces reader macros by implementing a JSON parser in the reader itself

Ingy döt Net12:08:35

I think YS macros will be reader macros by definition because YS itself is just a reader of an alternate syntax for Clojure, one that tries to make use of the best parts of YAML in the context of a Lisp. All of the code for YS translation takes place in a module called YAMLScript::Reader for the Perl implementation (over Lingy) and yamlscript.reader for the new Clojure implementation being worked on. The Perl YS is more of a real reader because it's output is a Lingy AST, where for now the Clojure implementation will "cheat" and just transform YS to Clojure.

👍 2
Ingy döt Net12:08:00

I am familiar with Clojure reader macros from Lingy. Regexes and lambdas are reader macros, yes?


Yes, with Clojure the reader is extensible through dispatch macros, but they don't have full access to the reader the way reader macros do in Common Lisp.


It keeps things simple while still allowing you to extend the reader

Ingy döt Net12:08:48

I've read that Clojure doesn't provide ways for people to make their own reader macros, iirc to keep Clojure variants from abounding. YS will promote making your own (reader) macros, but I think that's ok because YS is already restricted to needing to be valid YAML, and it's the clumsiness of writing code as ASTs in YAML that these macros help alleviate.


You can write you're own dispatch reader macros, but as I mentioned they're more limited that full reader macros in Common Lisp.


I would agree starting with YAML has some nice advantages

Ingy döt Net15:08:50

Playing around a bit... This YS:

a =: 123
b =:
  if (a > 100):
  - "big"
  - "small"
has ys macro syntax for def and if that reads the same as this clojure:
(def a 123)
(def b 
  (if (> a 100)
and they could be defined in YS with something like:
defsyn def:
  key: ( sym sp+ "=" )
  clj: ( 'def (first key) val)

defsyn if:
  key: ( "if" sp+ ysexpr )
  - seq: 1
    clj: ( 'if (third key) (first val) )
  - seq: 2 
    clj: ( 'if (third key) (first val) (second val) )

Ingy döt Net15:08:17

The processing steps are something like: • if we are a mapping pair • match the key against the list of patterns like • string "if" + 1 or more spaces + an expression • if the key matches • generate clojure based on the relevant parts of the key and the value

Ingy döt Net15:08:31

without the ys macros you can still do:

- a
- 123
- b
- if:
  - (a > 100)
  - "big"
  - "small"
in basic ys, the macros just offer other styles to write things in

Ingy döt Net15:08:16

There's currently about a dozen of these special cases, but I realized that libraries will want their own, and then programmers will want their own as well

Ingy döt Net15:08:39

It occurs to me that this defsyn syntax is itself a special macro syntax and should probably be first thought out in its explicit functions.

Ingy döt Net15:08:23

or else it wil need to be a YS "special form" 🙂

Ingy döt Net15:08:28

It's important (I think) to keep in mind that YAMLScript's goal is not to save Clojure from Lisp. It's to introduce Clojure to YAML and to make YAML programmable. Those goals can be easily fairly easily accomplished but if the result looks like a turd, nobody will be interested.


That makes sense


In a similar way you may find some inspiration Dylan and Elixir


Dylan and Elixir both are languages that behind the scenes are Lisp, but have a more conventional syntax on-top.


Dylan even more so than Elixir, but they both start there


The folks behind Dylan even wrote a paper about it, they call them d-expressions, in a similar vein as s-expressions


And Elixir's syntax was evidently inspired by the idea that John McCarthy originally had for what he called m-expressions that would be translated into the underlying s-expressions.


Dylan's also a language that was evidently influential on Clojure, so it'd be interesting to see some of that come full circle.


Perhaps you could think of YAML as y-expressions


I did briefly, but I have to admit I only scanned the pod docs 😅


I’ve been a little too busy lately (at least that’s my excuse) 😂


That’s certainly a better name and very perly to my ear

Ingy döt Net15:08:34

(As you might already know) any YAMLScript node (including the root node) can be expressed as just clojure (as long as it is also valid YAML)