Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

() throws compilation error #32

Closed
lhorie opened this issue Oct 22, 2015 · 2 comments
Closed

() throws compilation error #32

lhorie opened this issue Oct 22, 2015 · 2 comments
Labels

Comments

@lhorie
Copy link

lhorie commented Oct 22, 2015

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 anko added the idea label Oct 25, 2015
@anko
Copy link
Owner

anko commented Oct 25, 2015

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
Copy link

IIRC, it is in common lisp.

anko added a commit that referenced this issue Feb 6, 2016
Consider an ES6 object literal with a method that has empty arguments
and an empty body:

    {
      d() { }
    }

Before this commit, that would intuitively have been written as

    (object ('d ()))

which failed because the ('d ()) list has 2 elements, which the logic
attempted to compile to an ordinary property instead of a method. It's
ambiguous with

    {
      d: null
    }

if () were to compile to null.  It currently compiles to nothing (#32),
but the argument stands.

This change hence introduces this syntax

    (object (method 'd ()))

similarly to how getters and setters already allow empty bodies with

    (object (get 'd ())
            (set 'd ()))

I also moved the check for the initial "get" / "set" / "method" atom
above the args.length==2 check, to ensure it takes precedence.
@anko anko closed this as completed in 3c74426 Mar 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants