On Mon, May 4, 2020 at 9:04 AM Jean Abou Samra <j...@abou-samra.fr> wrote:
>
> Date: Mon, 4 May 2020 12:21:30 +0200
> From: Jean Abou Samra <j...@abou-samra.fr>
> To: lilypond-devel@gnu.org
> Subject: Question (define and set!)
> Message-ID: <8f79371e-400b-574b-3126-146d008cf...@abou-samra.fr>
> Content-Type: text/plain; charset=utf-8; format=flowed
>
> Hi,
>
> Why do you often find constructs similar to this one in LilyPond's source?
>
> midi.scm line 26:
>
> (define-session-public absolute-volume-alist '())
> (set! absolute-volume-alist (append absolute-volume-alist etc.))
>
> line 72:
>
> (define instrument-names-alist '())
> (set! instrument-names-alist ...
>
> Is there any difference with (define-session-public
> absolute-volume-alist '(...)) ? I suspect there is one since this is
> frequent but I can't figure out what the purpose is here.

Part of it is likely due to a subtle issue in Scheme. set! already
assumes that the variable exists; define not only gives it a value,
but tells Scheme that the variable actually represents something. Thus

(define x (1+ x))

creates an error, because it assumes that x is undefined, but is
trying to use the value of the (nonexistent) variable x. The proper
command is set!.

More information is available at:

https://stackoverflow.com/questions/5406064/difference-between-define-let-and-set

--- Christopher Heckman

Reply via email to