lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: scheme set list function


From: David Kastrup
Subject: Re: scheme set list function
Date: Tue, 09 Apr 2019 10:29:00 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Gianmaria Lari <address@hidden> writes:

> Ciao Harm, Andrew, Aaron and David,
>
> this is what I have been able to do adapting Harm code:
>
> \version "2.21.0"
> foo =
> #(let ((x '(1)))
>   (define-scheme-function (arg)(symbol?)
>     (case arg
>       ((incNumber) (set! x (append (drop-right x 1) (list (1+ (last x))))))
>       ((unindent) (drop-right! x 1))
>       ((indent) (append! x '(1)))
>       ((reset) (set! x '(1))))
>     (object->string x)))

Harm did not accidentally write (let ((x (cons 1 0))) ... here.  '(1) is
a _constant_ list where you guarantee to the Scheme interpreter that you
will not modify any cons cell of the list and it can place it in
read-only memory.  If now the next call is 'indent , this guarantee is
violated, possibly leading to crashes and inconsistencies in shared
constants.  Then you use append! and drop-right! for list manipulation
and rely on their side effects to do what you want.  Those side effects
are optional.  This is rather bad Scheme code.  What are the goals you
intend to achieve with those changes?

-- 
David Kastrup



reply via email to

[Prev in Thread] Current Thread [Next in Thread]