Re: Local/temporary methods in CLOS

Liste des GroupesRevenir à cl lisp 
Sujet : Re: Local/temporary methods in CLOS
De : monnier (at) *nospam* iro.umontreal.ca (Stefan Monnier)
Groupes : comp.lang.lisp
Date : 12. Mar 2025, 04:00:07
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <jwvldtb55n7.fsf-monnier+comp.lang.lisp@gnu.org>
References : 1 2 3 4
User-Agent : Gnus/5.13 (Gnus v5.13)
I suspect Costanza's ContextL may speaks to these requirements.

It does.

You are in some scope in which you would like to modify the behavior
of a generic function, so it has different methods. In "COP"
(context-oriented programming) that behavior would belong to a layer.
You dynamically activate and deactivate the layer (by name, I think).
The layer defines the methods (so physically they are not locally
enclosed in the scope(s) where you are activating the layer). That's a
feature, since you can activate a layer in multiple places.

Here's an example:

Say I implement a small DSL as a macro.  That DSL may itself want to
offer the ability to extend the language with macros.  Each macro and
special form in the DSL could map to a method (using an `eql`
specializer on the head of the term, typically), so if you want your DSL
to offer local macros (think `macrolet`), you need to temporarily add
methods during the macro expansion of the subterms.  For some DSLs it
might make sense to define sets of macros which can be thought of as
"namespaces", and then locally activate them, which maps neatly to
ContextL's notion of layers and temporary activation of them.

To take DSL examples from ELisp:

- PEG has `define-peg-rule` (which could be implemented as defining
  a new method) but it also has `define-peg-ruleset` (which could map
  to defining a new layer) and then `with-peg-rules` (which can
  locally activate layers, and also define a new layer "on the spot").
- RX has `rx-define` as well as `rx-let` (which both defines a layer
  and activates it) but no way to define a layer separately from
  its activation.  Yet, looking at RX users, the ability to define a set
  of RX constructs and activate them later would be welcome.
- Pcase has `pcase-defmacro` but not "macrolet" equivalent.  It would
  make a lot of sense to add some way to have local Pcase macros.


        Stefan

Date Sujet#  Auteur
11 Mar 25 * Local/temporary methods in CLOS5Stefan Monnier
11 Mar 25 `* Re: Local/temporary methods in CLOS4Kaz Kylheku
11 Mar 25  `* Re: Local/temporary methods in CLOS3Stefan Monnier
12 Mar 25   `* Re: Local/temporary methods in CLOS2Kaz Kylheku
12 Mar 25    `- Re: Local/temporary methods in CLOS1Stefan Monnier

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal