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.

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


In Common Lisp, we could "pass by name" global variables:

(defun do-something (name) (incf (symbol-value name)))
(defvar *x* 0)
(defvar *y* 0)
(do-something '*x*)
(do-something '*y*)
(do-something '*y*)
(list *x* *y*)
--> (1 2)

This wouldn't work for lexical variables.

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



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


--
__Pascal Bourguignon__ http://www.informatimago.com/

"What is this talk of "release"? Klingons do not make software
"releases". Our software "escapes" leaving a bloody trail of
designers and quality assurance people in its wake."
.



Relevant Pages

  • 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)
  • 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)