Created
July 15, 2018 01:41
-
-
Save justinmeiners/e9cf227fc5b3177a3b75b757118898d1 to your computer and use it in GitHub Desktop.
Playing around with ParenScript.
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
; 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