h3rald / min

A small but practical concatenative programming language and shell
https://min-lang.org
MIT License
310 stars 23 forks source link

Quotation is re-used when lambda is re-executed #174

Closed h3rald closed 2 years ago

h3rald commented 2 years ago

I'm confused by this behavior of cons. It seems new items are added to the original empty list.

(() cons cons) ^list

$ "a" "B" list
 (
   "a"
   "B"
 )

$ "a" "B" list
 (
   "a"
   "B"
   "a"
   "B"
 )

$ "a" "B" list
 (
   "a"
   "B"
   "a"
   "B"
   "a"
   "B"
 )

That is not what happens in Joy

DEFINE
lista == [] cons cons .

2 3 lista .
[2 3]

2 3 lista .
[2 3]

Originally posted by @DanielAjoy in https://github.com/h3rald/min/discussions/173

DanielAjoy commented 2 years ago

A way around it was to use

(()) apply

instead of ()

h3rald commented 2 years ago

Checked the code and it indeed modifies the provided quotation instead of returning a new one, which is exactly what you noticed.

This is not a general problem luckily and just a "special" behavior of the cons operator. I cannot understand or remember why I coded it in this way; perhaps it was just a too-literal interpretation of a definition of the operator I read somewhere.

The fix should be easy enough.

h3rald commented 2 years ago

Fixed in v0.37.0