Questions tagged [lisp-2]

lisp-2 refers to Lisp-like languages with two different namespaces for variables and function names.

Lisp 2: some languages, like Common Lisp, have separate namespaces for variables and functions. Those are said to be a Lisp 2 language. A Lisp 1, like Scheme, does only have a single namespace.

Common Lisp actually has more than 2 namespaces.

For major difference between Lisp 1 and Lisp 2 see this question

17 questions
114
votes
2 answers

What is the difference between Lisp-1 and Lisp-2?

I have tried to understand the difference between Lisp-1 and Lisp-2 and how this relates to Clojure but I still do not understand properly. Can anyone enlighten me?
yazz.com
  • 57,320
  • 66
  • 234
  • 385
31
votes
6 answers

Separate Namespaces for Functions and Variables in Common Lisp versus Scheme

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…
cjs
  • 25,752
  • 9
  • 89
  • 101
7
votes
4 answers

Using a lambda value from function as first element of list

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…
7
votes
3 answers

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

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…
spacingissue
  • 497
  • 2
  • 12
6
votes
4 answers

Common Lisp a Lisp-n?

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…
fogus
  • 6,126
  • 5
  • 36
  • 42
4
votes
4 answers

Why must I funcall a function returned from another?

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)…
MasterMastic
  • 20,711
  • 12
  • 68
  • 90
3
votes
3 answers

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

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…
147pm
  • 2,137
  • 18
  • 28
3
votes
1 answer

Calling a list of functions in Common Lisp

In Clojure, I can define a sequence of functions, then call them like they'd been any other value, as so: (doseq [op [+ - * /]] (println (op 1 2 3 4))) which produces the following output: 10 -8 24 1/24 nil Trying to do the same in Common Lisp…
Electric Coffee
  • 11,733
  • 9
  • 70
  • 131
3
votes
1 answer

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

(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…
Jim Pivarski
  • 5,568
  • 2
  • 35
  • 47
2
votes
2 answers

Common Lisp, "defined but never used"

This function compiles with warnings, fn is defined and never used in the first line, and that fn is an undefined function in the second line: (defun test-function (fn) (funcall #'fn)) Why? A general explanation or a link to it would be…
Carlos Ledesma
  • 307
  • 1
  • 2
  • 8
2
votes
2 answers

In Scheme or STk, a function will be shown as a procedure or closure, but why does LISP give an error?

On Ubuntu, if I run MIT-Scheme, it will show a function as a procedure: 1 ]=> (define (sq x) (* x x)) ;Value: sq 1 ]=> (sq 3) ;Value: 9 1 ]=> sq ;Value 11: #[compound-procedure 11 sq] and Berkeley's STk will show sq as a closure: STk> (define…
nonopolarity
  • 146,324
  • 131
  • 460
  • 740
2
votes
3 answers

emulating Clojure-style callable objects in Common Lisp

In Clojure, hash-maps and vectors implement invoke, so that they can be used as functions, for example (let [dict {:species "Ursus horribilis" :ornery :true :diet "You"}] (dict :diet)) lein> "You" or, for vectors, (let [v…
Daniel Shapero
  • 1,869
  • 17
  • 30
2
votes
3 answers

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

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…
Plakhoy
  • 1,846
  • 1
  • 18
  • 30
1
vote
2 answers

Why does mapcar in lisp take a name instead of function?

I am going through a lisp book and I am looking at mapcar, my question is why is that this is valid: > (mapcar #'+ '(1 2) '(3 4)) but this one isn't: (mapcar + '(1 2) '(3 4)) in other words, is there a reason it was decided in lisp that the first…
maininformer
  • 967
  • 2
  • 17
  • 31
1
vote
0 answers

Why doesn't set work with lambda in Common Lisp?

I am writing a lisp interpreter (in C), and am at the point of implementing lambda functions and the set language features. In my interpreter the following works: (set 'f (lambda (x) (cdr x))) (f '(a b c)) outputting (b c). However, apparently this…
Jon Deaton
  • 3,943
  • 6
  • 28
  • 41
1
2