I am writing on a system that interacts with the user (actually a
retrieval system as known in artificial intelligence, but this doesn't
matter here). I wanted to use EVAL to execute some commands, but I
failed. I hope somebody on the list can help me with my problem.
I want the user to be able to say something like
(assert atom) or
(retrieve (loves ?x saralee)) or
(erase atom) etc.
on a command line and then execute that command.
All the commands are of the form (<command> <argument>), so I thought
I (mis)use the eval feature of Scheme. Like
(let loop ()
(let ((command (read (current-input-port))))
(eval command (interaction-environment))
However, this did not work. The problem is that I need the arguments
to ASSERT, RETRIEVE, ERASE, etc. in a quoted form, as there is for
example no variable called "atom" or function "loves". Thus, I have
to do a transformation of
'(assert atom) to
so I can say
(eval '(assert 'atom) (interaction-environment)) instead of
(eval '(assert atom) (interaction-environment))
;[which is wrong, as there is no variable `atom'].
I've tried something like
(eval (cons (car command)
(map (lambda (x) (quote x))
which did not work, of course, as every argument was changed to 'x
(e.g. atom became 'x, etc).
(lambda (x) (list 'quote x)) which is the same as
(lambda (x) `(quote ,x))
[as the map function] did not work either, as eval tried to call a
function named "'atom" [i.e. quote-'A'-'T'-'O'-'M'].
If the argument is only a single symbol, I can do a workaround with
symbol->string and string->symbol. But this doesn't work for lists
like (loves ?x saralee).
Does anybody know of a general way how I can quote something
"automatically"? I thought it should be pretty simple, but obviously
I am missing something here.
Thank you for your time and your input in advance.
Description: PGP signature