let.test 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #! /bin/sh
  2. # -*-scheme-*-
  3. exec ${MES-src/mes} --no-auto-compile -L ${0%/*} -L module -C module -e '(tests let)' -s "$0" "$@"
  4. !#
  5. ;;; -*-scheme-*-
  6. ;;; GNU Mes --- Maxwell Equations of Software
  7. ;;; Copyright © 2016,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  8. ;;;
  9. ;;; This file is part of GNU Mes.
  10. ;;;
  11. ;;; GNU Mes is free software; you can redistribute it and/or modify it
  12. ;;; under the terms of the GNU General Public License as published by
  13. ;;; the Free Software Foundation; either version 3 of the License, or (at
  14. ;;; your option) any later version.
  15. ;;;
  16. ;;; GNU Mes is distributed in the hope that it will be useful, but
  17. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. ;;; GNU General Public License for more details.
  20. ;;;
  21. ;;; You should have received a copy of the GNU General Public License
  22. ;;; along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  23. (define-module (tests let)
  24. #:use-module (mes mes-0)
  25. #:use-module (mes test))
  26. (mes-use-module (mes let))
  27. (mes-use-module (mes test))
  28. (pass-if "first dummy" #t)
  29. (pass-if-not "second dummy" #f)
  30. (pass-if-equal "let " 1
  31. (let ((x 1)) 1))
  32. (let () (define *let-define* '*let-define*) #f)
  33. (pass-if-equal "let define "
  34. #f
  35. (and (defined? '*let-define*) *let-define*))
  36. (begin (define *begin-define* '*begin-define*) #f)
  37. (pass-if-equal "begin define" '*begin-define*
  38. (and (defined? '*begin-define*) *begin-define*))
  39. (pass-if-equal "let loop" '(3 2 1)
  40. (let loop ((lst '(3 2 1)))
  41. (cond ((null? lst) '())
  42. (#t (cons (car lst) (loop (cdr lst)))))))
  43. (pass-if-equal "let* comments" 5
  44. (let* ((aa 2)
  45. (bb (+ aa 3))
  46. #! boo !#
  47. ;;(bb 4)
  48. )
  49. bb))
  50. (pass-if-equal "letrec" 24
  51. (letrec ((factorial (lambda (n)
  52. (cond ((= n 1) 1)
  53. (#t (* n (factorial (- n 1))))))))
  54. (factorial 4)))
  55. (result 'report)