Skip to main content
added 680 characters in body
Source Link

Common Lisp (GNU CLISP)

[1]> (lambda () (funcall *))
#<FUNCTION :LAMBDA NIL (FUNCALL *)>
[2]> (funcall *)

*** - Program stack overflow. RESET

Explanation (see if you can figure it out first):

The value of the variable variable * is the result of the last form evaluated at the prompt. Thus, (funcall *) says "call the last REPL result," and that happens to be (lambda () (funcall *)) which is a function that calls the last REPL result, which at that point is itself.

There are lots of variations on this theme:

[7]> (setf (symbol-function '*) (lambda () (funcall *)))
#<FUNCTION :LAMBDA NIL (FUNCALL *)>
[8]> (*)

*** - Program stack overflow. RESET

A particularly devious one would be a function that "works" (does something that's not a stack overflow) at first, and then later overflows the stack. E.g., using ** (which is the second to last REPL result):

[14]> (defun hello-world () (print 'hello-world))
HELLO-WORLD
[15]> (defun uh-oh () (funcall **))
UH-OH
[16]> (uh-oh)

HELLO-WORLD 
HELLO-WORLD
[17]> (uh-oh)

*** - Program stack overflow. RESET

Common Lisp (GNU CLISP)

[1]> (lambda () (funcall *))
#<FUNCTION :LAMBDA NIL (FUNCALL *)>
[2]> (funcall *)

*** - Program stack overflow. RESET

Explanation (see if you can figure it out first):

The value of the variable variable * is the result of the last form evaluated at the prompt. Thus, (funcall *) says "call the last REPL result," and that happens to be (lambda () (funcall *)) which is a function that calls the last REPL result, which at that point is itself.

Common Lisp (GNU CLISP)

[1]> (lambda () (funcall *))
#<FUNCTION :LAMBDA NIL (FUNCALL *)>
[2]> (funcall *)

*** - Program stack overflow. RESET

Explanation (see if you can figure it out first):

The value of the variable variable * is the result of the last form evaluated at the prompt. Thus, (funcall *) says "call the last REPL result," and that happens to be (lambda () (funcall *)) which is a function that calls the last REPL result, which at that point is itself.

There are lots of variations on this theme:

[7]> (setf (symbol-function '*) (lambda () (funcall *)))
#<FUNCTION :LAMBDA NIL (FUNCALL *)>
[8]> (*)

*** - Program stack overflow. RESET

A particularly devious one would be a function that "works" (does something that's not a stack overflow) at first, and then later overflows the stack. E.g., using ** (which is the second to last REPL result):

[14]> (defun hello-world () (print 'hello-world))
HELLO-WORLD
[15]> (defun uh-oh () (funcall **))
UH-OH
[16]> (uh-oh)

HELLO-WORLD 
HELLO-WORLD
[17]> (uh-oh)

*** - Program stack overflow. RESET
Source Link

Common Lisp (GNU CLISP)

[1]> (lambda () (funcall *))
#<FUNCTION :LAMBDA NIL (FUNCALL *)>
[2]> (funcall *)

*** - Program stack overflow. RESET

Explanation (see if you can figure it out first):

The value of the variable variable * is the result of the last form evaluated at the prompt. Thus, (funcall *) says "call the last REPL result," and that happens to be (lambda () (funcall *)) which is a function that calls the last REPL result, which at that point is itself.