Mercerenies / gdlisp

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

GDScript functions with non-standard signatures #107

Open Mercerenies opened 1 year ago

Mercerenies commented 1 year ago

GDLisp currently supports required arguments, optional arguments, and "rest" arguments. Putting aside the issue of named arguments (#55) for the moment, this means that, in GDLisp, the "correct" number of arguments with which to call a function is always a (potentially infinite) interval. A function like

(defn foo (a b &opt c d &rest e))

can be called with anywhere from 2 to infinity arguments. A function like

(defn foo (a b &opt c d))

can be called with anywhere from 2 to 4 arguments.

Unfortunately, a handful of GDScript built-in functions are not compatible with this interface.

How do we handle these?

Mercerenies commented 1 year ago

Current behavior is to just assume we have the right number of arguments. So, for instance, if you gave Rect2 three arguments, the fourth would get filled in with null automatically.

Mercerenies commented 1 year ago

Related note: We've encountered this problem with yield before (#5), which can take zero or two arguments. We didn't need to deal with it then because it turned out that yield made more sense as a special form (which can do its own ad-hoc validation of arguments at compile-time).