On Oct 26, 9:26 am, John Harrop <jharrop...@gmail.com> wrote:
> On Sun, Oct 25, 2009 at 2:50 PM, Radford Smith <radscr...@gmail.com> wrote:
>
> > Ruby blocks are anonymous functions with syntax sugar. You could write
> > James' with_open method like this:
>
> > def with_open(stream, &f)
> > f.call(stream)
> > end
>
Yeah, sorry I don't think about these things too heavily sometimes.
Ruby's yield is a sexy way of doing this.
Also, you can create anonymous functions out in the open like this:
f = lambda do |arg1,arg2|
....
end
f.call arg1 , arg2
or
f = Proc.new{|arg1| ... }
f.call arg1
Replace do/end with {/} if preferred.
I guess all of this sort of answers my earlier questions although
with the macro stuff it looks like it's going to take some time to
fully
grok. At least once I do I'll understand all those Paul Graham
essays :)
> > The equivalent in Clojure is effectively the same:
>
> > (defn with-open [stream f]
> > (f stream))
>
> What about exception safety? Shouldn't that really be
>
> (defn with-open [stream f]
> (try
> (f stream)
> (finally
> (.close stream))))
>
> ?
In ruby you can do similarly with begin ... rescue ... ensure ....
end.
Should add, I thought the white paper from Clojure in Action was a
good read for someone who is newish to lisp.
Thanks folks,
Daniel Bush
--~--~---------~--~----~------------~-------~--~----~
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
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---