Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support vector destructuring assignment #21

Open
ingydotnet opened this issue Jul 18, 2023 · 5 comments
Open

Support vector destructuring assignment #21

ingydotnet opened this issue Jul 18, 2023 · 5 comments

Comments

@ingydotnet
Copy link
Collaborator

ingydotnet commented Jul 18, 2023

At least in these forms:

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

(defn a [[b c]] ...)
@Tekki
Copy link

Tekki commented Jul 23, 2023

And don't forget the hash maps

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

@PEZ
Copy link
Collaborator

PEZ commented Jul 23, 2023

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
Copy link

Tekki commented Jul 23, 2023

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];

@ingydotnet
Copy link
Collaborator Author

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.

@ingydotnet
Copy link
Collaborator Author

See #41

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants