4 ms·
Lisp is probably the only language where eval makes sense. If you need to concatenate strings together to create "code", you're doing it wrong.
by AlexanderDhoore 12y ago
Lisp is probably the only language where eval makes sense. If you need to concatenate strings together to create "code", you're doing it wrong.
- Zikes 12y agoI've seen it used to decent effect in Javascript templating libraries.
- agumonkey 12y agoEven more so in proto-spreadsheets.
- icebraining 12y agoWhat you mean is that it only makes sense in homoiconic languages; Lisp is not the only one[1]. In particular, there's Julia, now[2]. [1] http://en.wikipedia.org/wiki/Homoiconicity#Examples http://en.wikipedia.org/wiki/Homoiconicity#Examples [2] http://docs.julialang.org/en/latest/manual/metaprogramming/ http://docs.julialang.org/en/latest/manual/metaprogramming/
- kazinator 12y agoThat reminds me of the ancient Infix module for Common Lisp. [1]> (load "infix") T [2]> (let ((a 1) (b 2) (c 3)) #i(a*b+c)) 5 [3]> '#i(a*b+c) (+ (* A B) C) Like the colon in Julia, we can quote the infix (#i) expression, to reveal its AST. Infix URL: http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/code/syntax/infix/infix.cl http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/l... Infix has f(x,y) type function calls and a[i,j] type array referencing and whatnot. It's not really homoiconicity because the AST doesn't resemble the language being quoted. The AST and its printed notation are homoiconic; the LALR(1) statement/expression/infix cruft layered on it arguably isn't.
- innguest 12y agoFor adding infix to s-exps, "sweet expressions" are a much cleaner approach: http://www.dwheeler.com/readable/ http://www.dwheeler.com/readable/
- kazinator 12y agoI'm sure I've seen that before. Anyway, it's destined for the same dustbin as infix.cl. These things have value in showing "see, you can do this, but Lisp programmers don't actually use it". Before infix.cl and Readable, back in the 1970's, there was also something called CGOL[1]. This was described in a 1976 MIT paper by Pratt R. Vaughan titled CGOL: An Alternative External Representation for LISP Users. And, of course, Lisp wasn't supposed to wear its S-expression underwear on the outside in the first place; M-expressions were supposed to be used for programming. [1] http://en.wikipedia.org/wiki/CGOL http://en.wikipedia.org/wiki/CGOL
- dllthomas 12y agoYou could assemble an AST in a non-homoiconic language. This has some added complexity over something like Lisp to be sure, but it doesn't have most of the downsides of concatenating strings.
- icebraining 12y agoYeap. An example in Python: http://eli.thegreenplace.net/2009/11/28/python-internals-working-with-python-asts/ http://eli.thegreenplace.net/2009/11/28/python-internals-wor...
- dllthomas 12y agoVery nice. Template Haskell takes a similar approach, though is (usually) not run-time.