Paste number 71402: trying to make a function that generates functions

Index of paste annotations: 1

Paste number 71402: trying to make a function that generates functions
Pasted by: ebil
When:7 months, 1 day ago
Share:Tweet this! | http://paste.lisp.org/+1J3E
Channel:#lisp
Paste contents:
Raw Source | XML | Display As
(defun maketemp ()
 (let ((num 0))
  (lambda (x)
   (setq num (+ x num)))))

then try:
(setf blah (maketemp))

and:

(funcall blah 0)

and I get an error.

Annotations for this paste:

Annotation number 1: re:
Pasted by: v
When:7 months, 1 day ago
Share:Tweet this! | http://paste.lisp.org/+1J3E#1
Paste contents:
Raw Source | Display As
(defun maketemp ()
 (let ((num 0))
  (lambda (x)
   (setq num (+ x num)))))

then try:
(setf blah (maketemp))

and:

(funcall blah 0)
---------------------------

;;this would evaluate to  

(lambda (x)
 (setq 0 (+ x 0))

also it seems you are in common lisp, which has separate name spaces for functions and variables.

You may have to play around with the 'function' function to make it work...

Colorize as:
Show Line Numbers
Index of paste annotations: 1

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.