[Top][All Lists]

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

Re: Some improvements for cl-flet

From: Robin Tarsiger
Subject: Re: Some improvements for cl-flet
Date: Mon, 11 Oct 2021 19:29:27 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.1

Richard Stallman wrote:
   > Yes, but SYMBOL-MACROLET is relatively common in Common Lisp programs,
   > which in itself warrants its inclusion in a Common Lisp emulation
   > library, IMO.

I am sure you know what you're referring to.  But I am shocked this
would be used frequently.  Can you plesae show me why and how?

One key category of use is for macros that take a body and want to expose
variable-like places to that body. For instance, there is the with-slots macro
which binds convenience aliases for slots of a CLOS object, so that:

  (with-slots (foo bar) object
    (setf foo bar))

is equivalent to:

  (setf (slot-value object 'foo) (slot-value object 'bar))

and with-slots can be implemented using symbol-macrolet. Alternatively, any
other place where a macro wants to expose a symbol which may or may not be
a local variable proper in every case, while preserving a compatible interface
with the provided body, may use symbol-macrolet to provide this decoupling.

It is much less common to use symbol-macrolet directly in application code,
though once or twice I have seen it used for local constants in a manner
similar to how parameterless C macros are used for constants.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]