lingy-lang/lingy

Support vector destructuring assignment

ingydotnet opened this issue · 5 comments

At least in these forms:

(let [[a b] c] ...)

(defn a [[b c]] ...)
Tekki commented

And don't forget the hash maps

(let [{title :Title author :Author} book] ...)
PEZ commented

Can you link us to some readings and watchings about your Perl destructuring stuff, @ingydotnet? Even if we don't end up leveraging it, it could be nice for reference and inspiration.

Tekki commented

Ingy's assign Perl module can be found in Metacpan at https://metacpan.org/pod/assign and his talk at the conference 2023 at https://youtu.be/ifoYsubNRj4.

To destructure an array like in (let [[first _ third] a] ...) with just Perl there are two simple ways:

my @a = ('one', 'two', 'three', 'four');

# first solution
my ($first, undef, $third) = @a;

# second solution
my ($first, $third) = @a[0,2];

And don't forget the hash maps

Didn't forget that. Just wanted to keep the scope down on this issue.
I'll make another issue for hash-maps.