From: Vsevolod
Subject: Code walker library for CL
Date: 
Message-ID: <e8fba1e2-496f-4735-9bba-6b3a9175eab6@o36g2000yqh.googlegroups.com>
Is there a general-purpose code-walker end-user library for ANSI CL?
I mean a properly documented, stable and maintained one? Dedicated to
this task.
Maybe there's a library, which has such targets, but needs some effort
in one of the mentioned directions to reach maturity?

I have looked at a general-purpose code-walker in ARNESI. But it
hardly can be considered stable, documented and user-friendly.
Besides, there's the CMU AI repository, but the available options need
some efforts at least in the fields of modernization, testing and
documentation to become a first-class library.

Besides I've looked at code-walkers in CL-CONT and ITERATE. They may
be called special-purpose ones. At least they are not well separated
from the libraries, they are part of.

Any suggestions?..
Thanks!

Vsevolod Dyomkin

From: Marco Antoniotti
Subject: Re: Code walker library for CL
Date: 
Message-ID: <0881b2fa-589d-4c58-adec-f8334389939e@37g2000yqp.googlegroups.com>
On Mar 26, 7:46 pm, Vsevolod <········@gmail.com> wrote:
> Is there a general-purpose code-walker end-user library for ANSI CL?

Now.  Let's go in complaining mode and talk about some *real* issues.

The answer is no.  And you cannot build one portably because the CLtL2
environment API (or a similar one) is not always there.  See what CL-
WALKER tries to do in this respect.


> I mean a properly documented, stable and maintained one? Dedicated to
> this task.
> Maybe there's a library, which has such targets, but needs some effort
> in one of the mentioned directions to reach maturity?
>
> I have looked at a general-purpose code-walker in ARNESI. But it
> hardly can be considered stable, documented and user-friendly.
> Besides, there's the CMU AI repository, but the available options need
> some efforts at least in the fields of modernization, testing and
> documentation to become a first-class library.
>
> Besides I've looked at code-walkers in CL-CONT and ITERATE. They may
> be called special-purpose ones. At least they are not well separated
> from the libraries, they are part of.

That's the best you can do.  Write a special purpose one.  I think
Pascal B. has a decent one.  Do not expect to be able to reliably and
portably get information about macrolet or symbol-macros, or declared
types of bindings outside code you have full control of.

> Any suggestions?..

Talk to the vendors/implementors (plural mandatory).

Cheers
--
Marco
From: Vsevolod
Subject: Re: Code walker library for CL
Date: 
Message-ID: <4941d293-818a-4c12-b5fa-78bf244aa918@f19g2000yqo.googlegroups.com>
On Mar 26, 9:36 pm, Marco Antoniotti <·······@gmail.com> wrote:
> The answer is no.  And you cannot build one portably because the CLtL2
> environment API (or a similar one) is not always there.  See what CL-
> WALKER tries to do in this respect.

Thanks for the pointer. I see that CL-WALKER actually roots in ARNESI.
And it seems, that it's what I was looking for. Strange, that I've
missed it.

And could you explain, why the environment API isn't always there?

Thanks,
Vsevolod
From: Marco Antoniotti
Subject: Re: Code walker library for CL
Date: 
Message-ID: <ca5dda00-e950-4d6f-a8e4-f30d42b5d016@f11g2000vbf.googlegroups.com>
On Mar 26, 9:27 pm, Vsevolod <········@gmail.com> wrote:
> On Mar 26, 9:36 pm, Marco Antoniotti <·······@gmail.com> wrote:
>
> > The answer is no.  And you cannot build one portably because the CLtL2
> > environment API (or a similar one) is not always there.  See what CL-
> > WALKER tries to do in this respect.
>
> Thanks for the pointer. I see that CL-WALKER actually roots in ARNESI.
> And it seems, that it's what I was looking for. Strange, that I've
> missed it.

CL-WALKER totally reimplements the ARNESI walker (I can be wrong:
please correct me!  This is just my angle).  The ARNESI walker is
essentially the WALKER you can download from the CMU AI Repository.
CL-WALKER takes to route of providing you with an AST of a Lisp
program, which may or may not be an overkill.  Plus it forces you to
do something that you would not do with WALKER, which is to program in
an event driven (or SAX for the younger crowd) way.

> And could you explain, why the environment API isn't always there?

It did not make it in the ANSI.  Implementors/vendors are not
compelled to provide it.  Franz has an excellent and extended
implementation of it (although it changes at least one signature
w.r.t. the CLtL2 spec).  CMUCL/SBCL has primitives that allow you to
implement it.  LW dropped a couple of functions in the passage to 5.x,
thus crippling the ARNESI walker (hence CL-WALKER and the older
WALKER).  I don't know about ABCL, CCL, Clisp, Corman, and ECL.

