real language

Bookmarking Digg Diigo DZone Earthlink Google
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language ArrowLISP

(Using symbols exclusively)

Author:Nils M Holm
Score: (3.02 in 119 votes)
; Bottles Song in Pure LISP
; Copyright (C) 2003,2006 Nils M Holm. All rights reserved.
; This is purely symbolic lisp.
; There are no pre-defined numbers, not even digits.
; There are no strings.
; There is no input/output.
; There are no side effects.
; Numbers are represented by lists of digits.
; Lyrics are generated in this format:
; (((9 9) bottles of beer on the wall)
;  ((9 9) bottles of beer)
;  (take one down and pass it around)
;  ((9 8) bottles of beer on the wall))
(define (bottles)
  ; Define some sentences
    (quote (bottles of beer on the wall)))

    (quote (bottles of beer))) 

    (quote (take one down and pass it around)))

  ; Append two lists
  (append (lambda (a b)
    (cond ((null a) b)
      (t (cons (car a) (append (cdr a) b))))))
  ; Append four lists
  (append4 (lambda (a b c d)
    (append a (append b (append c d)))))

  ; Find predecessor of digit
  (pred (lambda (n)
      ((eq n (quote 1)) (quote 0))
      ((eq n (quote 2)) (quote 1))
      ((eq n (quote 3)) (quote 2))
      ((eq n (quote 4)) (quote 3))
      ((eq n (quote 5)) (quote 4))
      ((eq n (quote 6)) (quote 5))
      ((eq n (quote 7)) (quote 6)) 
      ((eq n (quote 8)) (quote 7))
      ((eq n (quote 9)) (quote 8))
      (t ()))))

  (cadr (lambda (x) (car (cdr x))))
  (list (lambda (x) (cons x ())))
  (decrement (lambda (n)
    (cond ((null (pred (cadr n)))
        (cons (pred (car n)) (list (quote 9))))
      (t (cons (car n) (list (pred (cadr n))))))))

  (zerop (lambda (n)
    (cond ((eq (car n) (quote 0))
        (cond ((eq (cadr n) (quote 0)) t)
            (t ())))
      (t ()))))
  (verse (lambda (n)
      (list (append (list n) beer-on-wall))
      (list (append (list n) beer)) 
      (list take-down)
      (list (append (list (decrement n)) beer-on-wall)))))
  (count-bottles (lambda (n lyrics)
    (cond ((zerop n) lyrics)
      (t (count-bottles (decrement n)
        (append lyrics (list (verse n)))))))))
  (count-bottles (quote (9 9)) ())))

Download Source | Write Comment

Alternative Versions


Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!




Security Code: