Subject: Re: Fexprs more flexible, powerful, easier to learn? (Newlisp vs CL)
From: rpw3@rpw3.org (Rob Warnock)
Date: Wed, 28 Jan 2009 07:21:53 -0600
Newsgroups: comp.lang.lisp
Message-ID: <ismdnQJB_fhsxh3UnZ2dnUVZ_gednZ2d@speakeasy.net>
Didier Verna  <didier@lrde.epita.fr> wrote:
+---------------
| rpw3@rpw3.org (Rob Warnock) wrote:
| > Unfortunately, for compatibility with historical Lisps, Common Lisp
| > chose to leave global variables SPECIAL by default, *not* lexical as
| > in Scheme. This was a serious mistake, IMHO.
| 
| Why? I rarely use global variables, but when I do, I usually find it
| very convenient that they are dynamically scoped by default (sort of
| like Emacs's user options). Do you have a frequent use-case where you'd
| prefer them to be lexical ?
+---------------

Noodling about in the REPL, mainly, where short (1-char, even) names
are *so* tempting and yet *so* likely to get you in trouble, usually by
accidentally converting some innocent lexical binding deep in your program
into a dynamic binding... whereupon hilarity ensues. [Or true disaster.]
Having global lexicals as the default (e.g., Scheme) or at least having
a convenient mechanism for global lexicals (CL + DEFLEX macro) completely
side-steps the problem:

    cmu> (deflex x 3)

    X
    cmu> (deflex y 4)

    Y
    cmu> (defun xy () (list x y))

    XY
    cmu> (let ((x 1)
	       (y 2))
	   (list* x y (xy)))

    (1 2 3 4)
    >

Truth be told, I don't often use global lexicals in final production
code...  *except* in the case where some kind of command line is
being provided to the user in which variable names might be typed as
arguments to commands. Parenthephobic users also tend to be earmuff shy.
A real-life example is my "hwtool" pattern [about which I've posted
here before], which is a CL plus OPFR[1] plus some PEEK/POKE/MMAP
utilities plus an application-specific library of user-oriented
functions -- "commands" to be typed to the OPFR REPL. The commands
aren't the problem; it's various global constants, such as names or
devices, registers, or bits. Stuff like this [example only, not real]:

    hwtool> dump32 dev1 dev1-size
    0x48a92bc8: 0x0000003a 0x00000010 0x00000070 0x00000094
    0x48a92bd8: 0x00000030 0x0000000c
    hwtool> disable dev1 dev1-control dev1-intr-en
    :OK
    hwtool> dump32 dev1 dev1-size
    0x48a92bc8: 0x0000003a 0x00000000 0x00000070 0x00000094
    0x48a92bd8: 0x00000030 0x0000000c
    hwtool> 

Sure, the user could be told to type "dump32 *dev1* +dev1-size+",
but the results of trying to force that sort of silliness on them
would be... uh... not comfortable for the one doing the forcing.


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607