From: avi@...4.com (Avi Bryant) Date: 2001-11-25T15:44:07+09:00 Subject: [ruby-talk:26428] Re: Table: Ruby versus Smalltalk, Objective-C, C++, Java; John Knight wrote in message news:<3C00332C.3E21DBC4@johnknight.com>... > After I sent my comment out, I started to think about the lack of macros in ruby. > I am not sure I understand how block structures replace macros. > They may replace closuress but macros? One common use of macros in Lisp and Dylan is to hide the use of closures. For example, there's an idiom for resources such as files that lets (open-resource x) (do-some-stuff...) (close-resource x) be expressed as (with-resource x (do-some-stuff...)) If this were written as a function rather than a macro, it would have to be (with-resource x (lambda () (do-some-stuff...)) In ruby, the equivalent idiom uses a block, which is lighterweight syntax than lambda and so doesn't seem as useful to wrap. However, not all cases where closures are wrapped by macros in lisp are as easily replicated in Ruby. For example, assuming Ruby blocks introduced a new lexical scope (which they unfortunately don't, but never mind), the expansion of a lisp let statement in ruby looks like: proc{|x, y| do_something() }.call(a,b) This can be improved to: let(a,b){|x, y| do_something() } but it still ain't as pretty as lisp. And of course there are scores of uses for macros that have nothing to do with closures. A classic one is embedding domain-specific dialects, such as lispified HTML - the ruby cgi library is nice, but it's not as clean or as general as the typical (with-html (html (form :action 'foo' (input :name 'bar'))) etc. Avi