core: Add garbage collector/jam collector experiment.
[mes.git] / tests / let.test
1 #! /bin/sh
2 # -*-scheme-*-
3 echo ' ()' | cat $($(dirname $0)/../scripts/include.mes $0) $0 /dev/stdin | $(dirname $0)/../scripts/mes "$@"
4 #paredit:||
5 exit $?
6 !#
7
8 ;;; -*-scheme-*-
9
10 ;;; Mes --- Maxwell Equations of Software
11 ;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
12 ;;;
13 ;;; let.test: This file is part of Mes.
14 ;;;
15 ;;; Mes is free software; you can redistribute it and/or modify it
16 ;;; under the terms of the GNU General Public License as published by
17 ;;; the Free Software Foundation; either version 3 of the License, or (at
18 ;;; your option) any later version.
19 ;;;
20 ;;; Mes is distributed in the hope that it will be useful, but
21 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 ;;; GNU General Public License for more details.
24 ;;;
25 ;;; You should have received a copy of the GNU General Public License
26 ;;; along with Mes.  If not, see <http://www.gnu.org/licenses/>.
27
28 (mes-use-module (mes base-0))
29 (mes-use-module (mes base))
30 (mes-use-module (mes quasiquote))
31 (mes-use-module (mes let))
32 (mes-use-module (mes test))
33
34 (pass-if "first dummy" #t)
35 (pass-if-not "second dummy" #f)
36
37 (let () (define *top-let-a* '*top-let-a*) #f)
38 (pass-if "top let " (seq? (and (defined? '*top-let-a*) *top-let-a*) #f))
39
40 (pass-if "let loop"
41   (sequal?
42    (let loop ((lst '(3 2 1)))
43      (cond ((null? lst) '())
44            (#t (cons (car lst) (loop (cdr lst))))))
45    '(3 2 1)))
46
47 (pass-if "let* comments"
48   (seq? (let* ((aa 2)
49                (bb (+ aa 3))
50                #! boo !#
51                ;;(bb 4)
52                )
53           bb)
54         5))
55
56 (pass-if "letrec"
57   (seq?
58    (letrec ((factorial (lambda (n)
59                          (cond ((= n 1) 1)
60                                (#t (* n (factorial (- n 1))))))))
61      (factorial 4))
62    24))
63
64 (result 'report)
65