Thanks for clarification. But I am wondering about a function can return nil:
user=> (fn [] ((+ 1 2) nil)) #<user$eval__63$fn__65 [EMAIL PROTECTED]> But "just returning nil" is not ok? user=> (fn [] (nil)) java.lang.NullPointerException (NO_SOURCE_FILE:24) user=> (fn [] ((nil))) java.lang.NullPointerException (NO_SOURCE_FILE:25) Thanks -Ralf On Sat, Nov 29, 2008 at 3:18 PM, Rich Hickey <[EMAIL PROTECTED]> wrote: > > > > On Nov 29, 9:06 am, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote: > > On Nov 29, 2008, at 8:03 AM, Ralf Bensmann wrote: > > > > > But #(...) and (fn [] ...) should be the same? > > > > The other replies have noted why that's not right. > > > > There is a way to get the effect you were looking for. If you want to > > return a constant or do something with side-effects before returning a > > value, you can use do: > > > > #(do nil) is a function that will always return nil > > > > #(do (prn "hi") 5) will print "hi" and then return 5 > > > > I really dislike the use of do other than for side effects. I imagine > a code checker which will eventually flag usage of do et al. > > Someone did show (fn [] nil). If it's somehow important to use #(), > please use: > > #(identity nil) > > Rich > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---