#!/usr/bin/guile \ -e main -s !# ;;; Copyright 2005 Daniel Cer (daniel.cer@cs.colorado.edu) ;;; ;;; This work is licensed under the Creative Commons Attribution-NonCommercial- ;;; ShareAlike License. To view a copy of this license, visit ;;; http://creativecommons.org/licenses/by-nc-sa/2.5/ or send a letter to ;;; Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, ;;; 94105, USA. (define (fibonacci n) (if (<= n 0) -1 (do ((fib 1 (+ fib prev_fib)) (prev_fib 1 fib) (i 2 (+ i 1)) ) ((>= i n) fib) '()) )) (define (main args) (if (not (equal? (length args) 2)) (display (string-append "Usage:\n\t" (car args) " (n-th fibonacci # to calculate)\n")) (let ((n (car (cdr args)))) (display (string-append "fibonacci(" n "): " (number->string (fibonacci (string->number n))) )))) )