3 ms·
One of the greatest lies that Lispers have is: "Lisp has no syntax". Syntax is defined as "the structure of statements in a computer language." What Lisp has,
by dmitriid 9y ago
One of the greatest lies that Lispers have is: "Lisp has no syntax". Syntax is defined as "the structure of statements in a computer language."
What Lisp has, and is, is a syntax to describe an AST. If you get the syntax wrong, your program won't run. And even that syntax isn't uniform across the various Lisps (some will throw in weird chars and constructs here and there to make dealing with common structures easier etc.)
It does make it somewhat easier to manipulate code as data if you wish to. And it does somewhat make reasoning about some parts of your code somewhat easier. Is it that good as it's glorified to be?
The author links to Korma as an example of the power of code as data, and macros:
(select users
(where {:active true})
(order :created)
(limit 5)
(offset 3))
:-\
To me, it's a chain of 5 functions which are neither shorter to write nor better than Java's jOOQ [1]:
create.select(a.FIRST_NAME, a.LAST_NAME, countDistinct(s.NAME))
.from(a)
.join(b).on(b.AUTHOR_ID.eq(a.ID))
.join(t).on(t.BOOK_ID.eq(b.ID))
.join(s).on(t.BOOK_STORE_NAME.eq(s.NAME))
.groupBy(a.FIRST_NAME, a.LAST_NAME)
.orderBy(countDistinct(s.NAME).desc())
.fetch();
Look, it even has a similar number of parentheses ;)
[1] Example from https://www.jooq.org/doc/3.10/manual-single-page/#sql-building https://www.jooq.org/doc/3.10/manual-single-page/#sql-buildi...
- kazinator 9y agoThat particular select instance could indeed just be an ordinary function, whereby the (where ...) and (order ...) are just evaluated argument expressions, also calling ordinary constructors for objects that influence the query. It doesn't really demonstrate the ability to manipulate syntax. Things start to get more interesting when some of the inputs need to be lambdas. Still, the sugaring of those can be in the arguments, and select can remain a function. Now suppose that a clause can, say, bind a lexical variable that a later clause can somehow usefully refer to; things like that.
- dmitriid 9y agoUnless I’m missing something everything you said applies to jOOQ code.
- mmjaa 9y agoOddly enough, this code is pretty much completely paste- compatible with Lua, too. (Except the ; of course ..)
- lispm 9y ago> One of the greatest lies that Lispers have is: "Lisp has no syntax". It's wrong, Lisp has a lot of syntax. > What Lisp has, and is, is a syntax to describe an AST. That's wrong, too. Lisp syntax does not describe an AST. > To me, it's a chain of 5 functions which are neither shorter to write nor better than Java's jOOQ [1]: That's not the point, the Lisp version is on another level: * it does not expose its implementation * the macro allows to translate this code at something like compile time The Java code is a bunch of function invocations which create a string. Usually at runtime.