[gambit-list] srfi-13 define-macro replacements

ben at crickhollow.fuhok.net ben at crickhollow.fuhok.net
Sat Mar 26 14:18:53 EST 2005


Here are define-macro versions of `let-string-start+end' and
`let-string-start+end2' needed by the reference implementation of
srfi-13.  I'm still reading over everyone else's work, so I don't know
if these will be useful or not.

-------------------------------------------------------------------------------
(define-macro (let-string-start+end start+end proc s-exp args-exp . body)
  (or (list? start+end)
      (error "let-string-start+end: start+end must be list"))
  (case (length start+end)
    ((2)
     `(receive ,start+end (string-parse-final-start+end ,proc ,s-exp ,args-exp)
        , at body))
    ((3)
     `(receive ,start+end (string-parse-start+end ,proc ,s-exp ,args-exp)
        , at body))
    (else
     (error "let-string-start+end: wrong length start+end"))))

(define-macro (let-string-start+end2 start+end-pair proc str1 str2 args . body)
  (or (list? start+end-pair)
      (error "let-string-start+end: start+end-pair must be list"))
  (let ((rest (gensym))
        (procv (gensym)))
    (receive (start1 end1 start2 end2) (apply values start+end-pair)
      `(let ((,procv ,proc)) ; Make sure PROC is only evaluated once.
         (let-string-start+end
          (,rest ,start1 ,end1) ,procv ,str1 ,args
          (let-string-start+end
           (,start2 ,end2) ,procv ,str2 ,rest
           , at body))))))
-------------------------------------------------------------------------------

Regards,

Ben





More information about the Gambit-list mailing list