From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Linus_Bj=C3=B6rnstam?= Newsgroups: gmane.lisp.guile.user Subject: Re: Macro to prepend element to list Date: Sat, 20 Mar 2021 19:10:06 +0100 Message-ID: <40b6ccf5-d3ec-406c-b05c-bf55ebc011b5@www.fastmail.com> References: <7e1286e7-3135-7747-9e25-395ffab3362e@abou-samra.fr> <7fbe592f-2816-480d-86ca-3876277d2461@www.fastmail.com> <92e5fb1a-a57b-b65c-28a6-f6d3ef397fb2@abou-samra.fr> Mime-Version: 1.0 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20922"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Cyrus-JMAP/3.5.0-alpha0-206-g078a48fda5-fm-20210226.001-g078a48fd To: "Jean Abou Samra" , guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Mar 20 19:11:01 2021 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lNg3x-0005Hq-6d for guile-user@m.gmane-mx.org; Sat, 20 Mar 2021 19:11:01 +0100 Original-Received: from localhost ([::1]:35272 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNg3w-0003sg-65 for guile-user@m.gmane-mx.org; Sat, 20 Mar 2021 14:11:00 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41206) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lNg3V-0003ov-VM for guile-user@gnu.org; Sat, 20 Mar 2021 14:10:34 -0400 Original-Received: from out5-smtp.messagingengine.com ([66.111.4.29]:45147) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lNg3U-0000Qd-3Z for guile-user@gnu.org; Sat, 20 Mar 2021 14:10:33 -0400 Original-Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 812AB5C00D0; Sat, 20 Mar 2021 14:10:31 -0400 (EDT) Original-Received: from imap42 ([10.202.2.92]) by compute6.internal (MEProxy); Sat, 20 Mar 2021 14:10:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.se; h= mime-version:message-id:in-reply-to:references:date:from:to :subject:content-type:content-transfer-encoding; s=fm2; bh=fdkjM 2h59LXYBaqr4oQAUJ+HC799KKS73nFggmkkOSg=; b=y47PWt4Hgv2W/iKWSxeBa oyXt1f6+oopK2GPewjlAlZkHgAKNh3LfDVOrmCw1u3tOTFBy182OvyJ38/bSLLRd KrCsG5r0g1kHkNktuaoiE/uS/Zn+cBECG+kyINSQlm/WkVFHDFAJalNmIJf8jnrM B7j/l0qXlU4a0eUie9vvPGsYSnSA4A7qwvdLpW5IaPrJG6QQhlf7FGWCH9vTwUpK 0OTXTheP9vqAigTHO2EFgEHORa9tGgibvZWJKQbcntLsYg+izpWrGJ3cjB7wQlKJ HW2bg4JL5+diaVGJSKSwI8MF4o9lp+LWoJpihxAG3iBim5JmVYkPXwkc3EiBf1ge Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=fdkjM2h59LXYBaqr4oQAUJ+HC799KKS73nFggmkkO Sg=; b=J/Y7s6TvrUshsnEIHe1JH3nuHsXXiacoGy5l54MgxTx6H/3I/B17g7eXx QWobjWav/J3H2BZG/jysT5xOWjOXIPxly/yF8bag/MNb/9K2/25CyNl0rW7z7I6N lfYAnFmSGIPFkqZDvoLmuNjHRaG5iF0CAH3qB0EkUvhGmHLRnoaMmfvS0uSO+Dep 8aBGcSMQhLikMWy2s8gKtZMkZ8EDJ650QN7uUJnH2HOx0Hq1nh/QKeZCHc+q32MJ aSlbZEY8EkFhi8SAX0x4xXmcGnNMEr72YevjwN7kITD58bL05wGy+5lkTxytGC4E 3AxYjeLYtziThpKr0p0Q5AO6luwBQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudegtddguddtgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepnfhi nhhushgpuehjnphrnhhsthgrmhcuoehlihhnuhhsrdhinhhtvghrnhgvthesfhgrshhtmh grihhlrdhsvgeqnecuggftrfgrthhtvghrnhepkeelveeiveeljeffteeiledtleekveet udehfeehudeifffftddtgeejieehtdejnecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomheplhhinhhushdrihhnthgvrhhnvghtsehfrghsthhmrghi lhdrshgv X-ME-Proxy: Original-Received: by mailuser.nyi.internal (Postfix, from userid 501) id DFCA9310005D; Sat, 20 Mar 2021 14:10:30 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface In-Reply-To: <92e5fb1a-a57b-b65c-28a6-f6d3ef397fb2@abou-samra.fr> Received-SPF: pass client-ip=66.111.4.29; envelope-from=linus.internet@fastmail.se; helo=out5-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:17372 Archived-At: I see! To be honest, this seems like a guile-1.8ism... I don't think such code = would work for guile2 though 3. Why? Because your are mutating a pointer= local to your procedure, not the actual data pointed to by the music pr= operty You are modifying the pointer to the list returned by the call, n= ot the list where it is stored.=20 I don't know enough lilypond, but a more standard way of doing that woul= d be something like (ly:music-property-set! m 'articulations (cons (mak= e-music 'ArticulationEvent 'articulation-type "staccato") (ly:music-prop= erty m 'articulations))) (or a shorthand thereof). More verbose, sure, but also standard scheme... This could of course be abstracted away in some nicer way, like somethin= g I just pulled out of my posterior without much prior knowledge of lily= pond (except for a fingering chart for bassoon I maintain):=20 (update! (select '(note-event 'artuculations)) (lambda (p) (cons (make-m= usic ...) m))) This could be done with higher order functions and passing lambdas arou= nd without having to rely on macros... --=20 Linus Bj=C3=B6rnstam On Sat, 20 Mar 2021, at 18:05, Jean Abou Samra wrote: > Le 20/03/2021 =C3=A0 17:04, Linus Bj=C3=B6rnstam a =C3=A9crit=C2=A0: >=20 > > Well, mutating like that is not very common, except for maybe with a= lists. > > > > In which situations are you mutating the list like that? Usually you= would build a reverse list using a recursive function and an accumulato= r, which can be done without set! (which has a boxing overhead). >=20 >=20 > Mostly to mutate properties of LilyPond's probs (property objects). > This works somewhat like Guile's object properties. For example, to > add articulations on notes: >=20 > \version "2.23.1" >=20 > #(define-macro (prepend! thing lst) > =C2=A0=C2=A0 `(set! ,lst (cons ,thing ,lst))) >=20 > addStaccato =3D > #(define-music-function (music) (ly:music?) > =C2=A0=C2=A0 (map-some-music > =C2=A0=C2=A0=C2=A0=C2=A0 (lambda (m) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (if (music-is-of-type? m 'note-e= vent) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (prepend= ! (make-music 'ArticulationEvent 'articulation-type=20 > "staccato") > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (ly:music-property m= 'articulations))) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 #f) > =C2=A0=C2=A0=C2=A0=C2=A0 music)) >=20 > \addStaccato { c'4 d' e'8 f' g' a' } >=20 > (Output attached.) >=20 > It is also of use in so-called engravers (it's harder > to find a simple use case for these). I guess all of this > is so LilyPond-specific that it suits better in my personal > libraries, and maybe upstream if I see a compelling use > case in the code base. >=20 > Thanks! > Jean >=20 >=20 > Attachments: > * prepend-example.ly > * prepend-example.pdf