1 2-- demo 3 4define a (read cd) $ if (> a cd) 5 print demo 6 print "not demo" 7 8say $ print a $ save $ b $ x $ c 8 9 10print fun 11 12-- test on folding 13 14a $ 15 16b $ c 17 18d $ e $ f 19 20g $ h $ i j $ k $ 21 22-- test on comma 23 24print (, a) 25 a 26 , b 27 , c (, d) 28 29-- test on HTML 30 31doctype 32 33html 34 head 35 title $ = Cirru 36 script (:defer) $ :src build/build.js 37 link (:rel stylesheet) $ :href css/page.css 38 link (:rel icon) 39 :href http://logo.cirru.org/cirru-32x32.png?v=3 40 body 41 textarea.demo.source $ :placeholder "Source Code" 42 textarea.demo.target $ :placeholder "Compiled Data" 43 @insert ../html/ga.html 44 45-- test on indentation 46 47a $ b $ c 48 49e f 50 (g) 51 h 52 53-- test on parentheses 54 553 4 (1) 4 56 57((((1)))) 58 59x 60 61-- test on quotes 62 63a b c d 64 65"a b c d" 66 67"a b \" c d" 68 69"a b" "c d" 70 71-- test on unfolding 72 73set 74 add 1 $ 75 , x y 76 add 5 $ 77 add 2 78 79-- test on HTML attributes 80 81div 82 div 83 :class a 84 div 85 :class a b c d 86 87 div 88 :class a (@ b) (@ c) d 89 90 div 91 :class a 92 @if (@ b) 93 div b 94 div c 95 div 96 :class a 97 @if (@ b) b c 98 99-- test on helpers 100 101@if (@call a b) (div) (span) 102 103@each members 104 div (@ name) 105 106@each a 107 div (@ b) 108 @each c 109 div (@ d) 110 111-- test on HTML structure 112 113@rich more 114 #demo-more-box 115 #demo-more 116 :data-lang-text demo-more 117 #demo-more-list 118 @each room 119 .demo-more-room 120 span.demo-name 121 @ topic 122 span.demo-join 123 :data-lang-text demo-join 124 :data-id (@ id) 125 126-- text on bool 127 128print #true 129print #false 130print #yes 131print #no 132print #t 133print #f 134 135-- test on Cirru js 136 137set a 1 138set a (= "This is a string") 139set b #t 140 141-- this is comment 142 143number 1.4 144string x 145regex ^\s$ 146regex "^\\s-\"$" 147sentence this is a string 148 149array 1 2 3 (= nothing) #t (= #t) 150 151set c (array 1 (= nothing)) 152 153set d $ object (a (= google)) 154 b (= reader) 155 c 1 156 d $ array 1 2 (= string) 157 1581 c 159-1 c 160 161:b d 162.log console a 2 163.log console 164 165set demo $ object 166 call $ \ x (.log console x) (. this call) 167. demo (.call 1) (.call 4) 168 169=.x d 3 170 171set d null 172 173new Array 1 2 3 174 175set x (:length c) 176set str (= str) 177set c (.toUpperCase str) 178 179\ x (+ x 1) 180\ (x y) (+ x y) 181\ x (set aa 1) (+ aa x) 182 183set f (\ x (+ x 1)) 184 185+ a 1 2 186+= a 1 187 188> 1 2 3 189 190if (> 2 1) (+ a 1) 191else 2 192 193if (> a 2) 194 .log console (= "large") 195elseif (> a 1) 196 .log console (= "still good") 197else 198 .log console (= "so so") 199 200set a $ if (> 2 1) #t #f 201 202switch a 203 1 (.log console 1) 204 2 (.log console 2) 205 else (.log console (= "something else")) 206 207set a $ array 2 +3 -4 208for (a x i) (.log console x i) 209 210set a 0 211while (< a 10) (+= a 1) (.log console a) 212 213-- WebAssembly variable names 214 215-- ":(c) 2015 Andreas Rossberg" 216 217module 218 export :even $even 219 export "odd" $odd 220 221 func $even (param $n i32) (result i32) 222 if (i32.eq (get_local $n) (i32.const 0)) 223 i32.const 1 224 call $odd (i32.sub (get_local $n) (i32.const 1)) 225 226 func $odd (param $n i32) (result i32) 227 store_global $scratch (get_local $n) 228 if (i32.eq (get_local $n) (i32.const 0) 229 i32.const 0 230 call $even (i32.sub (get_local $n) (i32.const 1)) 231 232 global $scratch i32 233 234assert_eq (invoke :even (i32.const 13)) (i32.const 0) 235assert_eq (invoke :even (i32.const 20)) (i32.const 1) 236assert_eq (invoke :odd (i32.const 13)) (i32.const 1) 237assert_eq (invoke :odd (i32.const 20)) (i32.const 0) 238