• A library for building trees

    From Spiros Bousbouras@21:1/5 to All on Sun Aug 7 13:27:39 2022
    I have written a Common Lisp library for building trees which I'm making available under a "do anything you want license". It can be downloaded
    at http://vlaho.ninja/prog/#trbu .For a more detailed explanation here
    is an excerpt from
    http://vlaho.ninja/prog/trbu/README.txt
    {
    When writing code for macros , the macro code generally constructs a list
    which is the macro expansion. Sometimes you can do this using MAPCAR and similar. But often I found myself in a situation where I constructed a
    partial list and then , as I was parsing the code given in an invocation
    of the macro , I gradually wanted to add more elements to the end of the
    list. Using the standard APPEND for this gives quadratic performance. So
    what I was doing was to PUSH elements to the front of the list and , when
    I had created the whole expansion , I would do (reverse list) .With this approach the code I was writing often looked unnatural to me. In
    situations where one can construct the expansion list in one loop and it's
    not convenient to use MAPCAR {or similar} , many people would use LOOP .I
    don't like LOOP either so I needed a different solution hence I wrote this library. The main idea is that you can append to the list you are
    constructing in constant time rather than having to traverse the whole
    list from the start. It's not just for macro expansions obviously but I
    almost exlusively use it for that because , in every other situation where
    I need a sequence , I'm much more likely to use a vector than a list.
    }

    http://vlaho.ninja/prog/trbu/manual.txt has plenty of examples.

    --
    Genius. It's a word. What does it really mean? If I win, I'm a genius.
    If I don't, I'm not.
    Bobby Fischer

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peri Didaskalou@21:1/5 to Spiros Bousbouras on Tue Aug 9 15:37:54 2022
    On 2022-08-07 9:27 a.m., Spiros Bousbouras wrote:
    I have written a Common Lisp library for building trees which I'm making available under a "do anything you want license". It can be downloaded
    at http://vlaho.ninja/prog/#trbu .For a more detailed explanation here
    is an excerpt from
    http://vlaho.ninja/prog/trbu/README.txt
    {
    When writing code for macros , the macro code generally constructs a list which is the macro expansion. Sometimes you can do this using MAPCAR and similar. But often I found myself in a situation where I constructed a partial list and then , as I was parsing the code given in an invocation
    of the macro , I gradually wanted to add more elements to the end of the list. Using the standard APPEND for this gives quadratic performance. So
    what I was doing was to PUSH elements to the front of the list and , when
    I had created the whole expansion , I would do (reverse list) .With this approach the code I was writing often looked unnatural to me. In
    situations where one can construct the expansion list in one loop and it's not convenient to use MAPCAR {or similar} , many people would use LOOP .I don't like LOOP either so I needed a different solution hence I wrote this library. The main idea is that you can append to the list you are constructing in constant time rather than having to traverse the whole
    list from the start. It's not just for macro expansions obviously but I almost exclusively use it for that because , in every other situation where
    I need a sequence , I'm much more likely to use a vector than a list.
    }

    http://vlaho.ninja/prog/trbu/manual.txt has plenty of examples.


    Brilliant Spiro!
    It's always great to consider alternatives born out of need,
    preference and/or frustration.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Zyni=20Mo=C3=AB?=@21:1/5 to Spiros Bousbouras on Wed Aug 10 09:54:41 2022
    Spiros Bousbouras <spibou@gmail.com> wrote:
    I have written a Common Lisp library for building trees

    Tim Bradshaw's 'collecting' (https://tfeb.github.io/tfeb-lisp-hax/#collecting-lists-forwards-and-accumulating-collecting)
    also does some of these things. Does not do the tree thing, but does allow collecting into general objects.

    --
    the small snake

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)