←back to thread

389 points kurinikku | 5 comments | | HN request time: 1.081s | source
Show context
liontwist ◴[] No.42165013[source]
The cons/car/cdr implementation as lambda was magical the first time I saw it. But it just shows that the language runtime must implement key/value dictionaries and you are able to borrow that implementation to make other data structures.
replies(3): >>42165632 #>>42166573 #>>42203090 #
1. hinkley ◴[] No.42166573[source]
I find the destructuring logic in elixir much more interesting, and the watered down version in ES6 much more practical.

In elixir you can pop off as many as you like.

replies(1): >>42166784 #
2. liontwist ◴[] No.42166784[source]
Can you share any resources about it?
replies(1): >>42167135 #
3. hinkley ◴[] No.42167135[source]
I’m a bit of an elixir noob, but Enum functions like slice let you cut up lists in various ways, and you can pattern match values in maps in function definitions:

http://www.skuunk.com/2020/01/elixir-destructuring-function....

Which can let you unroll function preambles, or apply different rules if for instance an admin user runs a function versus a regular user.

replies(1): >>42168091 #
4. liontwist ◴[] No.42168091{3}[source]
I think this is a little different. Pattern matching gives you car and cdr, but not cons.
replies(1): >>42168217 #
5. hinkley ◴[] No.42168217{4}[source]
That exists for maps and lists.