2018-06-15 16:24:11 +03:00
|
|
|
;;(defn f [s] (str* s "!"))
|
|
|
|
|
|
|
|
(defn example1 [suffix]
|
|
|
|
(Array.copy-map (fn [s] (str* s suffix)) ;; Can use 'suffix' (of type &String) as long as we're in the example1-scope
|
|
|
|
&[@"a" @"b" @"c"]))
|
|
|
|
|
|
|
|
;; (defn example2 []
|
|
|
|
;; (let [x @"hello"
|
|
|
|
;; f (fn [] x)] ; Lambda takes ownership of the string
|
|
|
|
;; f))
|
|
|
|
|
2018-06-18 13:09:25 +03:00
|
|
|
|
|
|
|
;; g : (λ [a] Int)
|
|
|
|
(defn g [f]
|
|
|
|
(f 5))
|
|
|
|
|
|
|
|
(defn h1 []
|
|
|
|
(g inc))
|
|
|
|
|
|
|
|
(defn h2 [y]
|
|
|
|
(g (fn [x] (+ x y))))
|
|
|
|
|
|
|
|
|
2018-06-15 16:24:11 +03:00
|
|
|
(defn-do main []
|
|
|
|
(Debug.assert-balanced
|
|
|
|
(println* &(example1 "!"))))
|
2018-06-18 13:09:25 +03:00
|
|
|
|
|
|
|
|
|
|
|
(defn blaha [f]
|
|
|
|
(Int.+ 1 (f 5)))
|
|
|
|
|
|
|
|
(defn main [x]
|
2018-08-24 16:20:05 +03:00
|
|
|
(Array.endo-map blaha [inc dec (fn [_] x)]))
|
2018-06-18 13:09:25 +03:00
|
|
|
|
|
|
|
;; /* void blaha(void *f) { */
|
|
|
|
;; /* int _0; */
|
|
|
|
;; /* if is_closure(f) { */
|
|
|
|
;; /* _0 = call(f, 5); */
|
|
|
|
;; /* f.delete(f); */
|
|
|
|
;; /* } else { */
|
|
|
|
;; /* _0 = f(5); */
|
|
|
|
;; /* } */
|
|
|
|
;; /* return (1 + _0); */
|
|
|
|
;; /* } */
|
|
|
|
|
|
|
|
|
|
|
|
(defn call-on-me [f]
|
|
|
|
(f))
|
|
|
|
|
|
|
|
(def a (fn [] 123))
|
|
|
|
(defn b [] 666)
|
|
|
|
|
|
|
|
(defn-do main []
|
|
|
|
(a)
|
|
|
|
(b))
|