This means that in emacs lisp you can something like this: (defun f (x) (+ x x)) In scheme, all names live in the same space, the value bound to the name is looked up and used whereever it appears. The first position in a list form that is evaluated names a function and that name is looked up in the function name space. Why else would the function cell of a contain (lambda (&rest x) x) if we couldn't turn this lambda expression into a function?Īn important difference between scheme and emacs lisp (and indeed most other lisps) is that scheme has a single namespace whereas emacs lisp has separate namespaces for functions and variables. Is there a way to imitate the Scheme world on this issue? It seems like there must be a way. Which gives (void-function new-a) if I try to use it as a function. So can elisp do this, i.e., assign a lambda expression to a symbol and then use it as a function? I've tried (setq new-a (lambda (&rest x) x)) Simply assigns the lambda expression to atom? - and now atom? is a function. Now, this reminds me of Scheme where a lambda expression is the body of the function and is assigned to a variable name with Scheme's all-purpose define. Which has the same functionality as the original function above. I can then use it if I want > ((lambda (&rest x) x) 1 2 3 4 5) I can call (symbol-function 'a), which returns (lambda (&rest x) x). While investigating Emacs Lisp's symbol cells, I found out that for an example function like (defun a (&rest x)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |