lispcommon-lispheap-memoryclispstack-memory

DYNAMIC-EXTENT ignored in CLISP?


I read here that "it is permissible for an implementation to ignore" the dynamic-extent declaration in Common Lisp, and I was wondering if it is in fact ignored in the CLISP implementation.

I have tried testing with the following code:

(let ((b (cons 1 2))) 
 (declare (dynamic-extent b)) 
 (list b))

Which returns:

((1 . 2))

My guess is that it is ignored, but I wanted to be sure.

Also, if it is ignored, is there a way for me to explicitly allocate memory to the stack rather than the heap?


Solution

  • > is there a way for me to explicitly allocate memory to the stack rather than the heap?

    No, and you can be thankful of it because it eliminates an entire category of bugs from the programs: there can be no "dangling pointers" to already dead objects that make your program crash.

    Furthermore, with CLISP or similar implementations, you don't need stack-allocated memory because:

    Finally, insisting on stack allocation of objects prevents you from freely choosing the programming style that is adapted to your problem. Lisp supports many programming styles: functional, procedural, object-oriented, pattern-based, logic, relational, rule, goal-oriented, and more. By requesting stack allocation, you restrain yourself to functional and procedural programming style; this really does not bring you forward.