(HELP (HELP (HELP (HELP)))) 
Author Message
 (HELP (HELP (HELP (HELP))))

I have a very simple code but I could not find my way out with it !
I whant to assign values to symbols DYNAMICLY! by the following:

(defun define (dbname &rest arglist)
         (eval (list 'setf dbname arglist) )    

The goal is when I type: (define 'mydata 'abdullah 12 'mutawa)
          I get : (setf mydata '('abdullah 12 'mutawa)) <evaluated>  

Is there a way around it, do you think eval is not a good idea, or maybe
I should use apply? and how???

Abdullah.



Mon, 29 Mar 1999 03:00:00 GMT  
 (HELP (HELP (HELP (HELP))))



Quote:
>I have a very simple code but I could not find my way out with it !
>I whant to assign values to symbols DYNAMICLY! by the following:

>(defun define (dbname &rest arglist)
>         (eval (list 'setf dbname arglist) )    

>The goal is when I type: (define 'mydata 'abdullah 12 'mutawa)
>          I get : (setf mydata '('abdullah 12 'mutawa)) <evaluated>  

Actually, what I suspect your goal is that it should do

        (setf mydata '(abdullah 12 mutawa))

i.e. you don't want quotes inside the quoted list.

To make the simplest modification to your program to do what I think you
want, it should be:

(defun define (dbname &rest arglist)
  (eval `(setf ,dbname ',arglist)))

Note that in order to make the second argument to SETF be quoted, you have
to put the quote in explicitly.  The non-backquote version of this would
be:

  (eval (list 'setf dbname (list 'quote arglist)))

Quote:
>Is there a way around it, do you think eval is not a good idea, or maybe
>I should use apply? and how???

Have you looked at the section of the FAQ about using EVAL?  EVAL is
usually wrong, and there's almost always a way to do it better.

A non-EVAL way to do this is:

  (setf (symbol-value dbname) arglist)

Note also that when you're constructing code to be handed to EVAL,
backquote will usually be useful to generate the code you want (for the
same reason that backquote is so useful in macro definitions).
--
Barry Margolin
BBN Planet, Cambridge, MA

(BBN customers, please call (800) 632-7638 option 1 for support)



Mon, 29 Mar 1999 03:00:00 GMT  
 (HELP (HELP (HELP (HELP))))



   I have a very simple code but I could not find my way out with it !
   I whant to assign values to symbols DYNAMICLY! by the following:

   (defun define (dbname &rest arglist)
            (eval (list 'setf dbname arglist) )    

   The goal is when I type: (define 'mydata 'abdullah 12 'mutawa)
             I get : (setf mydata '('abdullah 12 'mutawa)) <evaluated>  

   Is there a way around it, do you think eval is not a good idea, or maybe
   I should use apply? and how???

No, it is not.  It rarely is.  At least, use

  (setf (symbol-value dbname) arglist)

and rename DEFINE into something less general.

'vb



Tue, 30 Mar 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. help! f90.help help help help

2. HELP HELP HELP HELP

3. HELP HELP HELP HELP

4. help help help help!!!!!!!!!!!

5. HELP: HELP: HELP: HELP: Online-manual on Expect

6. ***HELP***HELP***NEED INFORMATION***HELP***HELP

7. Ord Function HELP Please HELP HELP HELP

8. Help Help Help

9. TopSpeed - ODBC 3.1???? HELP HELP HELP

10. HELP - HELP - HELP

11. HELP HELP HELP - round function error

12. SUPER TAGGING HELP HELP HELP

 

 
Powered by phpBB® Forum Software