Purpose
This is the Lisp version of our combination
application. It's one of the Palm
Samples.
Requirements
You need LispMe (see tools section).
Source
code
Below is the .lisp
file.
; Combination.lisp
; Palm
; LispMe
(define (factorial n)
(if (<= n 1) 1 (* n (factorial (- n 1)))))
(define (combination n p)
(/ (factorial n) (* (factorial (- n p)) (factorial p))))
(define (go)
(let ((sock 4))
(display "Combination > Palm > LispMe")
(display "#0a")
(display "#0a")
(display "factorial(7) = ")
(display (factorial 7))
(display "#0a")
(display "factorial(4) = ")
(display (factorial 4))
(display "#0a")
(display "factorial(3) = ")
(display (factorial 3))
(display "#0a")
(display "combination(7, 4) = ")
(display (combination 7 4))
(display "#0a")
#n))
Comments
LispMe is a mobile tool. If you love both Lisp and
Palm devices, then that's the way to go! It runs directly on your
mobile device.
Create a memo category named "LispMe" with
Palm Desktop. This is where LispMe will look when you open a file.
Copy and Paste the source code above into a new memo
in this LispMe category. Run HotSync. The source code will be stored
in a ;Combination.lisp
memo. Run LispMe and tap Ld
to load the memo. To run the app, just enter (go)
and tap Eval.
The core functions are : factorial,
combination and go.
Note how functional programming can look weird if
you're not used to it: + 7 4 (pre-fixed
notation) means 7 + 4 (unfixed notation).
Next sample
|