Michael Sperber wrote:
> Mikael Tillenius <mti_at_tillenius.com> writes:
>
>
>> Description: In section 1, top of right column on page 6 of the
>> report, argument passing is discussed. Quote "Note that call-by-value
>> refers to a different distinction between by-value and by-reference
>> passing in Pascal. In Scheme, all data structures are passed by
>> reference." This seems to imply that Scheme passes arguments similar
>> to how Pascals call-by-reference. This is not true, for example
>> call-by-reference would make it possible to implement a procedure
>> "swap" so that a call "(swap a b)" would swap the values of "a" and
>> "b".
>>
>
> I don't think it implies that: It says "data structures" rather than
> "variables", which is what you'd need for `swap'. The distinction is
> important, as shown here:
>
>
I'm not sure if I understand you correctly. Maybe we agree but just
express it in different words. I interpret to two sentences quoted above
as meaning that Schemes passes arguments more like Pascals reference
("VAR") parameters than like Pascals value (non "VAR") parameters. I
strongly believe Scheme is more similar to Pascals value parameters
(even though the value often is a pointer to an object).
For example, consider the following Pascal code:
type
pair = record
car, cdr: integer;
end;
procedure swap1(VAR a, b: ^pair);
var t:^pair;
begin
t:=a; a:=b; b:=t
end;
procedure swap2(a, b: ^pair);
var t:^pair;
begin
t:=a; a:=b; b:=t
end;
"swap1" actually works and swaps its arguments but "swap2" is basically
a no-op. Both could access and modify for example "^a.car". You cannot
implement "swap1" as a procedure in Scheme.
> http://lists.r6rs.org/pipermail/r6rs-discuss/2007-January/001346.html
>
> For now, I'll say "mutable data structures" to make things more
> precise and to make it harder to gloss over the semantic
> distinction. Suggestions for further improvement are welcome.
>
I still think its confusing to talk about Pascals value/reference
parameters since reference in that context means reference to local
variable (which Scheme doesn't support). Scheme values are more similar
to Pascal pointers.
/Mikael
Received on Thu Feb 22 2007 - 14:18:32 UTC