Skip to content

Instantly share code, notes, and snippets.

@justinmeiners
Created July 15, 2018 01:41
Show Gist options
  • Save justinmeiners/e9cf227fc5b3177a3b75b757118898d1 to your computer and use it in GitHub Desktop.
Save justinmeiners/e9cf227fc5b3177a3b75b757118898d1 to your computer and use it in GitHub Desktop.
Playing around with ParenScript.
; ParenScript experiment
; https://common-lisp.net/project/parenscript/reference.html
; https://gitlab.common-lisp.net/parenscript/parenscript
; typical functions
(defun fib (n)
(cond ((= n 0) 0)
((= n 1) 1)
(t (+ (fib (- n 1)) (fib (- n 2))))))
; arrays
(defvar numbers '(1 2 3 4 5))
; JSON objects
(defvar props (create :name "Justin Meiners"
:age 23
:state "Utah"))
; generate some HTML,
(defvar template (ps-html ((:button :id "test-button") "try-me")))
; Using CL as a macro system
(defvar x (lisp (car (mapcar (lambda (x) (+ x 1)) '(1 2 3)))))
(defun main ()
; replace the innerHTML with the template
(setf (@ document body inner-h-t-m-l) template)
(let ((main-button ((@ document get-element-by-id) "test-button")))
; add an onclick event to a button
(setf (@ main-button onclick)
(lambda (event)
(alert ((@ numbers map) fib))
(alert "Hello!")))))
(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment