Values and objects

Rustom Mody rustompmody at gmail.com
Sun May 11 10:12:11 EDT 2014


On Sunday, May 11, 2014 6:21:08 PM UTC+5:30, Steven D'Aprano wrote:

> The point is, it is *logically impossible* for a language to use 
> precisely the same syntax for value-assignment and variable-assignment. 
> Consider the variable called "x", which is bound to the value 23. If the 
> language has a single assignment operator or statement:

Its called set in classic lisp.
Here's an emacs lisp session (the oldest lisp I can lay my hands on)
The semicolons are comments like python's #

*** Welcome to IELM ***  Type (describe-mode) for help.
ELISP> (set (quote d) "Hello World")
"Hello World"
ELISP> (set (quote c) (quote d))
d
ELISP> ; those quote-s are getting boring
ELISP> (set 'b 'c)
c
ELISP> ; once more short-form a very common case
ELISP> (setq a 'b)
b
ELISP> ; Now unfold the chain
ELISP> ; Level 0
ELISP> 'a
a
ELISP> ; Level 1
ELISP> a
b
ELISP> ;Level 2
ELISP> (eval a)
c
ELISP> ;Level 3
ELISP> (eval (eval a))
d
ELISP> ;Level 4
ELISP> (eval (eval (eval a)))
"Hello World"
ELISP> 


IOW set UNIFORMLY evaluates its 2 arguments.
To get usual assignment like behavior of normal programming languages,
one (typically) quotes the first argument.


This is a sufficiently common case that it gets its own 'special
form' -- setq (ie set-quote)

However the more general case in which (the name of)* the variable is
evaluated at run-time is always available.

* "Name of" is strictly not correct because:
ELISP> (symbol-name 'a)
"a"

However if I dont say the "name of..." its hard to speak in
an intelligible way.

Here is the relevant intro from the elisp manual:

A "symbol" in GNU Emacs Lisp is an object with a name.  The symbol name
serves as the printed representation of the symbol.  In ordinary Lisp
use, ... a symbol's name is unique--no two symbols have the same name.

   A symbol can serve as a variable, as a function name, or to hold a
property list.  Or it may serve only to be distinct from all other Lisp
objects, so that its presence in a data structure may be recognized
reliably.  

tl;dr:
Quote-Eval go up and down the 'meta-language' tower
just as Lambda-(function)Apply go up and down the functional tower.

Elaborated further:
http://blog.languager.org/2013/08/applying-si-on-sicp.html



More information about the Python-list mailing list