/usr/lib/and-letstar.scm is in scheme9 2013.11.26-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | ; Scheme 9 from Empty Space, Function Library
; By Nils M Holm, 2010,2012
; Placed in the Public Domain
;
; (and-let* <binding> ... <body>) ==> object
;
; (load-from-library "and-letstar.scm")
;
; Each <binding> has the form (<variable> <expression>) and binds
; the given <variable> to the normal form of <expression>.
;
; Like LET*, AND-LET* evaluates its <binding>s in sequence, so each
; <expression> is evaluated in an environment that includes all previous
; <binding>s of the same AND-LET*. Unlike LET*, though, AND-LET* returns
; #F immediately as soon as one of its <expression>s evaluates to #F.
; Only when all <expression>s evaluate to non-#F values, it evaluates
; <body> and returns its value. AND-LET* expands as follows:
;
; (and-let* ((<var1> <expr1>) ---> (let ((<var1> <expr1>))
; ... (and <var1>
; (<varN> <exprN>)) ...
; <body>) (let ((<varN> <exprN>))
; (and <varN>
; <body>))))
;
; This is only a subset of SRFI-2 AND-LET*.
;
; Example: (and-let* ((a '((x . 1)))
; (a (assq 'x a)))
; (cdr a)) ==> 1
;
; (and-let* ((a '((x . 1)))
; (a (assq 'z a)))
; (cdr a)) ==> #f
(define-syntax (and-let* clauses expr . exprs)
(letrec
((nest-let
(lambda (c)
(cond ((null? c)
(cons expr exprs))
((null? (cdr c))
`(let ((,(caar c) ,(cadar c)))
(and ,(caar c)
,@(cons expr exprs))))
(else
`(let ((,(caar c) ,(cadar c)))
(and ,(caar c)
,(nest-let (cdr c)))))))))
(let loop ((c clauses))
(cond ((null? c))
((or (not (pair? (car c)))
(null? (cdar c))
(not (null? (cddar c)))
(not (symbol? (caar c))))
(error "and-let*: syntax error" c))
(else
(loop (cdr c)))))
(if (null? clauses)
`(let () ,expr ,@exprs)
(nest-let clauses))))
|