This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Xlisp 3 via Lispcube on iOS

1 post · 4815 views

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?)
;; 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)