[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Scheme-reports] Can a library keep state?
- To: scheme-reports <scheme-reports@x>
- Subject: [Scheme-reports] Can a library keep state?
- From: Jeronimo Pellegrini <j_p@x>
- Date: Mon, 2 Jan 2012 09:29:27 -0200
The report mentions that
"In a library declaration, it is an error to import
the same identifier more than once with different bindings,
or to redefine or mutate an imported binding with define,
define-syntax or set!."
So a library cannot, for example, export a variable that
is supposed to be mutated by the user. But can it export
a getter and a setter?
(define-library (foo bar)
(import (scheme base))
(export get-x set-x!)
(define x 0)
(define (get-x) x)
(define (set-x! z) (set! x z))))
> (import (foo bar))
ERROR: undefined variable: x
> (set-x! 10)
This works in Chibi (and I'd use this a lot!) -- but it's
not explicitly allowed by the standard, so I'm checking.
Is this the intended semantics? (If it is, I'm happy!)
Scheme-reports mailing list