Skip to content

Instantly share code, notes, and snippets.

@gcentauri
Last active July 15, 2019 04:52
Show Gist options
  • Save gcentauri/db32f152070ab394d0b6f8bccb8c555e to your computer and use it in GitHub Desktop.
Save gcentauri/db32f152070ab394d0b6f8bccb8c555e to your computer and use it in GitHub Desktop.
picolisp number guesser
# 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