tomhrr / dale

Lisp-flavoured C
BSD 3-Clause "New" or "Revised" License
1.03k stars 48 forks source link

Allow uql unquoting null nodes if possible #123

Closed porky11 closed 6 years ago

porky11 commented 7 years ago

When I define a variadic macro, that also can take zero variadic arguments something like following isn't enough:

(def x (macro intern (...)
  (qq a (uql (get-varargs-list (arg-count mc))))))

I also have to define another version for zero arguments ( or could check explicitely if it is a null node, which mostly is even more complicated)

(def x (macro intern (void)
  (qq a)))
tomhrr commented 7 years ago

On Thu, Sep 22, 2016 at 04:22:31AM -0700, Fabio Krapohl wrote:

When I define a variadic macro, that also can take zero variadic arguments something like following isn't enough:

(def x (macro intern (...) (qq a (uql (get-varargs-list (arg-count mc))))))

I also have to define another version for zero arguments ( or could check explicitely if it is a null node, which mostly is even more complicated)

(def x (macro intern (void) (qq a)))

I'm not sure this is a good idea, mainly because unquoting a null node, putting aside the case above, almost always means something has gone wrong. If this were changed, then the common case would require the author to determine from the macro expansion that the node was null and expanded to nothing, which could make debugging tricky in some cases. It would be possible instead for an 'empty' node, one with a null token and a null list node, to expand to nothing, and for get-varargs-list to return such a node when no arguments have been passed to the macro: does that sound OK?

porky11 commented 7 years ago

So you want to change uql, so it takes a list node instead of the first node of a list, and some new kind of node will be added, that is neither a list-node nor a symbol, representing an empty list?

tomhrr commented 7 years ago

On Mon, Oct 10, 2016 at 04:57:15PM -0700, Fabio Krapohl wrote:

So you want to change uql, so it takes a list node instead of the first node of a list, and some new kind of node will be added, that is neither a list-node nor a symbol, representing an empty list?

I think that changing uql such that it expands to the list node is probably a good idea, but that would happen under #121, rather than this issue. For this issue, what I'm proposing is that:

(def x (macro intern (void)
  (def empty-node (var auto \ (make-node)))
  (qq a (uql x))))

would expand to:

(a)

because uql would see that empty-node had both a null token-str and a null list-node, and expand it to nothing. Along with that, get-varargs-list would return such a node if no varargs were present.

porky11 commented 7 years ago

Yes, this seems a good idea

tomhrr commented 7 years ago

Thanks, this should be fixed now.