[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Macro to prepend element to list
From: |
Linus Björnstam |
Subject: |
Re: Macro to prepend element to list |
Date: |
Sat, 20 Mar 2021 17:04:56 +0100 |
User-agent: |
Cyrus-JMAP/3.5.0-alpha0-206-g078a48fda5-fm-20210226.001-g078a48fd |
Well, mutating like that is not very common, except for maybe with alists.
In which situations are you mutating the list like that? Usually you would
build a reverse list using a recursive function and an accumulator, which can
be done without set! (which has a boxing overhead).
--
Linus Björnstam
On Sat, 20 Mar 2021, at 15:24, Jean Abou Samra wrote:
> Hello,
>
> I find myself frequently using the following macro:
>
> (define-macro (prepend! thing lst)
> `(set! ,lst (cons ,thing ,lst)))
>
> Have I missed a module somewhere that does this kind of things?
> At least, I couldn't find anything in SRFIs. It may also be the
> case that this is too specific to certain non-functional usages
> (LilyPond in my case).
>
> Thanks in advance,
> Jean Abou Samra
>
>
>