Re: How to update an agrument passed by name in scheme
- From: Anton van Straaten <anton@xxxxxxxxxxxxxxxx>
- Date: Thu, 02 Feb 2006 19:36:27 GMT
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
.
- Follow-Ups:
- Re: How to update an agrument passed by name in scheme
- From: ggem
- Re: How to update an agrument passed by name in scheme
- From: Matthias Blume
- Re: How to update an agrument passed by name in scheme
- References:
- How to update an agrument passed by name in scheme
- From: artejera
- Re: How to update an agrument passed by name in scheme
- From: Anton van Straaten
- Re: How to update an agrument passed by name in scheme
- From: Joe Marshall
- Re: How to update an agrument passed by name in scheme
- From: H.
- Re: How to update an agrument passed by name in scheme
- From: Anton van Straaten
- Re: How to update an agrument passed by name in scheme
- From: Pascal Bourguignon
- How to update an agrument passed by name in scheme
- Prev by Date: Re: How to update an agrument passed by name in scheme
- Next by Date: Re: How to destroy a system
- Previous by thread: Re: How to update an agrument passed by name in scheme
- Next by thread: Re: How to update an agrument passed by name in scheme
- Index(es):
Relevant Pages
|