Hence my advice stands.  Talk to the implementors/vendors and ask them
to provide at least the CLtL2 API at a minimum.  In a PW they (or you
know who :) ) would hash out a more polished API.

Cheers
--
Marco
From: Pillsy
Subject: Re: Code walker library for CL
Date: 
Message-ID: <92275e1b-a0d0-4366-862d-02f56f25a28b@e25g2000vbe.googlegroups.com>
On Mar 26, 6:06 pm, Marco Antoniotti <·······@gmail.com> wrote:
> On Mar 26, 9:27 pm, Vsevolod <········@gmail.com> wrote:
[...]
> > And could you explain, why the environment API isn't always there?
[...]
> CMUCL/SBCL has primitives that allow you to implement it.

SBCL also has a contrib module which actually does implement it.

Cheers,
Pillsy
From: Raymond Toy
Subject: Re: Code walker library for CL
Date: 
Message-ID: <sxdskkyhe5z.fsf@rtp.ericsson.se>
>>>>> "Pillsy" == Pillsy  <·········@gmail.com> writes:

    Pillsy> On Mar 26, 6:06�pm, Marco Antoniotti <·······@gmail.com> wrote:
    >> On Mar 26, 9:27�pm, Vsevolod <········@gmail.com> wrote:
    Pillsy> [...]
    >> > And could you explain, why the environment API isn't always there?
    Pillsy> [...]
    >> CMUCL/SBCL has primitives that allow you to implement it.

    Pillsy> SBCL also has a contrib module which actually does implement it.

CMUCL also has the environment API.

And I believe both (among others) will run Allegro's envanal code,
which extends the CLtL1 environment API.

Ray
From: Pascal J. Bourguignon
Subject: Re: Code walker library for CL
Date: 
Message-ID: <87prg4c9rb.fsf@galatea.local>
Marco Antoniotti <·······@gmail.com> writes:

> On Mar 26, 7:46�pm, Vsevolod <········@gmail.com> wrote:
>> Is there a general-purpose code-walker end-user library for ANSI CL?
>> Besides I've looked at code-walkers in CL-CONT and ITERATE. They may
>> be called special-purpose ones. At least they are not well separated
>> from the libraries, they are part of.
>
> That's the best you can do.  Write a special purpose one.  I think
> Pascal B. has a decent one.  

Not yet.  But I'm planing writting one indeed.


> Do not expect to be able to reliably and
> portably get information about macrolet or symbol-macros, or declared
> types of bindings outside code you have full control of.
>
>> Any suggestions?..
>
> Talk to the vendors/implementors (plural mandatory).

Indeed, implementations often provide one. 
Eg. #+clisp ext:expand-form


-- 
__Pascal Bourguignon__
From: Rob Warnock
Subject: Re: Code walker library for CL
Date: 
Message-ID: <0eKdnVp6xp_Xt1HUnZ2dnUVZ_tPinZ2d@speakeasy.net>
Pascal J. Bourguignon <···@informatimago.com> wrote:
+---------------
| Indeed, implementations often provide one. 
| Eg. #+clisp ext:expand-form
+---------------

+cmu walker:walk-form

Signature:

    WALKER:WALK-FORM (form &optional environment walk-function)

where the default walk-function is:

    (lambda (subform context env)
      (declare (ignore context env))
      subform)))

