4 ms·
Does anybody have a few examples of DSLs people make in a lisp (ideally clojure because I have worked with it a tad)? I've seen plenty of cases where people mak
by bpicolo 10y ago
Does anybody have a few examples of DSLs people make in a lisp (ideally clojure because I have worked with it a tad)? I've seen plenty of cases where people make a pseudo-dsl via optional arguments, but not seen this so-oft mentioned "yeah we just wrote a dsl for it because lisp" sort of deal.
- GavinMcG 10y agohttp://beautifulracket.com/appendix/domain-specific-languages.html http://beautifulracket.com/appendix/domain-specific-language...
- bpicolo 10y agoHmm, I guess I have seen datascript / datalog. My main question is more about how many articles seem to suggest that it's basically par-for-the-course in lisp programming to just make a DSL in your projects, so was wondering when that might actually occur.
- homerowilson 10y agoAs mentioned in this list, Ihaka and Gentleman's R implementation of S begain like this but quickly grew into a larger system. R's source code today is still full of lispisms.
- coliveira 10y agoMaxima CAS is implemented as a DSL on top of Common Lisp. It is one of the best environments for symbolic math (other than commercial products such as Mathematica).
- codemac 10y agoA significant portion of naughty dog games were written in a dialect of scheme that was implemented in CL. The cool feature being rlet, register let, that allowed programmers to write a section of code in lisp that referenced specific registers .
- samth 10y agoMatthew Butterick (the author of Beautiful Racket linked in another reply) is solving this year's Advent of Code, all as DSLs: https://github.com/mbutterick/aoc-racket https://github.com/mbutterick/aoc-racket
- kazinator 10y agoThe TXR Lisp dialect provides an awk macro that implements a language closely resembling Awk in its structure and semantics. For example, write the third field of every record (if the field exists) into `file.{recnum}`: (awk ([f 2] (-> `file.@nr` (prn [f 2])))) The manual contains a translation of all of the Awk examples from the POSIX standard: http://www.nongnu.org/txr/txr-manpage.html#N-03D16283 http://www.nongnu.org/txr/txr-manpage.html#N-03D16283 The (-> name form ...) syntax above is scoped to the surrounding awk macro. Like in Awk, the redirection is identified by string. If multiple such expressions appear with the same name, they denote the same stream (within the lexical scope of the awk macro instance to which they belong). These are implicitly kept in a hash table. When the macro terminates (normally or via non-local jump like an exception), these streams are all closed.
- sedachv 10y agoHere is an example of a DSL I made in Common Lisp for doing compile-time URL checking in a web application: http://carcaddar.blogspot.com/2008/11/compile-time-inter-application-uri-link.html http://carcaddar.blogspot.com/2008/11/compile-time-inter-app... Common Lisp makes it easy to compose DSLs so it was trivial to apply the URL checking DSL to the JavaScript generating DSL (Parenscript) and have the browser-side code checked at compile time as well. Another good example is CLiki2: https://github.com/vsedach/cliki2/blob/master/src/readtable.lisp https://github.com/vsedach/cliki2/blob/master/src/readtable.... The HTML template system is a small DSL on top of a string interpolation library (vs a 10,000 line templating library that can't even get HTML attributes right). It was also trivial to make it use streams to eliminate string allocation/copying.
- yogthos 10y agoA few good examples in Clojure would be: core.async https://github.com/clojure/core.async https://github.com/clojure/core.async core.match https://github.com/clojure/core.match https://github.com/clojure/core.match Compojure https://github.com/weavejester/compojure https://github.com/weavejester/compojure Midje https://github.com/marick/Midje https://github.com/marick/Midje Korma http://sqlkorma.com/ http://sqlkorma.com/
- bpicolo 10y agoSerious question: Why are these considered "DSLs"? To me, these are just libraries with functions. Are they considered DSLs just because Lisps are basically an AST to begin with? Because when I think of a DSL, I think of something like SQL, or HTML, that is definitively different syntax, with it's own interpreter, for a specific purpose. Function calls in Clojure doesn't match with the definition of what's in my head here. This is sort of what I was getting at in my original comment.