Skip to content

Instantly share code, notes, and snippets.

@jido
Created October 21, 2010 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jido/639173 to your computer and use it in GitHub Desktop.
Save jido/639173 to your computer and use it in GitHub Desktop.
; 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