There's also WALKER:MACROEXPAND-ALL (a wrapper around WALK-FORM,
which binds special variable WALKER:WALK-FORM-EXPAND-MACROS-P to T),
which is useful when you want to see the expansions of things
inside special forms, e.g.:

    > (macroexpand
	'(let ((x 1))
	   (incf x)))

    (LET ((X 1))
      (INCF X))
    NIL
    > (walker:macroexpand-all
	'(let ((x 1))
	   (incf x)))

    (LET ((X 1))
      (LET* ((#1=#:G1589 1) (#2=#:G1588 (+ X #1#)))
	  (SETQ X #2#)))
    > 


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Tobias C. Rittweiler
Subject: Re: Code walker library for CL
Date: 
Message-ID: <874oxgt1g0.fsf@freebits.de>
···@informatimago.com (Pascal J. Bourguignon) writes:

> Indeed, implementations often provide one. 
> Eg. #+clisp ext:expand-form

That one used to behave surprisingly on EVAL-WHEN forms; it only
descends into them if :EXECUTE is present. The reason is that the
function is used inside the interpreter part where this behaviour makes
sense.

  -T.
From: gugamilare
Subject: Re: Code walker library for CL
Date: 
Message-ID: <c8bc41d1-6bd2-4c55-9d5a-a4fdd8873cad@y9g2000yqg.googlegroups.com>
On 26 mar, 15:46, Vsevolod <········@gmail.com> wrote:
> Is there a general-purpose code-walker end-user library for ANSI CL?
> I mean a properly documented, stable and maintained one? Dedicated to
> this task.
> Maybe there's a library, which has such targets, but needs some effort
> in one of the mentioned directions to reach maturity?
>
> I have looked at a general-purpose code-walker in ARNESI. But it
> hardly can be considered stable, documented and user-friendly.

You need to learn how to investigate. It is not that hard to
understand Arnesi's code walker.
This is not a CL only issue. In any language there are many libraries
that aren't properly documented. You are free to create documentation
for Arnesi's code walker if you want, and I am sure Arnesi's
developers will be grateful if you do so.

But I don't see why it is unstable. Can you show us why it is not
stable?

> Besides, there's the CMU AI repository, but the available options need
> some efforts at least in the fields of modernization, testing and
> documentation to become a first-class library.
>
> Besides I've looked at code-walkers in CL-CONT and ITERATE. They may
> be called special-purpose ones. At least they are not well separated
> from the libraries, they are part of.
>
> Any suggestions?..
> Thanks!
>
> Vsevolod Dyomkin
From: Vsevolod
Subject: Re: Code walker library for CL
Date: 
Message-ID: <0c2cff6e-ce1b-481c-aca9-0f8de44b570c@o36g2000yqh.googlegroups.com>
On Mar 26, 10:00 pm, gugamilare <··········@gmail.com> wrote:
> On 26 mar, 15:46, Vsevolod <········@gmail.com> wrote:
> You need to learn how to investigate. It is not that hard to
> understand Arnesi's code walker.

I found it harder, though, than to understand the Iterate one.

> This is not a CL only issue.
Did I say it is?

> But I don't see why it is unstable. Can you show us why it is not
> stable?

Somehow I've got that impression, when I looked at its source code.
Maybe it was just for a lot of code without any docstrings and
comments. The code seems to be assembled together at once, but not
tested heavily in different situations (otherwise there would be some
minor corrections with comments, why it's so -- look at iterate to see
what I mean). Besides, there's walk and unwalk, which should be
combined or shouldn't?
Well, maybe I've just got the wrong impression. I don't insist on
"instability".

Overall, I'm willing to find a library, that is most user-friendly. I
quite understand, that I can take any and bring it to the desired
level. Maybe, I'll do that. But first I try to investigate (by
asking).

Best regards,
Vsevolod
From: gugamilare
Subject: Re: Code walker library for CL
Date: 
Message-ID: <a8efb354-5d50-490c-99ce-7a87e409dec6@f11g2000vbf.googlegroups.com>
On 26 mar, 17:20, Vsevolod <········@gmail.com> wrote:
> On Mar 26, 10:00 pm, gugamilare <··········@gmail.com> wrote:
>
> > On 26 mar, 15:46, Vsevolod <········@gmail.com> wrote:
> > You need to learn how to investigate. It is not that hard to
> > understand Arnesi's code walker.
>
> I found it harder, though, than to understand the Iterate one.
>
> > This is not a CL only issue.
>
> Did I say it is?
>
> > But I don't see why it is unstable. Can you show us why it is not
> > stable?
>
> Somehow I've got that impression, when I looked at its source code.
> Maybe it was just for a lot of code without any docstrings and
> comments. The code seems to be assembled together at once, but not
> tested heavily in different situations (otherwise there would be some
> minor corrections with comments, why it's so -- look at iterate to see
> what I mean). Besides, there's walk and unwalk, which should be
> combined or shouldn't?

You first walk the code, and it produces a series of classes. You can
create methods / functions to operate on these classes and either
produce other classes or to produce code directly. If you produce
classes, or if you don't touch them at all, you unwalk it, and you
will obtain the same form, except that all macros will be expanded.

Here is an example of use, this transforms lisp-2 code into lisp-1
code:

http://www.cl-user.net/asp/wiYd2/sdataQIU2MwAKCwBIDQ30CH8X8yBX8yBXnMq=/sdataQu3F$sSHnB==

Last time I checked, I could safely walk and unwalk forms
successfully, without any problems.

> Well, maybe I've just got the wrong impression. I don't insist on
> "instability".
>
> Overall, I'm willing to find a library, that is most user-friendly. I
> quite understand, that I can take any and bring it to the desired
> level. Maybe, I'll do that. But first I try to investigate (by
> asking).

Well, that is the right way to do it, for sure.
>
> Best regards,
> Vsevolod