function foo () {
bar();
var x = 1;
}
var foo;
foo = function () {
var x;
bar();
x = 1;
}
var foo = 1;
function bar () {
if (!foo)
var foo = 10;
return foo;
}
bar();
var foo = 1;
function bar () {
var foo; // = undefined
if (!foo)
foo = 10;
return foo;
}
bar(); // ⇒ 10
ClojureScript
(let [x (try ... (catch ...))]
...)
var x = (function(){
try { ... }
catch (...) { ... }
})();
Parenscript
(setf x (let ((x 1))
x))
x = (function () {
var x = 1;
return x;
})();
<object> ⇒ Object
<array> ⇒ Array
(define-class <person> (<object>)
(name ""))
(define-method hello ((person <person>))
(format-to-string "Hello, %s!"
(get person "name")))
(define-class <student> (<person>)
id)
(define-method hello ((student <student>))
(concatenate (call-next-method)
(format-to-string " Student #%d!"
(get student "id"))))
(bind ((john (make <student>
name: "John" id: 23)))
(hello john))
;; ⇒ "Hello, John! Student #23"
(bind ((x 23))
`(y x ,x ,'x))
(foo::y bar::x 23 x)
`(bind ((x ...)) ...
(define-macro inc! (place value)
`(set! ,place
(+ ,place ,(or value 1))))
(bind ((x 1)
(+ -))
(inc! x)
x)
;; ⇒ 2
(bind ((x (bind ((x 1)) x))) x)
(%bind (x1 (%bind (x2 1) x2)) x1)
(bind ((x (+ (bind ((y 1))
(+ y 2))
3)))
(+ (- x 4) x))
(%bind (y 1)
(%bind (g1 (+ y 2))
(%bind (x (+ g1 3))
(%bind (g2 (- x 4))
(+ g2 x)))))
(%bind (y 1)
(%bind (g1 (+ y 2))
(%bind (x (+ g1 3))
(+ (- x 4) x))))
(%bind (x1 (%if ...
(%bind (x2 ...)
... (foo x2))
3))
(%begin (%var (x1 #f))
(%if ...
(%begin (%var (x2 ...)) ...
(%set x1 (foo x2)))
(%set x1 3))
var x1;
if (...) {
var x2 = ...;
...
x1 = foo(x2);
} else
x1 = 3;