yamlscript

Ingy döt Net 2023-08-09T12:41:35.576629Z

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.

👍 1
Ingy döt Net 2023-08-09T12:53:00.424079Z

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

delon 2023-08-09T19:51:54.489809Z

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.

delon 2023-08-09T19:54:47.860029Z

It keeps things simple while still allowing you to extend the reader https://clojure.org/reference/reader#_dispatch

Ingy döt Net 2023-08-09T12:53:48.475729Z

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.

delon 2023-08-09T19:57:16.923689Z

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

delon 2023-08-09T19:58:11.917699Z

I would agree starting with YAML has some nice advantages

Ingy döt Net 2023-08-09T15:26:50.723619Z

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)
    "big"
    "small"))
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 )
  val:
  - seq: 1
    clj: ( 'if (third key) (first val) )
  - seq: 2 
    clj: ( 'if (third key) (first val) (second val) )

Ingy döt Net 2023-08-09T15:33:17.954139Z

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 Net 2023-08-09T15:38:31.817629Z

without the ys macros you can still do:

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

Ingy döt Net 2023-08-09T15:40:16.051829Z

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 Net 2023-08-09T15:58:39.155099Z

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 Net 2023-08-09T15:59:23.867229Z

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

Ingy döt Net 2023-08-09T15:43:28.593539Z

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.

delon 2023-08-09T20:00:58.935119Z

That makes sense

delon 2023-08-09T20:01:34.356589Z

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

delon 2023-08-09T20:02:24.041809Z

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

delon 2023-08-09T20:03:02.859719Z

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

delon 2023-08-09T20:03:48.633049Z

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

delon 2023-08-09T20:05:02.842799Z

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.

delon 2023-08-09T20:09:38.813749Z

https://en.wikipedia.org/wiki/M-expression

delon 2023-08-09T20:11:18.972769Z

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

delon 2023-08-09T23:15:54.188869Z

Perhaps you could think of YAML as y-expressions

Ingy döt Net 2023-08-10T01:06:04.182649Z

@delon https://people.csail.mit.edu/jrb/Projects/dexprs.pdf looks interesting. I've added it to my reading list.

Ingy döt Net 2023-08-10T01:11:14.012879Z

Have you read about yes-expressions? https://metacpan.org/dist/YAMLScript/view/lib/YAMLScript.pod#ysexprs-%22Yes-Expressions%22

delon 2023-08-10T02:08:19.533429Z

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

delon 2023-08-10T02:09:00.543789Z

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

delon 2023-08-10T02:10:28.699899Z

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

delon 2023-08-10T02:10:41.991299Z

🐫

Ingy döt Net 2023-08-09T15:49:34.790199Z

(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)

David Hoppe 2023-08-09T20:42:39.761189Z

@hopasaurus has joined the channel

Ingy döt Net 2023-08-09T01:50:59.210709Z

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

hifumi123 2023-08-09T02:30:23.628799Z

a good intro to reader macros in lisp is https://gist.github.com/chaitanyagupta/9324402

Ingy döt Net 2023-08-09T12:57:05.710429Z

From that link I got to http://www.paulgraham.com/onlisptext.html which has a downloadable PDF of On Lisp 🙂

delon 2023-08-09T19:44:43.196759Z

Nice

delon 2023-08-09T19:47:10.772679Z

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.

hifumi123 2023-08-09T02:30:33.291809Z

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