Re: How to update an agrument passed by name in scheme



Anton van Straaten <anton@xxxxxxxxxxxxxxxx> writes:

H. wrote:
I have to admit I don't get this part of Scheme, in that a lot of
people say "say how much easier it is to do this thing in Scheme as
opposed to whatever other language". But passing by reference is
exceptionally easy in some of those other languages, and not so easy in
Scheme, which, based on this thread, cannot be done trivially.

Simplifying a bit, non-atomic values (pairs, vectors etc.) *are*
passed by reference in Scheme. The OP talked about "passed by name",
which is a little different.

I know you are hiding this under the blanket of "simplifying a bit",
but I would prefer not to confuse issues in this manner. In Scheme
(and in C), *all* values are passed by value, no matter whether they
are "atomic" or "non-atomic". The difference is in the fact that some
values /are/ references, so when they get passed by value, what gets
passed is a reference, namely the reference that is the value.

This is different from what happens with Pascal's VAR parameters or
C++'s reference parameters, where the compiler effectively inserts an
implicit address-of operator at the call site and an implicit
dereference operation at each use of the formal parameter within the
procedure body. In languages that have first-class references (like
C's pointers, Scheme's CONS cells, or ML's ref), one can achieve the
same effect by passing such a first-class reference value. But this
requires to /explicitly/ create the appropriate reference value at the
call site (or earlier), and to /explicitly/ dereference it (*,
car/cdr, !) at each use.

Matthias
.



Relevant Pages

  • Re: Whats the difference of those two ways of passing parameters
    ... Parameter passing in C is beautifully simple: ... reference", you just pass a pointer and modify the object through that. ... In languages like Java, ... int foo = 42; ...
    (comp.lang.c)
  • Re: How to update an agrument passed by name in scheme
    ... opposed to whatever other language". ... Scheme, which, based on this thread, cannot be done trivially. ... passed by reference in Scheme. ... IIRC, Algol had "pass by name" too, and this kind of argument passing ...
    (comp.lang.scheme)
  • Re: How to update an agrument passed by name in scheme
    ... formal semantics of Scheme are presented. ... >> value, what gets passed is a reference, namely the reference that is ... you might consider restating "passing the reference that is the ... The original context was rather far from the formal semantics of Scheme. ...
    (comp.lang.scheme)
  • Re: How to update an agrument passed by name in scheme
    ... what would you call the thing in Scheme with an external representation of the form (x. ... I was not trying to give an introductory treatment. ... that any use of the two words "by" and "reference" consecutively in the same sentence trigger a rewrite rule in your brain. ... confusion -- precisely the kind of confusion that we are seeing here. ...
    (comp.lang.scheme)
  • Re: How to update an agrument passed by name in scheme
    ... people say "say how much easier it is to do this thing in Scheme as opposed to whatever other language". ... But passing by reference is exceptionally easy in some of those other languages, and not so easy in Scheme, which, based on this thread, cannot be done trivially. ... that foo is an ordinary procedure, then without even knowing what foo does, we can safely conclude that the result of the expression is 5. ...
    (comp.lang.scheme)