2pEXgD0fZ5cF 1 day ago

Janet looks really interesting. Especially with how easy to embed it is.

If I understand it correctly creating DSLs in it should also be very easy with its macro and PEG feature?

3
afranchuk 21 hours ago

Writing DSLs is very easy, and fun! The PEG grammars are very elegant to build up. I wrote a language for programmatic recipes (think scaling, unit conversion, etc) with it and it was a delight. I'd provide an example but I haven't taken the time to write a README so I haven't published it publicly yet.

2pEXgD0fZ5cF 20 hours ago

Hey that's cool. Are you willing to instead share an example snippet of what the DSL itself looks like?

afranchuk 14 hours ago

Here's an excerpt (which is in a map passed to peg/compile) for numeric parsing:

    :nonzero-int (* (range "19") (any (range "09")))
    :int (+ "0" :nonzero-int)
    :decimal (cmt (* (? (<- :int)) "." (<- (some (range "09")))) ,parse-decimal)
    :fraction (cmt (\* (? (\* (number :nonzero-int) :s+)) (number :nonzero-int)
 "/" (number :nonzero-int)) ,parse-fraction)
    :integer (cmt (number :nonzero-int) ,parse-integer)
    :num (+ :decimal :fraction :integer)

petee 21 hours ago

I'm pretty new to it, but from what I've seen the answer is yes. And while I haven't wrote any macros yet I think PEGs are fantastic, and sooo readable. Their website has an example PEG to read Janet source - https://janet-lang.org/docs/syntax.html#Grammar

Embedding is really easy, as is writing c modules. You can link shared, or use an amalgamated c file. Check out https://janet-lang.org/capi/embedding.html

Honestly I'm having just as much fun learning Janet as I am writing C modules and embeddings; Janet all the things!

giraffe_lady 18 hours ago

It's an incredible lua replacement for embedding. A lot of the time for an embedded scripting language you're defining a DSL which bare lua is fairly poorly suited to. And you lose the tininess and simplicity of the embedding if you're having to cram PCRE and shit in there too.

Janet basically just copies lua's C interop because it's the best part of lua. And then with PEGs and a solid macro system you're in a much better position for scripting, or defining a scripting environment, or a configuration DSL, or whatever you wanted a non-C language for.