(linenum→info "unix/slp.c:2238")

gauche/0.8.12/lib/srfi-11.scm

    1: ;;
    2: ;; SRFI-11: Syntax for receiving multiple values
    3: ;;
    4: ;;  This implementation is based on the reference implemenetation shown
    5: ;;  in srfi-11 document <http://srfi.schemers.org/srfi-11/srfi-11.html>
    6: ;;  by Lars T Hansen.
    7: ;;
    8: ;;  Copyright (C) Lars T Hansen (1999). All Rights Reserved. 
    9: ;;
   10: ;;  This document and translations of it may be copied and furnished to
   11: ;;  others, and derivative works that comment on or otherwise explain it
   12: ;;  or assist in its implementation may be prepared, copied, published and
   13: ;;  distributed, in whole or in part, without restriction of any kind,
   14: ;;  provided that the above copyright notice and this paragraph are
   15: ;;  included on all such copies and derivative works. However, this
   16: ;;  document itself may not be modified in any way, such as by removing
   17: ;;  the copyright notice or references to the Scheme Request For
   18: ;;  Implementation process or editors, except as needed for the purpose of
   19: ;;  developing SRFIs in which case the procedures for copyrights defined
   20: ;;  in the SRFI process must be followed, or as required to translate it
   21: ;;  into languages other than English.
   22: ;;
   23: ;;  The limited permissions granted above are perpetual and will not be
   24: ;;  revoked by the authors or their successors or assigns.
   25: ;;
   26: ;;  This document and the information contained herein is provided on an
   27: ;;  "AS IS" basis and THE AUTHOR AND THE SRFI EDITORS DISCLAIM ALL
   28: ;;  WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY
   29: ;;  WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY
   30: ;;  RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
   31: ;;  PARTICULAR PURPOSE.
   32: ;;
   33: 
   34: ;; Adapted to Gauche by Shiro Kawai (shiro@acm.org)
   35: ;;  - Gauche prefers receive to call-with-values
   36: ;;  - Added a call to provide, so that this file can be "require"d.
   37: ;;  - Added module stuff.
   38: 
   39: (define-module srfi-11)
   40: (select-module srfi-11)
   41: (export let-values let*-values)
   42: 
   43: (define-syntax let-values
   44:   (syntax-rules ()
   45:     ((let-values (?binding ...) ?body0 ?body1 ...)
   46:      (let-values "bind" (?binding ...) () (begin ?body0 ?body1 ...)))
   47:     
   48:     ((let-values "bind" () ?tmps ?body)
   49:      (let ?tmps ?body))
   50:     
   51:     ((let-values "bind" ((?b0 ?e0) ?binding ...) ?tmps ?body)
   52:      (let-values "mktmp" ?b0 ?e0 () (?binding ...) ?tmps ?body))
   53:     
   54:     ((let-values "mktmp" () ?e0 ?args ?bindings ?tmps ?body)
   55:      (receive ?args ?e0
   56:         (let-values "bind" ?bindings ?tmps ?body)))
   57:     
   58:     ((let-values "mktmp" (?a . ?b) ?e0 (?arg ...) ?bindings (?tmp ...) ?body)
   59:      (let-values "mktmp" ?b ?e0 (?arg ... x) ?bindings (?tmp ... (?a x)) ?body))
   60: 
   61:     ;; NB: this clause shouldn't be necessary, but Gauche's macro expander
   62:     ;; as of 0.4.10 doesn't handle the case well.
   63:     ((let-values "mktmp" ?a ?e0 () ?bindings (?tmp ...) ?body)
   64:      (receive x ?e0
   65:        (let-values "bind" ?bindings (?tmp ... (?a x)) ?body)))
   66: 
   67:     ((let-values "mktmp" ?a ?e0 (?arg ...) ?bindings (?tmp ...) ?body)
   68:      (receive (?arg ... . x) ?e0
   69:        (let-values "bind" ?bindings (?tmp ... (?a x)) ?body)))
   70:     ))
   71: 
   72: (define-syntax let*-values
   73:   (syntax-rules ()
   74:     ((let*-values () ?body0 ?body1 ...)
   75:      (begin ?body0 ?body1 ...))
   76: 
   77:     ((let*-values (?binding0 ?binding1 ...) ?body0 ?body1 ...)
   78:      (let-values (?binding0)
   79:        (let*-values (?binding1 ...) ?body0 ?body1 ...)))))
   80: 
   81: (provide "srfi-11")
Syntax (Markdown)