gurkult / py-gurklang

An interpreted Python implementation of Gurklang.
https://docs.gurkult.com
MIT License
8 stars 2 forks source link

Tuple unpacking #6

Open gustavwilliam opened 3 years ago

gustavwilliam commented 3 years ago

We need a way to unpack tuples and add them to the stack. The following is the proposed syntax:

( 1 2 3 ) unpack
( 1 2 3 ) :tpl var
tpl unpack

Both of the examples above would give the following result. The values 1, 2 and 3 would be added to the stack — in that order.

lavirlifiliol commented 3 years ago

this can now be done with the case function like

(1 2 3) { ((. . .)) {} } case  # 1 2 3 is now on the stack, with 1 on top.
(1 2 3) { ((. .. ...)) {} } case  # 3 2 1 is now on the stack, with 3 on top.

there may still be value in having this as a function though.

gustavwilliam commented 3 years ago

That's very nice to know. I think we should still make the unpack command, since it looks cleaner in some sense.