From: Thaddeus L Olczyk
Subject: Inventing a new variable in lisp.
Date: 
Message-ID: <3c266de3.1017497125@nntp.interaccess.com>
I have a piece of code that looks like this:

(defmacro dothis( name value1 value2 condition)...)

I need to define a macro that calls dothis with value1=v1,v2,v3.
The porblem is that in order for do this to work, the name of the
variable name must be different wach time.

So:
dothis(FirstValue v1 va1 c)
dothis(FirstValue v2 va1 c)
will not work.

But:
dothis(FirstValue1 v1 va1 c)
dothis(FirstValue2 v2 va1 c)

Which is exactly the way I would like to do it.
Append the number to the end of the name in the macro.
The question is within the macro how do it.

IE
(defmacro doallthis(name value2 c)
  (list 
      'progn
       '(dothis whatdoIputhere? v1 value2 c)
       '(dothis whatdoIputhere? v2 value2 c)
       '(dothis whatdoIputhere? v3 value2 c)
  )
)

Any suggestions?
                

From: Coby Beck
Subject: Re: Inventing a new variable in lisp.
Date: 
Message-ID: <CEeV7.169700$Ga5.28341277@typhoon.tampabay.rr.com>
"Thaddeus L Olczyk" <······@interaccess.com> wrote in message
························@nntp.interaccess.com...
> I have a piece of code that looks like this:
>
> (defmacro dothis( name value1 value2 condition)...)
>
> I need to define a macro that calls dothis with value1=v1,v2,v3.
> The porblem is that in order for do this to work, the name of the
> variable name must be different wach time.
>
> So:
> dothis(FirstValue v1 va1 c)
> dothis(FirstValue v2 va1 c)
> will not work.
>
> But:
> dothis(FirstValue1 v1 va1 c)
> dothis(FirstValue2 v2 va1 c)
>
> Which is exactly the way I would like to do it.
> Append the number to the end of the name in the macro.
> The question is within the macro how do it.
>
> IE
> (defmacro doallthis(name value2 c)
>   (list
>       'progn
>        '(dothis whatdoIputhere? v1 value2 c)
>        '(dothis whatdoIputhere? v2 value2 c)
>        '(dothis whatdoIputhere? v3 value2 c)
>   )
> )
>
> Any suggestions?

This would seem to match your spec...

CL-USER 4 > (defmacro do-all-this (name value2 c)
                          `(progn
                             (do-this ,(intern (concatenate 'string
(symbol-name name) "-1")) v1 value2 c)
                             (do-this ,(intern (concatenate 'string
(symbol-name name) "-2")) v2 value2 c)
                             (do-this ,(intern (concatenate 'string
(symbol-name name) "-3")) v3 value2 c)))
DO-ALL-THIS

CL-USER 5 > (pprint (macroexpand-1 '(do-all-this first-value value2 c)))

(PROGN
  (DO-THIS FIRST-VALUE-1 V1 VALUE2 C)
  (DO-THIS FIRST-VALUE-2 V2 VALUE2 C)
  (DO-THIS FIRST-VALUE-3 V3 VALUE2 C))

CL-USER 6 >

When you want to return a snippet of code (like macros usually do) you can use
a back-quoted list of the form you want.  This then allows you to use a comma
to evaluate selected portions before returning them as I did above.  Now the
call to intern (and all of its arguments) are evaluated and its return value is
inserted into the list that the macro creates.

--
Coby
(remove #\space "coby . beck @ opentechgroup . com")
From: Coby Beck
Subject: Re: Inventing a new variable in lisp.
Date: 
Message-ID: <nKeV7.169702$Ga5.28350095@typhoon.tampabay.rr.com>
"Thaddeus L Olczyk" <······@interaccess.com> wrote in message
························@nntp.interaccess.com...
> I have a piece of code that looks like this:
>
> (defmacro dothis( name value1 value2 condition)...)
>
> I need to define a macro that calls dothis with value1=v1,v2,v3.
> The porblem is that in order for do this to work, the name of the
> variable name must be different wach time.
>
> So:
> dothis(FirstValue v1 va1 c)
> dothis(FirstValue v2 va1 c)
> will not work.
>
> But:
> dothis(FirstValue1 v1 va1 c)
> dothis(FirstValue2 v2 va1 c)
>
> Which is exactly the way I would like to do it.
> Append the number to the end of the name in the macro.
> The question is within the macro how do it.
>
> IE
> (defmacro doallthis(name value2 c)
>   (list
>       'progn
>        '(dothis whatdoIputhere? v1 value2 c)
>        '(dothis whatdoIputhere? v2 value2 c)
>        '(dothis whatdoIputhere? v3 value2 c)
>   )
> )
>
> Any suggestions?
>

This would seem to match your spec...

4 > (defmacro do-all-this (name value2 c)
           `(progn
                 (do-this ,(intern (concatenate 'string (symbol-name name)
"-1"))
                              v1 value2 c)
                 (do-this ,(intern (concatenate 'string (symbol-name name)
"-2"))
                              v2 value2 c)
                 (do-this ,(intern (concatenate 'string (symbol-name name)
"-3"))
                              v3 value2 c)))
DO-ALL-THIS

5 > (pprint (macroexpand-1 '(do-all-this first-value value2 c)))

(PROGN
  (DO-THIS FIRST-VALUE-1 V1 VALUE2 C)
  (DO-THIS FIRST-VALUE-2 V2 VALUE2 C)
  (DO-THIS FIRST-VALUE-3 V3 VALUE2 C))

6 >

When you want to return a snippet of code (like macros usually do) you can use
a back-quoted list of the form you want.  This then allows you to use a comma
to evaluate selected portions before returning them as I did above.  Now the
call to intern (and all of its arguments) are evaluated and its return value is
inserted into the list that the macro creates.

--
Coby
(remove #\space "coby . beck @ opentechgroup . com")