←back to thread

389 points kurinikku | 8 comments | | HN request time: 1.385s | source | bottom
1. 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 #
2. ◴[] No.42165632[source]
3. 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 #
4. liontwist ◴[] No.42166784[source]
Can you share any resources about it?
replies(1): >>42167135 #
5. hinkley ◴[] No.42167135{3}[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 #
6. liontwist ◴[] No.42168091{4}[source]
I think this is a little different. Pattern matching gives you car and cdr, but not cons.
replies(1): >>42168217 #
7. hinkley ◴[] No.42168217{5}[source]
That exists for maps and lists.
8. EuAndreh ◴[] No.42203090[source]
Not key value dictionaries, just pointers are needed.

A closure with no behaviour is just a pointer to the enclosed variable. A closure with 2 pointers is a pair, which you can get the car and cdr.

The runtime needs to make the pointee available outside its definition, so escape analysis, garbage collection, etc. But no dictionary is needed.