h3rald / min

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

square symbol / with symbol - bug #152

Closed ghost closed 3 years ago

ghost commented 3 years ago

I interpreted below lines and min interactive shell shut itself down.

$ (dup *) ^square
$ (5 square puts!) {} 'square %square with

Another exit way from min opened 😄

ghost commented 3 years ago

Hey! Please fix it. Then, Do you know how are symbols be binded to scopes? Could you tell me how?

h3rald commented 3 years ago

I finally understood what is going on here, and I am not sure that technically is a bug: it's another recursion problem.

If you rename the key of your dictionary to something else than "square" (the name of your lambda) everything works as expected.

Here's what is going on... it is actually easier to reproduce as follows:

(dup *) ^square
{} 'square %square ; <-- this shouldn't be allowed!
:d
3 *d/square

Basically, the invoke (or with in your case) is evaluating the symbol square within the scope of d.

Alright, so what's the value of square? Well... a quotation containing square that gets evaluated within the context of d.

Alright, so what's the value of square? Well... a quotation containing square that gets evaluated within the context of d.

...

I am not sure if I can prevent this from happening: I could check if you are trying to bind a quoted symbol which has the same value as the key, but I am not sure it's enough. Definitely it is going to cause trouble, so probably it shouldn't be allowed...

h3rald commented 3 years ago

It even works without a lambda!!! image

h3rald commented 3 years ago

Fixed.