unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: "Linus Björnstam" <linus.internet@fastmail.se>
To: "Jean Abou Samra" <jean@abou-samra.fr>, guile-user@gnu.org
Subject: Re: Macro to prepend element to list
Date: Sat, 20 Mar 2021 17:04:56 +0100	[thread overview]
Message-ID: <7fbe592f-2816-480d-86ca-3876277d2461@www.fastmail.com> (raw)
In-Reply-To: <7e1286e7-3135-7747-9e25-395ffab3362e@abou-samra.fr>

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
> 
> 
>



  reply	other threads:[~2021-03-20 16:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-20 14:24 Macro to prepend element to list Jean Abou Samra
2021-03-20 16:04 ` Linus Björnstam [this message]
2021-03-20 17:05   ` Jean Abou Samra
2021-03-20 18:10     ` Linus Björnstam
2021-03-20 20:16       ` Jean Abou Samra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7fbe592f-2816-480d-86ca-3876277d2461@www.fastmail.com \
    --to=linus.internet@fastmail.se \
    --cc=guile-user@gnu.org \
    --cc=jean@abou-samra.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).