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



Pascal Bourguignon wrote:
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.


Well, since AFAIK, scheme cannot "pass by name", we interpreted it as
"pass by reference".

This terminology is too ambiguous to be used without context. Scheme passes arguments by value, but it passes compound values by reference.

These things happen at different levels, i.e. arguments are evaluted to obtain a value to be passed, and the resulting (internal) value may be a reference.

What the OP meant by "passed by name" can also be described as "passing a variable by reference".

In Scheme, if you really want to pass a variable by reference, you can do so using a macro. If you want to pass a value by reference, you can do so using a compound value such as a pair or a vector; or by passing procedures which manipulate the value in question.

IIRC, Algol had "pass by name" too, and this kind of argument passing
is a big software engineering failure.

The OP's "passed by name", i.e. passing a variable by reference, isn't quite the same thing as the "call by name" argument passing used in Algol 60. Call by name argument passing essentially means that the arguments are passed without being evaluated. This does mean that variables are passed by reference, but it also means that more complex argument expressions are passed without being evaluated.

Call by name is not a failure in general: Lisp and Scheme macros still use it, as do pure functional languages like Haskell. (Or they use call-by-need, which is memoized call-by-name.)

In Algol 60, the problem was that the language had side effects, which don't mix well with call by name. In Lisp/Scheme macros, we still have to manually mitigate that problem, e.g. by forcing evaluation of arguments up front, if we're going to use them more than once in a macro.

As for lisp argument passing, indeed compound values are passed by
references and simple values are passed by value (Independently of boxing).

Becareful: vectors, strings, bignums, fixnums, characters, etc, all
but pairs ARE atomic! atom <=> not pair

I was using "atomic" in a more general sense. "Atom" in the old Lisp sense should be considered an obsolete term, and indeed it doesn't feature in more modern members of the Lisp family. ;-P

Anton
.



Relevant Pages

  • Re: segfault w/ block, but not file scope
    ... >>> Passing by reference has to do with passing around actual containers ... >> The language itself supports absolutely squat in regards to another ...
    (comp.lang.c)
  • Re: segfault w/ block, but not file scope
    ... >> Passing by reference has to do with passing around actual containers ... > The language itself supports absolutely squat in regards to another ... it is a mechanism of the language. ...
    (comp.lang.c)
  • Re: Finding the instance reference of an object [long and probably boring]
    ... reference implementation of the language uses "reference counting" to ... that Python has no way to declare reference variables. ... Suppose I write the following on some not-quite-Python language: ... OK, that's a fair argument, and I do suspect this is a big part of it -- when your language clearly supports passing object references and other types by-ref and by-val, and you can easily demonstrate the difference, then there is little temptation to claim that it doesn't do either one. ...
    (comp.lang.python)
  • Re: Using ref
    ... reference", as compared to a language that does not. ... Passing by reference means ... pointer/reference to the array being passed. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: no pointer in Java => my problem
    ... >>passed pointer in a C function either (that is, ... > you are passing is an adress and you can't change the address. ... > pass the value as an adrress when passing a reference, ... high level language and need to know how something behaves in *this ...
    (comp.lang.java.programmer)