Created
October 21, 2010 19:45
-
-
Save jido/639173 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; I have this in my code | |
(defn fun [f, continuation] (-> f continuation)) ; pass f to continuation | |
; I want to change it to this | |
(defn fun [argc, f, continuation] | |
(continuation | |
(fn [& args] | |
(let | |
[diff (- argc (count args)) | |
filler | |
(fn missing-alt [& more] | |
#((eval 'dodo*throw) {:message | |
(str "Missing alternative (" argc " expected), arguments: " more)}))] | |
#(apply f | |
(concat args (repeat diff filler))))))) | |
; Basically what it does is, given a desired number of arguments it calls the | |
; function f with the missing args filled with filler where filler calls function | |
; 'dodo*throw, defined as a local var of the calling function (that does not work | |
; with eval does it?) | |
Use: | |
(trampoline | |
(fun 2 (fn f1 [dodo*return, dodo*throw] | |
(fun 2 (fn f2 [dodo*return, dodo*throw] #(dodo*return 10)) | |
(fn [f2] | |
#(f2 (fn [x] x)) ; missing arg! | |
....) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment