Subject: Re: basic emacs lisp idioms
From: rpw3@rpw3.org (Rob Warnock)
Date: Wed, 18 Jun 2008 06:22:00 -0500
Newsgroups: comp.lang.lisp,comp.emacs
Message-ID: <rMednSn6rKlFcsXVnZ2dnUVZ_sbinZ2d@speakeasy.net>
Pascal J. Bourguignon <pjb@informatimago.com> wrote:
+---------------
| Blake McBride <blake@mcbride.name> writes:
| > ... emacs could be used as a really good command file.
| 
| I used to think the same, and what function you miss hear can rather
| trivially be written in emacs lisp.  However, there's no point in it,
| given than there are good Common Lisp implementations that you can use
| as shell or script (#!) interpreters.  Try clisp ...
+---------------

Or, CMUCL, assuming you've added my #! hack
<http://rpw3.org/hacks/lisp/site-switch-script.lisp>
or equivalent.

+---------------
| ...have a look at http://clisp.cons.org/clash.html
+---------------

I've not tried going *that* far, but my "cmu" script, which is the
usual way I fire up a CMUCL REPL, when given command-line args simply
evaluates them (instead of starting a REPL). Combine that with a
symlink from "~/bin/=" to "~/bin/cmu", and you get a neat little
command-line "CL calculator":

    $ = + 1 2
    3
    $ = expt 2 100
    1267650600228229401496703205376
    $ = \* \* 1e6
    1.2676506002282294e36
    $ 

Yes, it saves the last value in a file and restores it to "*"!  ;-}

    $ = floor 28376542876534 82736
    342976973
    38406
    $ = get-decoded-time
    54
    57
    3
    18
    6
    2008
    2
    T
    8
    $ = loop for i to 25 when '(oddp i)' collect '(expt 2 i)'
    (2 8 32 128 512 2048 8192 32768 131072 524288 2097152 8388608 33554432)
    $ = format t '"2^100 = ~d~%"' '(expt 2 100)'
    2^100 = 1267650600228229401496703205376
    NIL
    $ 

O.k., so quoting starts getting messy when you need strings or sub-exprs.
But you can always just single-quote the whole mess and be done with it:

    $ = '(let ((x "A String.")) (format t "Now print ~(~a~)~%" x) (values))'
    Now print a string.
    $ 

Where it works *really* well is if you have a whole bunch of
pre-defined functions for things you commonly do, which I typically
do in a script called "hwtool" (hardware debugging tool), e.g.:

    $ hwtool dump32 '"Show CMUCL\'s string layout."'
    0x48956a28: 0x0000002a 0x0000006c 0x776f6853 0x554d4320
    0x48956a38: 0x73274c43 0x72747320 0x20676e69 0x6f79616c
    0x48956a48: 0x002e7475 0x00000000 0x48956a2f 0x28f0000b
    0x48956a58: 0x48956a1b 0x28f0000b 0x48956a2f 0x28f0000b
    $ 


-Rob

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