jrincayc / ucblogo-code

Berkeley Logo interpreter
https://people.eecs.berkeley.edu/~bh/logo.html
GNU General Public License v3.0
188 stars 34 forks source link

Segmentation fault on invoking oddly defined procedure. #35

Open zigggit opened 4 years ago

zigggit commented 4 years ago

If a procedure similar to the following is defined

to stuff [ 1 ] print [Any Logo you like here] end

then UCB Logo exits with a segmentation fault as soon as the procedure is invoked.

Is this even a valid thing to define? My knowledge isn't good enough to be certain, but I suspect it might not be. Perhaps such a definition should be rejected in the first place.

brianharvey commented 4 years ago

Indeed, that's not a well-formed TO form. It should error rather than segfaulting, of course.

My guess is that TO is treating the [1] as if it were [:foo], i.e., using 1 as the variable name for a rest argument. So when STUFF is invoked, it's trying to set the value of 1 to a list of inputs (in this case an empty list, but if it were (STUFF A B C) the list would be [A B C].

You can have a variable named 1, by saying MAKE 1 [some value]. Then ? print 1 1 ? print :1 some value