lisp-2

Can Emacs Lisp assign a lambda form to a variable like Scheme?

不想你离开。 提交于 2020-04-14 07:23:11
问题 While investigating Emacs Lisp's symbol cells, I found out that for an example function like (defun a (&rest x) x) I can call (symbol-function 'a) , which returns (lambda (&rest x) x) . I can then use it if I want > ((lambda (&rest x) x) 1 2 3 4 5) (1 2 3 4 5) which has the same functionality as the original function above. 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 . For example

Is “Lisp-1 vs Lisp-2” relevant in a language with static types?

断了今生、忘了曾经 提交于 2019-12-11 06:59:52
问题 (This is a CS-theory type of question; I hope that's acceptable.) The "Lisp-1 vs Lisp-2" debate is about whether the namespace of functions should be distinct from the namespace of all other variables, and it's relevant in dynamically typed languages that allow the programmer to pass around functions as values. Lisp-1 languages (such as Scheme) have one namespace, so you can't have both a function named f and also an integer named f (one would shadow the other, just like two integers named f

How to store a function in a variable in Lisp and use it

爷,独闯天下 提交于 2019-12-11 02:02:06
问题 I want to store a function like print in a variable so that I can just type something short like p , e.g: In Scheme : (define print display) (print "Hello world\n") ;; alternate way (define print 'display) ((eval print) "Hello world\n") The same approach does not seem to work in Common Lisp : (defvar p 'print) ;;(print (type-of p)) (p "Hello world") ;; Attempt 1 ((eval p) "Hello world") ;; >> Attempt 2 ((eval (environment) p) "Hello world") ;; Attempt 3 I'm getting this error with Attempt 1

Common Lisp a Lisp-n?

谁都会走 提交于 2019-12-07 05:00:30
问题 I'm aware that Common Lisp has different binding environments for functions and variables, but I believe that it also has another binding environment for tagbody labels. Are there even more binding environments than this? If so, then is it fair to categorize Common Lisp as a Lisp-2? These question are not meant as pedantry or bike-shedding, I only want to gain a better understanding of Common Lisp and hopefully get some pointers into where to dig deeper into its spec. 回答1: I'm aware that

Common Lisp a Lisp-n?

自作多情 提交于 2019-12-05 08:46:20
I'm aware that Common Lisp has different binding environments for functions and variables, but I believe that it also has another binding environment for tagbody labels. Are there even more binding environments than this? If so, then is it fair to categorize Common Lisp as a Lisp-2? These question are not meant as pedantry or bike-shedding, I only want to gain a better understanding of Common Lisp and hopefully get some pointers into where to dig deeper into its spec. danlei I'm aware that Common Lisp has different binding environments for functions and variables, That would be namespaces ,

Do any lisps have a s-expression as their head, e.g. ((f 2) 3 4)? If not, why?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 01:47:07
问题 Do any lisps support nested s-expression on their head? For example ((f 2) 3 4) for which (f 2) presumably evaluates to a function/macro to apply on 3 4 . Is it possible to have a lisp supporting such a thing? Or are there technical limitations that prohibit this/make it impractical? 回答1: In those Lisps, which have single namespace for variables and functions, your expression is valid. These are called Lisp-1. Scheme and Clojure are examples of such Lisps. In those Lisps, which have separate

Using a lambda value from function as first element of list

∥☆過路亽.° 提交于 2019-11-30 19:41:55
I'm reading over Peter Norvig's Paradigms of Artificial Intelligence Programming, and I've come across an issue I cannot resolve on my own (this is my introduction to Lisp). The issue is quite a small one, really, but obviously not one my little brain can solve. Why is it that when a function's value is a lambda, it is an error to use that function as the first element to a list. For example: Lisp: (defun some-func () #'(lambda (x) x)) ;; At REPL ;; Does not work > ((some-func) 1) ;; Does work > ((lambda (x) x) 1) ;; Also works > (funcall (some-func) 1) I hope that makes sense! This is a good

Why must I funcall a function returned from another?

丶灬走出姿态 提交于 2019-11-30 18:11:33
问题 Why doesn't this work? ( ((lambda () (lambda (x) (funcall #'1+ x)))) 2) ; yields Compile-time error: illegal function call I ran into a situation like this and it later turned out that a funcall fixes it, i.e. (funcall ((lambda () (lambda (x) (funcall #'1+ x)))) 2) ; => 3 I'm confused because it seems like the first one should work, because I actually have a function I'm calling, not just a symbol that may belong to either namespace (i.e. (type-of ((lambda () #'1+))) ; => FUNCTION ). I

Using a lambda value from function as first element of list

旧时模样 提交于 2019-11-30 04:41:22
问题 I'm reading over Peter Norvig's Paradigms of Artificial Intelligence Programming, and I've come across an issue I cannot resolve on my own (this is my introduction to Lisp). The issue is quite a small one, really, but obviously not one my little brain can solve. Why is it that when a function's value is a lambda, it is an error to use that function as the first element to a list. For example: Lisp: (defun some-func () #'(lambda (x) x)) ;; At REPL ;; Does not work > ((some-func) 1) ;; Does

Separate Namespaces for Functions and Variables in Common Lisp versus Scheme

冷暖自知 提交于 2019-11-27 20:03:49
Scheme uses a single namespace for all variables, regardless of whether they are bound to functions or other types of values. Common Lisp separates the two, such that the identifier "hello" may refer to a function in one context, and a string in another. (Note 1: This question needs an example of the above; feel free to edit it and add one, or e-mail the original author with it and I will do so.) However, in some contexts, such as passing functions as parameters to other functions, the programmer must explicitly distinguish that he's specifying a function variable, rather than a non-function