[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: var parameters in T?
From: Mike Caplinger <mike@rice>
Date: Thu, 19 Jul 84 18:35:27 CDT
Is there any way to cleanly do VAR parameters in T? For example, I
might expect the function
(define foo (lambda (a) (set a 1)))
when invoked with
(lset c 0)
(foo (locative c))
to leave c with the value 1, but it doesn't. Obviously I don't
understand what locatives are doing for me...
T and Scheme and most Lisps are call-by-value where values are usually
references. A locative is a value which is a reference to a reference.
To dereference a locative you need to use CONTENTS. So maybe you want
to say
(define (foo loc) (set (contents loc) 1))
(block (foo (locative a)) a) => 1
This is exactly analogous to the situation in C (also call-by-value)
where if you say &, you need to say * on the other end:
foo(loc) int *loc; { *loc = 1; }
(foo(&a), a) => 1
Alternatively, you could use closures, which are a little lower-tech
than locatives:
(define (foo proc) (proc 1))
(block (foo (lambda (x) (set a x))) a) => 1
After all, (locative x) is just a shorthand for
(object nil
((contents self) x)
(((setter contents) self) (lambda (val) (set x val))))
so why provide both assign and update functionality if you're only
going to use one or the other.