The way you formatted it, it looks like on function definition, but in fact, it is just 6 top level forms. Comments are made by semicolons, by the way.
Code: Select all
(defun test(n) (greaterp high n low))
(setq l ‘(4 7 2))
(setq high 7)
(setq low 3)
(mapcar ‘test l)
(t nil nil) ; the result of the mapcar
If you execute these statements in this order on the REPL, the first DEFUN will fail, because HIGH and LOW are unbound at that point. However, since you want to put this explicit function declaration away anyway, let's just see how you would do it with an anonymous function.
First, make it a function. It should take the high and low values, and a list of values to check:
Code: Select all
(defun check-range (high low list)
;; ... here be code
)
You want to be able to call it like this:
A lambda function is just an anonymous function. Instead of first defining a function, binding it to a symbol, and finally calling it by that symbol,
Code: Select all
(defun foo (x)
(bar x))
;;; later, somewhere
(mapcar #'foo some-list)
you create a function "on the fly":
Code: Select all
;;; somewhere
(mapcar (lambda (x)
(bar x))
some-list)
"Just throw more hardware at it" is the root of all evil.
Svante