@@ -74,175 +74,348 @@ so open the REPL in the repository and input these code to the interpreter:
** Fundamentals
#+BEGIN_SRC lisp
(maca (-> (a)
(if (a b c) ;multi-line then/else
((var d (+ a b c)) ;infix argument and var declaration
(var e (== a b c d))) ; multiple comparison
((var f '(a (b c) (+ 1 2 3))) ; array literal
(var g (:a a :b (b c) :c (+ 1 2 3))))) ; object literal
;; true if it's not undefined
(if? a b c)
(granpa > parent > obj > (child 2) > grandchild 3 4 5)
;; direct access with []
(obj > 2 > "key" > 'key > :key)
;; prototype accessor
(obj >> child > grandchild)
(obj >> (method a))
(obj >>)
;; existantial accessor
(a ? b ? c)
;; function call chaining
(--- cc1 ("one-again") ("two-again") ("three-again"))
;; if-statement with returning a value
;; and alias from "or" to ||, "and" to &&
(or ((if a b c) > '(if d e f)) (and (x a) (x b)))
;; implicit return
a))
(defun fundamentals ()
;; fundamentals
(maca (glue a 2 space "string")
(paren a)
(paren (paren a)) ;reduces redundancy automatically
(paren (paren (paren a))) ;reduces redundancy automatically
(comma (comma a b c) (comma a b c))
(comma a b c)
(stringify a)
(blk ((a b c)))
(blk
((blk
((a b c)))))
(bracket a)
;; constants and basic assignments
undefined
t
"string"
;; comments (if you want to include some comment into js)
(// "haaa~~~~ this is comfortable")
(// a)))
#+END_SRC
#+BEGIN_SRC js
function(a){
var d,e,f,g,tmp203,tmp204;
if(a(b,c)){d = (a + (b + c))e = (a==b)&&(b==c)&&(c==d)
}else{f = [a,b(c),(1 + (2 + 3))]g = {a:a,b:b(c),c:(1 + (2 + 3))
}
};
if(((a!==undefined) && ((typeof a)!=="undefined"))){b
}else{c
};
granpa.parent.obj.child(2).grandchild(3,4,5);
obj[2]["key"][key][key];
obj.prototype.child.grandchild;
obj.prototype.method(a);
obj.prototype;
((((g1625 = a.b)!=undefined))?(((((g1626 = g1625.c)!=undefined))?(g1626):((void 0)))):((void 0)));
cc1("one-again")("two-again")("three-again");
(if(a){tmp203 = b
}else{tmp203 = c
}if(d){tmp204 = e
}else{tmp204 = f
}tmp203[tmp204] || (x(a) && x(b)));
return a;
};
MACA> (fundamentals)
a2 "string";
(a);
((a));
(((a)));
a,b,c,a,b,c;
a,b,c;
'a';
{ /* indentation level: 0 */
a(b,c);
}
;
{ /* indentation level: 0 */
{ /* indentation level: 1 */
a(b,c);
}
;
}
;
[a];
undefined;
true;
"string";
/* haaa~~~~ this is comfortable */;
/* A */;
#+END_SRC
** Assignments
#+BEGIN_SRC lisp
(defun assignments ()
;; assignments
(maca (= number 3)
(blk ((= number 3) (= number 3)))
(with-label (label)
(= number 3)
(= number 3))
(comma (= number 3) (= number 3)))
(maca (var number 3))
(maca (var number))
;;(maca (var (+ 2 1) 3)) ;throws error
)
#+END_SRC
#+BEGIN_SRC js
MACA> (assignments)
number = 3;
{ /* indentation level: 0 */
number = 3;
number = 3;
}
;
label:{ /* indentation level: 0 */
number = 3;
number = 3;
}
;
number = 3,number = 3;
var number;
number = 3;
var number;
#+END_SRC
** Operaters
#+BEGIN_SRC lisp
(defun ops ()
;; infix
(maca (>>> number 3)
(+ a 3)
(+ a 3 4)
(- a 3 4)
(* a 3 4)
(+ a 3 (>>> number 3))
;; assignments
(= a 3)
(= a (a > b > v))
(a > b > v)
;; comparison
(< number 50)
(== 5 3)
(== 5 3 4)
(>= 5 3 4)
;; mono-ops
(new -number)
(typeof 5)
;; in
(in 5 array)))
#+END_SRC
#+BEGIN_SRC js
MACA> (ops)
(number >>> 3);
(a + 3);
(a + (3 + 4));
(a NIL (3 NIL 4));
(a * (3 * 4));
(a + (3 + (number >>> 3)));
a = 3;
a = a.b.v;
a.b.v;
(number<50);
(5==3);
(5==3)&&(3==4);
(5>=3)&&(3>=4);
(new Number);
(typeof 5);
(5 in array);
#+END_SRC
** Procedure/Inline/Inherit-this function
#+BEGIN_SRC lisp
(maca (-/> ()
;; inline function: maca expands it safely
(-/ baz (a b) (+ (some-operation a) (other-operation b)))
(= foo (baz foo bar))
;; procedure function: functions without a implicit return
(-/> (b)
(if (< b 3)
(var a (+ 3 b))
(var a (+ b 3)))
(= @a 2) ; alias for this[a]
;; inherit-this function (=>): saves 'this' of the outer environment
(($ "button") > (click (=> (e) (alert (this > 2))))))))
(defun functions ()
;; global scope(bare)
(maca (a b c)
(= d (- a b c))
(var e 2)
(+ a b c d e))
;; function definition
;; normal function: implicit return on
;; procedure function: returns undefined
(maca (-/> (a)
(alert a)
(-> (b)
(if (< b 3)
((var a (- 3 b))
(= b (expr a 5)))
((var a (- b 3))))
(var c (+ a 3))
(alert a b)
a)))
;; inherit-this function: saves 'this' of the outer environment
(maca (a > (click (=/> (e)
(alert (this > 2))))))
;; inline function: they are directly expanded into the environment
(maca (foo)
(bar foo)
(-/ baz (a b) (+ (some-operation a)
(other-operation b)))
(-/ bud (a b) (+ (sqrt a)
(expr b)))
(= foo (baz foo bar))
(alert (baz 1 (bud foo bar)))))
#+END_SRC
#+BEGIN_SRC js
function(){
var tmp1443,tmp1444,tmp24;
MACA> (functions)
var e;
a(b,c);
d = (a NIL (b NIL c));
e = 2;
(a + (b + (c + (d + e))));
var a,c;
function(a){ /* indentation level: 0 */
var a,c;
alert(a);
function(b){ /* indentation level: 1 */
var a,c;
if((b<3)){ /* indentation level: 2 */
a = (3 NIL b);
b = expr(a,5);
}
else{ /* indentation level: 2 */
a = (b NIL 3);
}
c = (a + 3)alert(a,b);
return a;
}
;
tmp1444 = bar;
tmp1443 = foo;
tmp24 = (someOperation(tmp1443) + otherOperation(tmp1444));foo = tmp24;
function(b){
var a,t1452,f1453;
t1452 = this;
f1453 = function(e){
return alert(t1452[2]);
};
if((b<3)){a = (3 + b)
}else{a = (b + 3)
};
this.a = 2;
$("button").click(f1453);
};
};
}
;
var this3226,inheritedFn3227;
this3226 = this;
inheritedFn3227 = function(e){ /* indentation level: 0 */
alert(this3226[2]);
}
;
a.click(inheritedFn3263);
var inlineTmp3266,inlineTmp3267,setterTemp3265,inlineTmp3283,inlineTmp3284,inlineTmp3286,inlineTmp3287,setterTemp3285,inlineTmp3303,inlineTmp3304,setterTemp3302,argName3282;
foo();
bar(foo);
inlineTmp3352 = bar;
inlineTmp3351 = foo;
setterTemp3350 = (someOperation(inlineTmp3351) + otherOperation(inlineTmp3352));
foo = setterTemp3350;
inlineTmp3438 = bar;
inlineTmp3437 = foo;
setterTemp3436 = (sqrt(inlineTmp3437) + expr(inlineTmp3438));
inlineTmp3418 = setterTemp3436;
inlineTmp3417 = 1;
argName3416 = (someOperation(inlineTmp3417) + otherOperation(inlineTmp3418));
alert(argName3416);
#+END_SRC
** Call/cc
#+BEGIN_SRC lisp
(maca ((alert
(with-cc (cont)
($ > (get "http://google.com"
(-/> (xhr) (cont (xhr > responce-text)))))))))
(maca ((var cc1)
(var cc2)
(var cc3)
(alert (with-cc (cont1)
(= cc1 cont1)
(cont1 (confirm "one")))
(with-cc (cont2)
(= cc2 cont2)
(cont2 (confirm "two")))
5
(with-cc (cont3)
(= cc3 cont3)
(cont3 (confirm "three")))
4)
(console > (log (cc1 > (to-string))))
(--- cc1 ("one-again") ("two-again") ("three-again"))
(// "this will call cont2 and cont3 again")
(console > (log (cc2 > (to-string))))
(--- cc2 ("two-again") ("three-again"))
(// "this will call cont3 again")
(console > (log (cc3 > (to-string))))
(--- cc3 ("three-again"))
(// "this will call alert")))
(defun continuation ()
(maca (alert
(with-cc (cont)
($ > (get "http://google.com"
(-/> (xhr) (cont (xhr > responce-text)))))))
(var cc1)
(var cc2)
(var cc3)
(alert (with-cc (cont1)
(= cc1 cont1)
(cont1 (confirm "one")))
(with-cc (cont2)
(= cc2 cont2)
(cont2 (confirm "two")))
5
(with-cc (cont3)
(= cc3 cont3)
(cont3 (confirm "three")))
4)
(console > (log (cc1 > (to-string))))
(cc1 "one-again")
(// "this will call cont2 and cont3 again")
(console > (log (cc2 > (to-string))))
(cc2 "two-again")
(// "this will call cont3 again")
(console > (log (cc3 > (to-string))))
(cc3 "three-again")
(// "this will call alert")
(funcall (console > log)
(with-cc (cont1)
(= cc1 cont1)
(cont1 (confirm "one")))
(with-cc (cont2)
(= cc2 cont2)
(cont2 (confirm "two"))))))
#+END_SRC
#+BEGIN_SRC js
((function(cont){
return $.get("http://google.com",function(xhr){
cont(xhr.responceText);
});
})(function(valueArg1053){
var tmp121;
return tmp121 = alert(valueArg1053);
}));;
var cc1,cc2,cc3;
((function(cont3){
function(cont){ /* indentation level: 0 */
return $.get("http://google.com",function(xhr){ /* indentation level: 1 */
cont(xhr.responceText);
}
);
}
(function(valueArg3773){ /* indentation level: 0 */
return alert(valueArg3773);
}
);
function(cont3){ /* indentation level: 0 */
cc3 = cont3;
return cont3(confirm("three"));
})(((function(cont2){
}
(function(valueArg3944){ /* indentation level: 0 */
return function(cont2){ /* indentation level: 0 */
cc2 = cont2;
return cont2(confirm("two"));
})(((function(cont1){
}
(function(valueArg3957){ /* indentation level: 1 */
return function(cont1){ /* indentation level: 0 */
cc1 = cont1;
return cont1(confirm("one"));
})(function(valueArg1062){
return function(valueArg1065){
return function(valueArg1068){
var tmp121;
return tmp121 = alert(valueArg1062,valueArg1065,5,valueArg1068,4);
};
};
}))))));
}
(function(valueArg3970){ /* indentation level: 2 */
return alert(valueArg3944,valueArg3957,5,valueArg3970,4);
}
);
}
);
}
);
console.log(cc1.toString());
cc1("one-again")("two-again")("three-again");
/* this will call cont2 and cont3 again */
;
cc1("one-again");
/* this will call cont2 and cont3 again */;
console.log(cc2.toString());
cc2("two-again")("three-again");
/* this will call cont3 again */
;
cc2("two-again");
/* this will call cont3 again */;
console.log(cc3.toString());
cc3("three-again");
/* this will call alert */
;;
/* this will call alert */;
function(cont2){ /* indentation level: 0 */
cc2 = cont2;
return cont2(confirm("two"));
}
(function(valueArg4146){ /* indentation level: 0 */
return function(cont1){ /* indentation level: 0 */
cc1 = cont1;
return cont1(confirm("one"));
}
(function(valueArg4159){ /* indentation level: 1 */
return console.log(valueArg4146,valueArg4159);
}
);
}
);
#+END_SRC
** other supported syntaxes