[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
Hello,
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!)
(begin
(define x 0)
(define (get-x) x)
(define (set-x! z) (set! x z))))
> (import (foo bar))
> x
ERROR: undefined variable: x
> (get-x)
0
> (set-x! 10)
> (get-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!)
Thanks,
J.
_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports