mirror of
https://github.com/carp-lang/Carp.git
synced 2024-10-11 12:37:32 +03:00
Better.
This commit is contained in:
parent
8636a38c4a
commit
8a65fbecfa
@ -17,14 +17,12 @@ typedef struct Closure__Unit_Int {
|
||||
void *env;
|
||||
} Closure__Unit_Int;
|
||||
|
||||
// The body of the lambda, but lifted to its own function. Takes the environment as a first argument.
|
||||
int lifted_lambda_main_0(Env_main_0 *env) {
|
||||
return 1 + env->x;
|
||||
}
|
||||
|
||||
int CALL_CLOSURE__Unit_Int__Int(Closure__Unit_Int *closure) {
|
||||
return closure->callback(closure->env);
|
||||
return 1 + env->x; // simplified for readability
|
||||
}
|
||||
|
||||
// Deleter for this particular closure
|
||||
void delete_Closure__Unit_Int__Int(Closure__Unit_Int closure) {
|
||||
free(closure.env);
|
||||
}
|
||||
@ -40,7 +38,7 @@ int main() {
|
||||
.env = env_0
|
||||
};
|
||||
// call f
|
||||
int _1 = CALL_CLOSURE__Unit_Int__Int(&f);
|
||||
int _1 = f->callback(f->env);
|
||||
// delete f
|
||||
delete_Closure__Unit_Int__Int(f);
|
||||
return _1;
|
||||
|
@ -9,6 +9,47 @@
|
||||
;; f (fn [] x)] ; Lambda takes ownership of the string
|
||||
;; f))
|
||||
|
||||
|
||||
;; g : (λ [a] Int)
|
||||
(defn g [f]
|
||||
(f 5))
|
||||
|
||||
(defn h1 []
|
||||
(g inc))
|
||||
|
||||
(defn h2 [y]
|
||||
(g (fn [x] (+ x y))))
|
||||
|
||||
|
||||
(defn-do main []
|
||||
(Debug.assert-balanced
|
||||
(println* &(example1 "!"))))
|
||||
|
||||
|
||||
(defn blaha [f]
|
||||
(Int.+ 1 (f 5)))
|
||||
|
||||
(defn main [x]
|
||||
(map blaha [inc dec (fn [_] x)]))
|
||||
|
||||
;; /* 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))
|
||||
|
Loading…
Reference in New Issue
Block a user