Re: lambda function returning a constant?

2011-09-07 Thread Mark Rathwell
How about this: (#(true)), is this not calling a function that has no arguments and returns true? But it still gives same exception This actually is trying to call 'true' as if it were a function, not a constant. The thing I think you're missing here is: when a symbol is butted up against an

Re: lambda function returning a constant?

2011-09-07 Thread Mark Rathwell
As you've already seen, if you just want the original value returned from a function, you can call the 'identity' function with that something as an argument, as in #(identity %) or #(identity true), etc. I should have also made clear here that you would never actually use this in real code,

Re: lambda function returning a constant?

2011-09-06 Thread Laurent PETIT
2011/9/4 julianrz julia...@yahoo.com Hello All, I am new to Clojure. Surprised why this code does not work: user= (filter #(%) [1 2 3]) ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn Here my intent behind #(%) is to define a lambda function returning its argument.

Re: lambda function returning a constant?

2011-09-06 Thread Alan Malloy
As Laurent says, you should just use the built-in `identity` function, but you can write it yourself: as you noticed, (fn [x] x) works, but if you want to do it with the shorthand syntax you can use #(do %). On Sep 4, 1:56 pm, julianrz julia...@yahoo.com wrote: Hello All, I am new to Clojure.

Re: lambda function returning a constant?

2011-09-06 Thread julianrz
(NO_SOURCE_FILE:0) I come from Scala experience, where it is easy to define a quick lambda function returning a constant or another simple expression, e.g. = true is a function with no args and returning true. Things like that are sometimes useful to pass into higher-order functions expecting a function

Re: lambda function returning a constant?

2011-09-06 Thread Armando Blancas
(#(true)), is this not calling a function that has no arguments and returns true? But it still gives same exception Not really: user= (macroexpand-1 '#(true)) (fn* [] (true)) I guess I should forgo the macro and go directly with (fn  [] true) For something like = true try: user= (defmacro =

Re: lambda function returning a constant?

2011-09-06 Thread Michael Gardner
On Sep 6, 2011, at 10:43 PM, Armando Blancas wrote: For something like = true try: user= (defmacro = [expr] `(fn [] ~expr)) #'user/= (macroexpand-1 '(= true)) (clojure.core/fn [] true) Alternatively: (constantly true) -- You received this message because you are subscribed to the Google

Re: lambda function returning a constant?

2011-09-06 Thread Phil Hagelberg
On Tue, Sep 6, 2011 at 7:32 PM, julianrz julia...@yahoo.com wrote: I come from Scala experience, where it is easy to define a quick lambda function returning a constant or another simple expression, e.g. = true is a function with no args and returning true. Things like that are sometimes