[#1816] Ruby 1.5.3 under Tru64 (Alpha)? — Clemens Hintze <clemens.hintze@...>

Hi all,

17 messages 2000/03/14

[#1989] English Ruby/Gtk Tutorial? — schneik@...

18 messages 2000/03/17

[#2241] setter() for local variables — ts <decoux@...>

18 messages 2000/03/29

[ruby-talk:02027] Re: Ruby Syntax similar to other languages?

From: David Suarez de Lis <excalibor@...>
Date: 2000-03-20 09:41:38 UTC
List: ruby-talk #2027
Good morning, (for me :)

matz dixit:

> Hi,
> 
> In message "[ruby-talk:02003] Re: Ruby Syntax similar to other languages?"
>     on 00/03/18, "Conrad Schneiker" <schneiker@jump.net> writes:
> 
> |> What's the benefit of foo.s(/pat/, "repl", "g") over foo.gsub(/pat/,
> |"repl")?
> |
> |In vi, sed, and perl, you don't thing of sub and gsub as being two different
> |methods, but rather as a single method that is modulated by optional
> |parameters--including g, i, s, m, o, e, and x in perl (IIRC), <snip>

I pretty much agree with Clemens in this one... presenting a single interface looks much more tidy and clean for this kind of operation... (I can understand the rationale behind sub and sub!, I am used to it from scheme... but why separating the global from the 'just once' or other possibilities?

> Hmm, although I think options i, s, m, o, and x should belong to
> regexp, I can understand your opinion.

Certainly, options should belong to the re... that would make it

string.s(/regex/imx, "replacement" [, OVERWRITE])

or maybe:

string.s(/regex/imx, "replacement")
string.s!(/regex/imx, "replacement")

> Hmm, are you proposing new syntax to do that?

I'd provide it as sintactical sugar for .sub and .gsub if that's more politically correct... but I think Clemens had a real good idea there and providing a simpler interface is the Right Thing...

> A method like Clemens suggested in [ruby-talk:01962] can be added
> relatively easily, but introducing syntax like s/RE/STR/ is another
> story, which I can hardly accept.

Certainly, it's not natural with Ruby... 

Even ``string =~ /regex/i'' looks unnatural... (even very familiar to sed, vi, Perl users)

I'd rather reduce interfaces to ``string.m(/regex/i)'' which feels more like OO to me: apply the m(atch) method to object ``string'' with this regex object ``/regex/'' with options ``i''

Again it feels more like the Right Thing...

On the other hand, it's your language :) But I honestly think it would make learning and use easier and tidier...

best regards,
d@
-------------------------------------------------------------
Mensaje enviado gracias al correo gratuito de Demasiado Corp.
[ http://correo.demasiado.com ]
-------------------------------------------------------------

			   

In This Thread

Prev Next