Chia-Network / clvm_tools_rs_fork

Modern Chialisp compiler implemented in Rust
Apache License 2.0
3 stars 9 forks source link

20230720 call with rest #198

Closed prozacchiwawa closed 1 year ago

prozacchiwawa commented 1 year ago

Adds an &rest keyword to function argument lists. It specifies that the runtime value that follows will be used to provide the rest of the argument list to this function as though each left subtree was specified as a separate argument and its tail value would be captured by an improper tail argument in the same position.

&rest fills unspecified arguments with a runtime value:

in (defun F (A B . C) ...) called like (F &rest (list 101 103 105 109)), the body of F receives A = 101, B = 103, C = (105 109).

in (defun F (A B . C) ...) called like (F 13 &rest (list 101 103 105 109)), the body of F receives A = 13, B = 101, C = (103 105 109).

in (defun F (A B . C) ...) called like (F 13 15 19 &rest (list 101 103)), the body of F receives A = 13, B = 15, C = (19 101 103).

See https://github.com/Chia-Network/clvm_tools_rs/blob/20230720-call-with-rest/src/tests/compiler/restargs.rs for examples.

Will likely backport this and put a PR in at the base level as well.