lilypond-user
[Top][All Lists]
Advanced

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

Re: scheme set list function


From: Andrew Bernard
Subject: Re: scheme set list function
Date: Mon, 8 Apr 2019 22:26:47 +1000

Hi Aaron,

I beg to differ. Here plain and clear from the start of the R5RS Scheme specification is the following:

Arguments to Scheme procedures are always passed by
value, which means that the actual argument expressions
are evaluated before the procedure gains control, whether
the procedure needs the result of the evaluation or not.

I am unable to deduce how the procedure evaluation can therefore be an implementation choice. Call by reference would alter the semantics of Scheme entirely. One of the main strengths of Scheme is that it supports lexical scoping so procedures can't alter variables outside the local scope, unless you resort to using global variables at the top level, but hopefully people no longer program like that.

I've never heard of any Scheme system that uses call by reference, and I would request that you provide evidence for that. If you can my Scheme world will be turned upside down.

I'll do another email about set-car! and list-set! a bit later.


Andrew



On Mon, 8 Apr 2019 at 12:41, Aaron Hill <address@hidden> wrote:
On 2019-04-07 6:01 pm, Andrew Bernard wrote:
> I am somewhat concerned that there is a misunderstanding you have about
> Scheme. Scheme procedures are call-by-value. This means the arguments
> are
> evaluated and the value then passed to the procedure. The value of the
> parameter in the calling environment cannot be changed. This is how C
> and
> Scheme and many other languages work. [In C you can pass a pointer to
> alter
> a variable outside the function. but there is no such thing in Scheme -
> for
> good reasons.] It's not call-by-reference.

The way I understand things, that's not entirely true.  Whether a Scheme
interpreter/compiler passes by value or reference is an implementation
detail.  Passing by reference is a convenient optimization to avoid
unnecessary copies and garbage; and near as I can tell this is very
commonly used across many environments.  As such, procedures can have
side effects where the objects that are passed to such procedures may be
modified.  Consider the 1+last! procedure I showed that is not a macro
itself, but it still has the side effect of altering the list.



reply via email to

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