[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question (define and set!)
From: |
Christopher Heckman |
Subject: |
Re: Question (define and set!) |
Date: |
Mon, 4 May 2020 16:19:23 -0700 |
On Mon, May 4, 2020 at 9:04 AM Jean Abou Samra <address@hidden> wrote:
>
> Date: Mon, 4 May 2020 12:21:30 +0200
> From: Jean Abou Samra <address@hidden>
> To: address@hidden
> Subject: Question (define and set!)
> Message-ID: <address@hidden>
> 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