215 points · by codecurve · 11y ago · 76 comments
In all seriousness, I worked with a bright guy who was a lot of fun to work with, but every once in a while his exuberance for this sort of thing would find itself in code that other people had to read/maintain. One particular example, he implemented a small subset of Lisp encoded into PHP arrays and it was used throughout some test code.
He effectively proved you could write PHP in a Lisp style and that PHP programmers overwhelmingly hate PHP flavored Lisp.
>> Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.
https://github.com/pusher/pusher-js/blob/2.2/src/defaults.js...
parser in https://github.com/pusher/pusher-js/blob/2.2/src/strategies/...
The main reason was that we were thinking about helping clients with server-supplied connection strategies. We could gather some metrics and tell the client in advance that, for example, WebSockets won't work due to some network issues. We also thought it could be useful for orchestrating migrations and working around potential load balancing issues. Injecting JavaScript was out of question, so I wrote this JSON DSL for connection strategies.
We haven't done that and it's probably never going to happen. The Internet has moved on, we dropped support for some ancient browsers, connectivity has improved and we haven't really felt a need for that feature, to be honest.
I agree that at the moment it's unnecessary.
x=filter(a,lambda(({ 'o }),
({ (#'>),
({ (#'call_other),
({ (#'environment),'o }),
"query_level"
}),
WL_APPRENTICE
})));
[1]: https://en.wikipedia.org/wiki/LPC_(programming_language)Before the bracket-syntax for arrays, this would have been awful to maintain.
(It's also worth noting that theme() hasn't worked this way since 2011; it now takes a more PHP-style associative array of named options.)
(Disclaimer: I’m used to Lisp so I’m not really the audience whose opinion matters. But I’m sure I would’ve benefited from reading this earlier. Skimmed it, and am now halfway through a more careful read.)
Images can be great aids in understanding text and making abstract concepts concrete. Also, in many cases the usual metaphor/simile rules apply. For instance, in the phrase he's "fast as a bolt of lightning" we can imagine the speed of the runner and it helps us envision how he "flashes" by opponents. In this case both concepts are known i.e. lighting and fast, but new descriptive meaning is created through the use of simile. Similarly, metaphor takes two known concepts and combines them to reveal a new concept. An example of metaphor, would be "he's an emotional rollercoaster", we know what emotional is and how a rollercoaster behaves, this gives us new insight into the persons high and low spiraling personality.
Essentially, I think good images interact just like simile and metaphor with a text, enhancing, extending, and clarifying concepts. If you go back now and look at your images, I think you'll see that they actually reflect rather verbatim what the text contains, only minimally extend or clarify the text, and at times might make it more confusing (how do turtles enhance our understanding of expressions?). So for these reasons, I found them to be distracting and not helpful, as nice as they actually appear graphically :)
Nice post btw :)
There is something special about special forms. A basic set of special forms is needed and can't be implemented as macros.
It doesn't have to be built into the language; it could be a macro based on COND or even on WHEN/UNLESS. But…
> A basic set of special forms is needed and can't be implemented as macros.
One has to have some special forms in order to build everything else as macros. And in practice, of course, there can be some big efficiency gains to having lots of special forms vice having only a few and lots of macrology.
In Common Lisp IF is built in and COND is a macro. One of the conditionals needs to be built-in.
http://www.lispworks.com/documentation/HyperSpec/Body/s_if.h...
> One has to have some special forms in order to build everything else as macros.
For conditionals, one conditional needs to be there, into which the other macro-based conditionals can be expanded.
> And in practice, of course, there can be some big efficiency gains to having lots of special forms vice having only a few and lots of macrology.
Not really. Common Lisp has a minimum of special forms and usually has some of the faster Lisp implementations.
That's actually not true. IF can be implemented in terms of LAMBDA.
(defun _true (then else) then)
(defun _false (then else) else)
(defmacro _if (condition then else)
`(funcall (funcall (function ,condition) (lambda () ,then) (lambda () ,else))))
? (_if _true (print 123) (print 456))
123
123
? (_if _false (print 123) (print 456))
456
456
?(Also note that Lisp macros don't have to be all written in Lisp. They are just expander functions. When you're bootstrapping a Lisp, you can write macros in the bootstrapping language. So the chicken-and-egg problem of "how do you write the first macros if there are no special forms" doesn't exist. You write the raw functions in assembly, or C or whatever, and register them as macro-expanders.)
[0] : https://github.com/kanaka/miniMAL [1] : https://github.com/kanaka/mal/tree/master/miniMAL [2] : https://github.com/kanaka/mal
Hy does this for Python (except that its initial implementation started from a parser). It essentially becomes a syntax for manipulating Python ASTs as plain old data-structures instead of classes with terrible interfaces. It's actually a great way to become intimate with the inner workings of your host language.
It's funny how far you can get by sprinkling a few parentheses around.
https://github.com/smizell/geneva
It is Lisp in JSON. I did it for fun, but thought it would a cool way to send instructions across the wire from the server to the client and back. Imagine validation rules that could be ready in any language with really very little parsing instructions.
https://github.com/refractproject/refract-spec/blob/master/r...
We use it very similarly to how you would with Lisp, where the "element" may be a function of sorts.
Still, seems very accessible and useful to people who don't feel like going through the trouble of learning/building a "real" lisp but will read a blog post.
I guess programmers of those languages must desperately want to escape to another language.
My solution is going to be turning these rules into something that looks like Python, and feed each line to eval(). I reckon that will make 90% of the rule evaluation engine, which is my brittler code, to just disappear.
Sometimes the most obvious choice is also the best.
No, none of these rules are input by users. All of them come from our repo. We're safe and good.Plumb is certainly not a Lisp though; it's actually a syntax for lambda calculus with de Bruijn indices, which just-so-happens to embed easily in common scripting languages (PHP, JS, Python, etc.).
Keep them coming.
For some of us, every week is Lisp week grin