A location is a place where a value can be stored.
An lvalue is an expression that refers to a location.
(The name "lvalue" refers to the fact that the left operand
set! is an lvalue.)
The only kind of lvalue in standard Scheme is a variable.
Kawa also allows computed lvalues. These are procedure
calls used in "lvalue context", such as the left operand of
You can only use procedures that have an associated setter.
In that case,
(set! (f arg ...) value)
is equivalent to
((setter f) arg ... value)
Currently, only a few procedures have associated
and only builtin procedures written in Java can have
(set! (car x) 10)
is equivalent to:
((setter car) x 10)
which is equivalent to:
(set-car! x 10)
Gets the "setter procedure" associated with a "getter procedure". Equivalent to
(procedure-property. By convention, a setter procedure takes the same parameters as the "getter" procedure, plus an extra parameter that is the new value to be stored in the location specified by the parameters. The expectation is that following
((setterthen the value of
settercan be used to set the
setterproperty. For example the Scheme prologue effectively does the following:(set! (setter vector-set) vector-set!)
Kawa also gives you access to locations as first-class values:
Returns a location object for the given
lvalue. You can get its value (by applying it, as if it were a procedure), and you can set its value (by using
set!on the application). The
lvaluecan be a local or global variable, or a procedure call using a procedure that has a
setter.(define x 100) (define lx (location x)) (set! (lx) (cons 1 2)) ;; set x to (1 . 2) (lx) ;; returns (1 . 2) (define lc (location (car x))) (set! (lc) (+ 10 (lc))) ;; x is now (11 . 2)
variableas an alias for
lvalue. In other words, makes it so that
(locationis equivalent to
(location. This works both top-level and inside a function.
Some people might find it helpful to think of a location
as a settable thunk. Others may find it useful to
think of the
location syntax as similar to the C ‘
for the ‘
*’ indirection operator, Kawa uses procedure application.
You can use
define-alias to define a shorter type synonym,
similar to Java’s
import TypeName (single-type-import) declaration:
(define-alias StrBuf java.lang.StringBuffer)