Email list hosting service & mailing list manager


multiple-value set! Neil W. Van Dyke 20 May 2005 18:10 UTC

Since the SRFI draft not only extends the "let" family to support
multiple-values, but also defines useful procedures for dealing with
multiple-values, would the extension of "set!" to multiple-values also
be within the scope of the SRFI?

If the SRFI-71 "let" forms support a binding expression pattern
language, "set!" should support the same pattern language.

The following simple R5RS implementation intentionally does not support
the "(rest VAR)" syntax that I suggested earlier for "let".  I like that
syntax less in "set!", since I'd like to reserve list syntax in a "set!"
VAR position to be for the generalized-"set!" found in some Lisps.  In
generalized-"set!", "rest" would be a keyword stomping on identifier
space (for which there is precedent in R5RS, but that leads to hygiene
pitfalls).

(define-syntax %srfi71:r5rs-set! (syntax-rules () ((_ X ...) (set! X ...))))

(define-syntax srfi-set!
  (syntax-rules ()

    ((_ VAR EXPR)     (%srfi71:r5rs-set! VAR EXPR))

    ((_ S0 S1 S2 ...) (%srfi71:set!:mult (S0 S1 S2 ...) () ()))))

(define-syntax %srfi71:set!:mult
  (syntax-rules (rest)

    ((_ (EXPR) TVS (SET0 ...))
     (call-with-values (lambda () EXPR) (lambda TVS SET0 ...)))

    ((_
      (S0 S1 ...) (TV0 ...     ) (SET0 ...                              ))
     (%srfi71:set!:mult
      (   S1 ...) (TV0 ... temp) (SET0 ... (%srfi71:r5rs-set! S0 temp))))))

--
                                             http://www.neilvandyke.org/