Page 1 of 1

Xlisp 3 via Lispcube on iOS

Posted: Sat Jul 11, 2015 2:41 am
by sennekuyl
Hi.

I'm a novice at programming, and have been practicing on the go with Lispcube. Anyone else use this tool?

I've written my first (successful) program in any language with Lispcube, that is without sequential directions. Just the reference manual. It is a dice roll function. It's simple & rough, but I feel like an old school programmer. (Dunning-Kruger here we come?)

Code: Select all

;; File dice-roll.lsp

(define one 1) ;; magic number - to make the roll between 1 & n
(define four 4) ;; magic number
(define iterate 0)
(define rolled nil)

(define (roll &optional (dice-size four) (number-of-dice one))
	(while (< iterate number-of-dice)
		(display "ROLL ")
		(set! rolled (list (write (dice dice-size))))
		(newline)
		(set! iterate (+ iterate one))))

(define (dice dice-size)
	(+ one (random dice-size)))

(newline)
(newline)
(display "To roll a die, type (roll n n)")
(newline)
(display "where n are positive integers.")
(newline)
(newline)
(display "How many sides does your dice have?")
(define die (read))
(display "How many rolls?")
(define rolls (read))
(roll die rolls)
(newline)