Created
November 16, 2020 09:25
-
-
Save osfameron/203318c643e9d1dc380767edb402fdd8 to your computer and use it in GitHub Desktop.
testing Carp
This file contains hidden or 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
https://blog.veitheller.de/Carp.html | |
(def x 1) | |
(+ x 1) ;; ??? | |
x | |
(IO.println &(Int.str (+ x 10))) | |
(defn id [a] a) | |
(id x) | |
(deftype Point [x Int, y Int]) | |
Point | |
(Point.init 1 2) | |
(Point 1 2) ;; ??? | |
(def p (Point.init 1 2)) | |
p | |
(id p) ;; ??? | |
(id @p) ;; ??? | |
(id &p) | |
&p | |
(Point.x &p) | |
(Point.set-x p 3) | |
(Point.set-x @p 3) | |
(Point.set-x &p 3) | |
(Point.set-x &@p 3) | |
(Point.set-x @&p 3) ;; !!!! | |
&p | |
(Point.update-x @&p &dec) | |
(=> p | |
(Point.update-x &dec)) ;; huh. macro expansion | |
(Point.update-x p (ref dec)) ;; nope | |
(=> p (ref) (copy) (Point.update-x &dec)) | |
(Point.update-x (copy (ref p)) (ref dec)) | |
(id (=> p (ref) (copy) (Point.update-x &dec))) | |
(id (=> p) | |
(ref) (copy) | |
(Point.update-x &dec) | |
(ref) (copy) | |
(Point.update-y &dec)) | |
;; presumably could write a macro that automatically does this... | |
(Point.prn &(=> p | |
(ref) (copy) | |
(Point.update-x &dec) | |
(ref) (copy) | |
(Point.update-y &dec))) | |
(Point.set-x! &p 3) | |
&p ;; !!!! | |
(do (Point.set-x! &p 3) &p) | |
&p | |
;;;; special forms | |
(let [x 1] | |
(+ x 1)) | |
(if (= 1 2) | |
(IO.println "Maths is broken") | |
(IO.println "Maths is fine")) | |
(foreach [x &[1 2 3]] | |
(println* "x: " x)) | |
(let [i 0] (while (< i 10) (do (IO.println "print me tenfold!") (set! i (+ i 1))))) | |
;; macros | |
(defmacro foo [a] (list '+ 1 a)) | |
(foo 1) | |
(id (foo 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment