3 ms·
> Nevertheless, this defect is largely harmless because Common Lisp separates the name space into one for functions and one for variables. In other words, it c
by aidenn0 11y ago
> Nevertheless, this defect is largely harmless because Common Lisp separates the name space into one for functions and one for variables. In other words, it can be said that the existence of this defect has been justified the separation of name spaces which has made the semantics of the Common Lisp language complex unnecessarily
One note on variable capture in Common Lisp; while it is true that a lisp-2 runs into the issues somewhat less often than a lisp-1, the existence of FLET and LABELS should let people know that it doesn't solve the problem.
The real solution to this in Common Lisp is packages.
(in-package foo)
(defun bar () (do-something))
(defmacro baz (x) `(bar ,x))
(in-package quux)
(flet ((bar () (do-something-else)))
(baz 2)) ; calls foo::bar not the bar bound in above FLET
Also, many people like that Common Lisp has two namespaces because there are many identifiers that are useful as both nouns and verbs (e.g. LIST).
- suzuki 11y agoThank you for your comment. However, a capture still occurs if a local variable happens to have the same name as some function in the standard library. As for nouns and verbs, higher-order functions treat verbs (i.e. functions) as values (i.e. nouns). From the viewpoint of functional programming or lambda calculus, the distinction between them is not necessarily natural.
- aidenn0 11y agoThanks for replying! It is true that there is capture w.r.t. the standard library, and the Common Lisp specification forbids rebinding those. This is a case where the separate namespace complicates the semantics.