Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Scheme (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Shared namespace for procedures and variables=== In contrast to Common Lisp, all data and procedures in Scheme share a common namespace, whereas in Common Lisp [[Common Lisp#The function namespace|functions and data have separate namespaces]] making it possible for a function and a variable to have the same name, and requiring special notation for referring to a function as a value. This is sometimes known as the "[[Lisp-1 vs. Lisp-2]]" distinction, referring to the unified namespace of Scheme and the separate namespaces of Common Lisp.<ref>{{Cite news |last1=Gabriel |first1=Richard P. |author-link=Richard P. Gabriel |last2=Pitman |first2=Kent |author-link2=Kent Pitman |year=1988 |title=Technical Issues of Separation in Function Cells and Value Cells |volume=1 |pages=81β101 |work=LISP and Symbolic Computation |issue=1 |publication-date=June 1988 |url=http://www.nhplace.com/kent/Papers/Technical-Issues.html |access-date=2012-08-09 |doi=10.1007/BF01806178}}</ref> In Scheme, the same primitives that are used to manipulate and bind data can be used to bind procedures. There is no equivalent of Common Lisp's <code>defun</code> and <code>#'</code> primitives. <syntaxhighlight lang="Scheme"> ;; Variable bound to a number: (define f 10) f ===> 10 ;; Mutation (altering the bound value) (set! f (+ f f 6)) f ===> 26 ;; Assigning a procedure to the same variable: (set! f (lambda (n) (+ n 12))) (f 6) ===> 18 ;; Assigning the result of an expression to the same variable: (set! f (f 1)) f ===> 13 ;; functional programming: (apply + '(1 2 3 4 5 6)) ===> 21 (set! f (lambda (n) (+ n 100))) (map f '(1 2 3)) ===> (101 102 103) </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)