Last active
July 15, 2019 04:52
-
-
Save gcentauri/db32f152070ab394d0b6f8bccb8c555e to your computer and use it in GitHub Desktop.
picolisp number guesser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# default only sets the var if it is NIL, this is here because | |
# the whole file gets evaluated on page load the way i have it rn | |
(default *Bounds '(1 . 100)) | |
(de small () | |
(car *Bounds) ) | |
(de big () | |
(cdr *Bounds) ) | |
(de guess-my-number () | |
(if (> (small) (big)) | |
(msg "cheat") | |
(>> 1 (+ (small) (big))) ) ) | |
(de smaller () | |
(set '*Bounds (cons (small) (dec (guess-my-number)))) | |
(guess-my-number) ) | |
(de bigger () | |
(set '*Bounds (cons (inc (guess-my-number)) (big))) | |
(guess-my-number) ) | |
(app) # starts a session | |
(default *Guess (guess-my-number)) # just here because its gui related | |
(action | |
(html 0 "Guess My Number" "@lib.css" NIL | |
(form NIL | |
(gui '(+Var +NumField) '*Guess 5) # coupd probably do this with a component value instead of +Var | |
(gui '(+JS +Button) "Smaller" '(setq *Guess (smaller))) | |
(gui '(+JS +Button) "Bigger" '(setq *Guess (bigger))) ) ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment