tinylisp icon indicating copy to clipboard operation
tinylisp copied to clipboard

Alternative basic cell

Open wboeke opened this issue 2 years ago • 1 comments

Hello, Instead of your clever nan boxing you also can use a struct with bitfields. The code will be easier because normal member names are available, and also more info can be added. I tried this with a cell size of 4 bytes, containing an integer of 28 bits and 2 type fields. I would be happy to include the source code, but github does'nt allow that. Another issue: functions with no side effects allow a sort of super tailcall, by resetting sp (stack pointer) to it's former value after function return. This way e.g. a recursive fibonacci does not need millions of cells, but only a few. (fib 30) does take 3.5 sec on my old laptop, which isn't that bad. Instead of 'lambda' the name 'func' must be used. As said, if you are interested in my source code, please send me a mail: [email protected]

wboeke avatar Aug 09 '22 14:08 wboeke

Another issue: functions with no side effects allow a sort of super tailcall, by resetting sp (stack pointer) to it's former value after function return.

I've seen this before, being called "ABC" garbage collection I think. But it is not safe to use. That's why I refrained from using it.

It's not safe when functions with side effects are indirectly called in the arguments passed to the side-effect free function. For example, (+ 1 (car (setq n (cons 2 ()))) 3) where n can be a local variable of a lambda or let. Here we use setq value, but implementations of setq may differ. When evlis evaluates the arguments, it leaves more than just numbers on the stack. Since setq is mentioned in the PDF, we can't use this "optimization" in non-pure Lisp (i.e. not pure functional). Perhaps there are some clever ways to get around it. But if so, it requires writing it up in the PDF, which may be out of scope of the intent to keep things small and simple.

EDIT: Now I recall I've seen "ABC garbage collection" here. It takes some degree of intuition and experience to "feel" that something is not right, like in this case. People post lots of "cool stuff" online that is just plain wrong (I don't mean you.)

Robert-van-Engelen avatar Aug 10 '22 17:08 Robert-van-Engelen