Debian Codegraph @

scheme/ikarus.apply.ss

raw
1 ;;; Ikarus Scheme -- A compiler for R6RS Scheme.
2 ;;; Copyright (C) 2006,2007,2008 Abdulaziz Ghuloum
3 ;;;
4 ;;; This program is free software: you can redistribute it and/or modify
5 ;;; it under the terms of the GNU General Public License version 3 as
6 ;;; published by the Free Software Foundation.
7 ;;;
8 ;;; This program is distributed in the hope that it will be useful, but
9 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
10 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 ;;; General Public License for more details.
12 ;;;
13 ;;; You should have received a copy of the GNU General Public License
14 ;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16
17 (library (ikarus apply)
18 (export apply)
19 (import
20 (except (ikarus) apply)
21 (ikarus system $pairs)
22 (ikarus system $stack))
23
24 (define apply
25 (let ()
26 (define (err f ls)
27 (if (procedure? f)
28 (die 'apply "not a list" ls)
29 (die 'apply "not a procedure" f)))
30 (define (fixandgo f a0 a1 ls p d)
31 (cond
32 [(null? ($cdr d))
33 (let ([last ($car d)])
34 ($set-cdr! p last)
35 (if (and (procedure? f) (list? last))
36 ($$apply f a0 a1 ls)
37 (err f last)))]
38 [else (fixandgo f a0 a1 ls d ($cdr d))]))
39 (define apply
40 (case-lambda
41 [(f ls)
42 (if (and (procedure? f) (list? ls))
43 ($$apply f ls)
44 (err f ls))]
45 [(f a0 ls)
46 (if (and (procedure? f) (list? ls))
47 ($$apply f a0 ls)
48 (err f ls))]
49 [(f a0 a1 ls)
50 (if (and (procedure? f) (list? ls))
51 ($$apply f a0 a1 ls)
52 (err f ls))]
53 [(f a0 a1 . ls)
54 (fixandgo f a0 a1 ls ls ($cdr ls))]))
55 apply)))