fib.scm 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. ;;; GNU Mes --- Maxwell Equations of Software
  2. ;;; Copyright (C) 2008 Kragen Javier Sitaker
  3. ;;;
  4. ;;; This file is part of GNU Mes.
  5. ;;;
  6. ;;; GNU Mes is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Mes is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Mes. If not, see <http://www.gnu.org/licenses/>
  18. ;; Setup output file
  19. (set-current-output-port (open-output-file "test/results/test027.answer"))
  20. (define (newline) (display #\newline))
  21. ;;; A dumb fibonacci test --- the first recursive code ever compiled.
  22. ;; At least, by the Ur-Scheme compiler.
  23. ;; This used to display "+" and "*" depending on which case you fell
  24. ;; into, which produced an interesting pattern of
  25. ;; "+*+*++*+*++*++*+*++*+", which I think can be produced by a simple
  26. ;; L-system. However, the exact pattern depends on the order of
  27. ;; argument evaluation, which differs between this compiler and (at
  28. ;; least) MzScheme.
  29. (define fibonacci
  30. (lambda (x) (if (= x 0) (begin (display "+") 1 )
  31. (if (= x 1) (begin (display "+") 1)
  32. (+ (fibonacci (- x 1))
  33. (fibonacci (- x 2)))))))
  34. (fibonacci 7)
  35. (newline)
  36. (exit 0)