[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Stray Birds
I have not seen anything here of late and my work machine is down, so...
------------------------------------------------------------------------
At some point it would be nice to use multiple value bindings so that local
scopes may export definitions in a more declarative style. I.e. the set!'s
really bother me in:
(define foo 'bogus)
(define bar 'bogus)
(let ()
... ;; local shared bindings
(set! foo internal-foo)
(set! bar (lambda (..) ...)
)
So I would like to propose 2 special forms: LET-VALUES and DEFINE-VALUES.
Let-values is trivial with HL macros, but define-values is not.
;================
; PROPOSED FORMS: let-values and define-values
;================
;; <values-form> must end in a VALUES form which has the same number of
values as
;; there are names in <name>... .
;; Bind names to values in body
;;
;;(let-values ( (<name>...) <values-form> )
;; <body-form>...)
;; Define multiple names to have values
;;
;;(define-values (<name>...)
;; <body-form>...
;; <values-form>)
;======================
; CHEAP IMPLEMENTATION
;======================
(define-syntax LET-VALUES
(syntax-rules ()
((let-values ( (<name> ...) <values-form>) <body> ...)
; =>
(call-with-values
(lambda () <values-form>)
(lambda (<name> ...) <body> ...))
) ) )
;; This next can't be done in HL macros because of the <value>s, but you get
;; the idea.
(define-syntax DEFINE-VALUES
(syntax-rules ()
((define-values (<name> ...) <body> ...)
; =>
(begin
(define <name> #f) ...
(call-with-values
(lambda () <body> ...)
(lambda (<value> ...) (set! <name> <value>) ...)) ;; 8^(
))
) )
;; QUESTIONS:
- Since there HL implementations which don't include low-level facilities,
can we still simply put define-values in the implementors-can-ignore
library?
- Are the names ok? {e.g. values-define, multiple-values-define,
with-values, ...}
- Other suggestions?
How about using WITH or BIND for named let? {Boy, this should start some
mail! 8^}
-Ken kend@newton.apple.com
- Follow-Ups:
- Stray Birds
- From: "Guillermo J. Rozas" <gjr@martigny.ai.mit.edu>
- Stray Birds
- From: "Guillermo J. Rozas" <gjr@martigny.ai.mit.edu>