From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Abou Samra Newsgroups: gmane.lisp.guile.user Subject: Re: Macro to prepend element to list Date: Sat, 20 Mar 2021 21:16:14 +0100 Message-ID: <9e46f19e-d66d-0009-2fd8-aebace21c3b9@abou-samra.fr> 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> <40b6ccf5-d3ec-406c-b05c-bf55ebc011b5@www.fastmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38705"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 To: =?UTF-8?Q?Linus_Bj=c3=b6rnstam?= , guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Mar 20 21:17:10 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 1lNi22-0009xA-Iz for guile-user@m.gmane-mx.org; Sat, 20 Mar 2021 21:17:10 +0100 Original-Received: from localhost ([::1]:38506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNi21-0008GU-8S for guile-user@m.gmane-mx.org; Sat, 20 Mar 2021 16:17:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54930) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lNi1V-0008GH-4C for guile-user@gnu.org; Sat, 20 Mar 2021 16:16:39 -0400 Original-Received: from mout.kundenserver.de ([212.227.17.13]:33737) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lNi1G-00049n-T4 for guile-user@gnu.org; Sat, 20 Mar 2021 16:16:33 -0400 Original-Received: from [192.168.1.20] ([82.65.251.18]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.184]) with ESMTPSA (Nemesis) id 1Mf0Jg-1luGsc0VsA-00gZpB; Sat, 20 Mar 2021 21:16:16 +0100 In-Reply-To: <40b6ccf5-d3ec-406c-b05c-bf55ebc011b5@www.fastmail.com> Content-Language: en-US X-Provags-ID: V03:K1:/wCo3RowLLvwCdKD02tdOxj5dgRjLLbaZs5yY7Gp2Hzsax44QA3 fE9oMxJCrwn6EHa7WvkzsnQi5JpzjdWosvAPpgljiwBUx9xLBfaaSrtRzeADgqtm9IKpJBn qVmIUuPwAarAySRJjKNb9se4ytjSgLrTvBeDTSqqIYLNI3oUZuGZAIVIM5QijNMWMoKsE7A NOS8ocq1ekiLbnS16AMxA== X-UI-Out-Filterresults: notjunk:1;V03:K0:19SlFFvgRlk=:g2o4n7BQV38Kw2nxrRdpLN 52ppro0EQ+xwe69+jqaXKEyxKa9ZNICYz0kOJGR5lUByDTSnjNta3TfvjxmEw28NsCJITqOM0 HTRF5s8C0tWBBu81AVbvngx8CHGffeOf18EidMLKwqmy69SBDhictaJgxl3u/nH8g8D7EtIOR oUn4Hhb1/KlsG+EAM7/GE7AuSf+MvJ9oHM+XsfITwobmPe2BU13Px+erOniVeeBk442GKoEsk iwNMfs75hJIdMeFKEuFln3zi3vneHbETUlZ8JWnW1yCqGfDNcfEVII/cleSPehqe1pf7o014H jWWSaZWpOjRf6AvuQta0cHZhYihKSber1Q/vCo71Ap4UCZe4a3cfMimHUdA0AjtfttmYcnuaN 6FOoPeoT83scVz37kly4IpKBeDfPXA5kDsxk+FJaVzg82GJnkcYRYstDneeo6INtIUgwl3F8K 7ovKETQgig== Received-SPF: none client-ip=212.227.17.13; envelope-from=jean@abou-samra.fr; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=unavailable 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:17373 Archived-At: Le 20/03/2021 à 19:10, Linus Björnstam a écrit : > 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 property You are modifying the pointer to the list returned by the call, not the list where it is stored. > > I don't know enough lilypond, but a more standard way of doing that would be something like (ly:music-property-set! m 'articulations (cons (make-music 'ArticulationEvent 'articulation-type "staccato") (ly:music-property m 'articulations))) (or a shorthand thereof). > > More verbose, sure, but also standard scheme... Well, not sure what you mean exactly, but ly:music-property is defined with a setter: (define-public ly:music-property   (make-procedure-with-setter ly:music-property                               ly:music-set-property!)) which makes the code equivalent to (ly:music-set-property! m 'articulations (cons ... (ly:music-property m 'articulations))), doesn't it? > This could of course be abstracted away in some nicer way, like something I just pulled out of my posterior without much prior knowledge of lilypond (except for a fingering chart for bassoon I maintain): > > (update! (select '(note-event 'artuculations)) (lambda (p) (cons (make-music ...) m))) > > This could be done with higher order functions and passing lambdas around without having to rely on macros... Indeed, we could do things along these lines: \version "2.23.1" #(define (ly:music-transform-property! music prop func)    (ly:music-set-property! music                            prop                            (func (ly:music-property music prop)))) addStaccato = #(define-music-function (music) (ly:music?)    (map-some-music      (lambda (m)        (if (music-is-of-type? m 'note-event)            (ly:music-transform-property!              m              'articulations              (lambda (elts)                (cons (make-music 'ArticulationEvent 'articulation-type "staccato")                      elts))))        #f)      music)) \addStaccato { c'4 d' e'8 f' g' a' } It is more verbose for prepending elements, but much more versatile, and 'cute' from (srfi srfi-26) can make the call more compact as well. Best regards, Jean