Mercerenies / gdlisp

Lisp on the Godot platform
GNU General Public License v3.0
146 stars 1 forks source link

Anonymous Class Constructor Arguments #7

Closed Mercerenies closed 3 years ago

Mercerenies commented 3 years ago

Currently, there's no way to specify arguments to an anonymous class constructor. We can write

(new Node (defn _init () ...))

But we can't make it so we pass arguments to the new class.

Now, this feature is a bit redundant, in the sense that any argument to the constructor could just as easily have been a closure value to begin with (and indeed, closure values are internally compiled to constructor arguments), but for consistency with top-level classes it would be nice to allow it. My suggestion is to leave the current syntax as is but also allow parentheses around the parent name, as follows

(new (Node 1 2 3) (defn _init (arg1 arg2 arg3) ...))

If you want to pass zero arguments (which is what you want 99% of the time), then you can leave off the parentheses, and the currently available syntax is still valid.

Mercerenies commented 3 years ago

85f8166 resolves this issue, with exactly the syntax suggested above.