Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Macros in Ruby

Reply
Thread Tools

Macros in Ruby

 
 
David A. Black
Guest
Posts: n/a
 
      08-06-2004
Hi --

On Fri, 6 Aug 2004, Ara.T.Howard wrote:

> On Fri, 6 Aug 2004, Hal Fulton wrote:
>
> > David A. Black wrote:
> >> Hi --
> >>

> <snip>
> >> I admit I'd opt for inconsistency over further punctuation in this
> >> case But actually I'm not sure I'd agree that & in arglists is the
> >> same usage as & as synonym for lambda. I've always thought of it as a
> >> kind of singular construct, necessary because the whole code-block
> >> thing has that singularity. Also there's this:
> >>
> >> pr = lambda {}
> >> some_method &pr
> >>
> >> which would become
> >>
> >> pr = &{}
> >> some_method &pr
> >>
> >> which bugs me in some way involving levels of indirection that I can't
> >> quite put my finger on....

> >
> > I can't put my finger on it either, but I see your point. And that is
> > perhaps the best argument against it I've seen.

>
> it's no stranger than this to me
>
> jib:~ > cat a.rb
>
> def method &block; m &block; end
> def m &block; block.call; end
>
> method{ puts 42 }
>
> jib:~ > ruby a.rb
> 42
>
> and feels alot like
>
> const char *cp = "foobar";
> printf ("%c\n", *cp);


(So your keyboard *does* have parens!

I think this is different, in the sense that

const char *cp;

declares "*cp" ("cp dereferenced by one level") to be of type const
char -- and then it's simply used that way. So it's consistent; *cp
is always of the same type, and * always means the same thing.

It's true that the two &'s in your example mean different things, so
one could argue that there's strangeness. But they're syntactically
quarantined from each other, so there's no unclarity.

However, if & were a synonym for lambda, different &'s would start to
mingle unclearly with each other. Specifically, & would then mean
both "make a Proc object from the following block" (lambda {}) and
"make a block from the following Proc object" (some_method &a_proc).
And then this:

def some_method(*args)
end

some_method &{}

could be either

some_method &lambda {}

or

some_method(lambda {})

I know that parentheses for method arguments are being encouraged
(required?) in upcoming Rubies, but I still think this would end up
getting tied in knots. To use another C analogy: it's almost like
using * and * instead of * and &, and counting on circumstantial or
semantic things to disambiguate them. (Not an exact analogy but
indicative of what I think might be the problems.)


David

--
David A. Black
http://www.velocityreviews.com/forums/(E-Mail Removed)



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
macros-loop? calling macros X times? Andrew Arro C Programming 2 07-24-2004 09:52 AM
Explanation of macros; Haskell macros mike420@ziplip.com Python 80 11-07-2003 02:22 AM
Re: Explanation of macros; Haskell macros Michael T. Babcock Python 0 11-03-2003 01:54 PM
Re: Explanation of macros; Haskell macros mike420@ziplip.com Python 5 11-01-2003 01:09 AM
Re: Explanation of macros; Haskell macros mike420@ziplip.com Python 1 10-07-2003 04:07 PM



Advertisments