[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

New symbols on the fly



One more question, just to let everyone know that I am a complete idiot.  I'm
trying to create and use symbols on the fly.  The idea is write some LISP code
that will simulate another computer language on the fly.  The example that I'm
trying is to create symbols called R1, R2, ... Rn, but only as the user tries
to access them (either to read or write).  They would type something like:

(STO 3)
or
(RCL 4)

and I wrote a few macros and functions that look like this:

(defvar RX 0)  ; define this ahead of time

(defmacro make-name (&rest args)
    `(intern (format nil "~{~A~}" (list ,@args))))

(defmacro sto (n)
       `(setf ,(make-name "R" RX) ,x))

(defmacro rcl (n)
  (declare (special RX))
       `(setf RX ,(make-name "R" n)))
       
(defun enter (n)
  (declare (special RX))
  (setf RX n))
       
Now the problem that I'm having is this: if I use the above code:

(ENTER 10)
(STO 3)

all works well, the number 10 is stored in R3.  If I next type:

(RCL 7)

no R7 symbol has been defined yet, so LISP yips at me.  I originally 
thought that "intern" would create a symbol if it needed to, otherwise
it would simple return the value of the symbol, but I must be wrong.
Using "find-symbol" does not seem to work either.  There must be an
easier way to do this, as this kind of thing is one of the chief advantages
of LISP.
           Jeffrey