scsh-users
[Top] [All Lists]

Re: how to automatically quote?

To: andreas.bernauer@gmx.de
Subject: Re: how to automatically quote?
From: Noah Friedman <friedman@splode.com>
Date: Tue, 24 Feb 2004 17:16:28 -0800 (PST)
Cc: scsh@zurich.csail.mit.edu
Reply-to: Noah Friedman <friedman@splode.com>
Andreas,

It's not clear to me exactly how extensive your syntax is, so it may be
that you will not be able to get away with using eval so trivially.  You
may need to write macros if you want to conditionally delay evalation or
implicitly quote some expressions.

But with the examples you provided, it seems that you may be able to use
`apply':

    (apply (car command) (cdr command))

But this may not be sufficient if the environment you want to use is not
the current environment, but alternatively you should be able to do:

    (eval (cons (car command)
                (map (lambda (x) (list 'quote x))
                     (cdr command)))
          (interaction-environment))

You said that the mapping relation

    (lambda (x) (list 'quote x))

did not work, but I'm not sure why that would be the case; in fact I tried
it and it seems to be fine:

    > (define (frobme sexp)
         (eval (cons (car sexp)
                     (map (lambda (x) (list 'quote x))
                          (cdr sexp)))
               (interaction-environment)))
    > (frobme '(list this should work))
    '(this should work)
    > (frobme '(+ 2 3))
    5

But as defined, `frobme' will not work correctly for nested function calls
since there's no obvious way to distinguish a funcall from a list of data.
That's why you may need macros.  The alternatives I can think of would be
pretty ugly.

<Prev in Thread] Current Thread [Next in Thread>