nsensfel / tonkadur

Narrative scripting/programming tool. Write stories in your favorite editor using a feature-rich language, compile them into a very small and simple language to easily integrate them into your game.
https://tonkadur.of.tacticians.online
Apache License 2.0
3 stars 0 forks source link

Partial lambda calls as lambda functions #33

Closed nsensfel closed 3 years ago

nsensfel commented 3 years ago

I don't remember why this wasn't implemented to start with.

(global (lambda text (int text (list string))) lambda0
   (lambda ((int  i) (text t) ((list string) l)
      (text_join (var t) (if (> i 3) l (reverse l)))
   )
)

(global (lambda text (text (list string))) lambda1
   (partial lambda0 3)
)

This should be doable by having Wyrd consider lambda values as a pair with one element being the line for the lambda function and the other being the list of arguments that are already assigned.

Considering how this would change pretty much every existing computations and instructions that support lambda expressions, this should be included in the next release candidate.

nsensfel commented 3 years ago

Reason for it not being implemented currently: the number of parameters is determined during compilation times, so a list with a size determined during runtime cannot be used as-is.

nsensfel commented 3 years ago

Potential solution: in wyrd, store parameters in wild dict. Number them in reverse: if the function has 3 parameters, store the first one in param_2, the second in param_1, etc... Thus, if this turned out to be an already partially parametered lambda, the previous parameters are in param_3, param_4, etc... This wild dict has to be what is passed around in addition to the instruction line.

nsensfel commented 3 years ago

Done in https://github.com/nsensfel/tonkadur/commit/87b3ce9b51499ac51027fcdd5cd971a16e5e844a.