On Nov 18, 6:48 pm, samppi <[EMAIL PROTECTED]> wrote:
> I'm trying to unit-test a library with which a user can define methods
> on the library's multi-function to change its behavior. So I need to
> be able to define lexically-scoped methods in each test. Is it
> possible to use let to create a lexically-scoped method?
>
> The problems I'm encountering are that, unlike for functions, there
> doesn't seem to be a special-form for creating methods, and that even
> if it could be defined it'd go in the current namespace instead of the
> library's namespace. But does anyone know how I can test this anyway?
>
> Thanks in advance!

Yes, this is all possible.

fn is the special form that creates new functions.

(fn [x] (* x x)) returns an anonymous function.

You can also use let to assign names to the anonymous functions:

(let [foo (fn [x] (* x x))
    (println (foo 3))

defn is a macro that translates to

(def name (fn [args] ...))

Allen

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to