Re: Question about macro expansion
&aux is also an option for that hack. &optional allows users to specify
a name. &aux doesn't change the API of the macro. I personally would go
for &optional because I think func should be a parameter.
On 4/11/2018 11:57 AM, Bob Felts wrote:
> Chris, cjv, and mikel:
>
> Madhu provided a suggestion that is a synthesis of your solutions. I didn't want to provide "func" as a parameter to the macros, because it's the same in every case, and I'd like to save typing. And, yes, "func" is defined in each file that uses foo.
>
> Madhu's suggestion was to define foo as follows:
>
> (defmacro foo (bar p v &optional (func (intern "FUNC" *package*)))
> ...
> (if (,func ...
>
>
> Thanks, everyone.
>
> And, yes, I'm not happy with a design that needs this, but I'm still trying to shape things.
>
>> On Apr 11, 2018, at 12:35 PM, Christopher Riesbeck <c-riesbeck@northwestern.edu> wrote:
>>
>>
>> On 4/11/2018 10:51 AM, Bob Felts wrote:
>>> Right. But in this case I'm emitting code to be compiled in multiple packages. At compile time, I want the "func" which is defined in the package in which the macro is expanded. Not the package in which the macro is defined.
>>>
>>>>> On Apr 11, 2018, at 10:33 AM, Bob Felts <wrf3@stablecross.com> wrote:
>>>>>
>>>>> Suppose that in package my-macros, I have:
>>>>>
>>>>> (defmacro foo (bar p v)
>>>>> `(defun ,bar ()
>>>>> (if (func ,p)
>>>>> ,v)))
>> The difficulty of doing this is a sign the design doesn't really make sense. Anyone using FOO has to know that they must define a function FUNC in their package. There's no sign of that in the call, and no way to use a different name, if they already have a FUNC (perhaps from a library) that does something else.
>>
>> Had you made FUNC a parameter of the macro, e.g., (foo func ...), then the macro would be more flexible and you wouldn't have this problem.
>>
>>
>> --
>> ................................................
>> Christopher Riesbeck
>> Associate Professor, Electrical Engineering and Computer Science
>> McCormick School of Engineering
>> Northwestern University
>>
>> 2145 Sheridan Rd., Evanston, IL 60208
>>
>> Home page: http://www.cs.northwestern.edu/~riesbeck/
>> Calendar: http://www.cs.northwestern.edu/~riesbeck/calendar.html
>>
>
> _______________________________________________
> Lisp Hug - the mailing list for LispWorks users
> lisp-hug@lispworks.com
> https://urldefense.proofpoint.com/v2/url?u=http-3A__www.lispworks.com_support_lisp-2Dhug.html&d=DwIDAg&c=yHlS04HhBraes5BQ9ueu5zKhE7rtNXt_d012z2PA6ws&r=rYww9Ur1WoBi28j2XhN4rwFLo31INs66FdFiX_Ro7pI&m=tmzqa4ZqNiaMr39HHYTs3Eax-arnp6nD75rfAyHpJg8&s=bsJHPDIhDjO8tx2DUmLpvDsZ1hQBPTO3FzxbcHEOWZs&e=
--
.................................................
Christopher Riesbeck
Associate Professor, Electrical Engineering and Computer Science
McCormick School of Engineering
Northwestern University
2145 Sheridan Rd., Evanston, IL 60208
Home page: http://www.cs.northwestern.edu/~riesbeck/
Calendar: http://www.cs.northwestern.edu/~riesbeck/calendar.html
_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html