anko / eslisp

un-opinionated S-expression syntax and macro system for JavaScript
ISC License
528 stars 31 forks source link

`()` throws compilation error #32

Closed lhorie closed 8 years ago

lhorie commented 8 years ago

In eslisp, you can use () in the (for () () ()) special form to create an infinite loop for (;;) {}

But if you use () in an expression, it throws a compilation error, e.g. (+ 1 ()) -> BinaryExpression right member must be an expression node.

Typically () evaluates to nil, so I'd expect the output to be 1 + null with no compiler error.

It'd still need to keep current behavior in for-loops, since for (;;) {} is a different thing from for (null; null; null) {}.

Alternatively, () could always mean null, and there would be another way of expressing empty expressions in for loops.

anko commented 8 years ago

Agreed; ()null would be neat. It should mean something, and null is least surprising.

The for macro could just do its own detection of when its first 3 arguments are empty lists.

vendethiel commented 8 years ago

IIRC, it is in common lisp.