[#6363] Re: rescue clause affecting IO loop behavior — ts <decoux@...>

>>>>> "D" == David Alan Black <dblack@candle.superlink.net> writes:

17 messages 2000/11/14
[#6367] Re: rescue clause affecting IO loop behavior — David Alan Black <dblack@...> 2000/11/14

Hello again --

[#6582] best way to interleaf arrays? — David Alan Black <dblack@...>

Hello --

15 messages 2000/11/26

[#6646] RE: Array Intersect (&) question — Aleksi Niemel<aleksi.niemela@...>

Ross asked something about widely known and largely ignored language (on

23 messages 2000/11/29
[#6652] RE: Array Intersect (&) question — rpmohn@... (Ross Mohn) 2000/11/29

aleksi.niemela@cinnober.com (Aleksi Niemel) wrote in

[#6723] Re: Array Intersect (&) question — Mathieu Bouchard <matju@...> 2000/12/01

> >Use a hash. Here's code to do both and more. It assumes that

[#6656] printing/accessing arrays and hashes — raja@... (Raja S.)

I'm coming to Ruby with a Python & Common Lisp background.

24 messages 2000/11/30

[ruby-talk:6649] Re: Question on sort!

From: Hugh Sasse Staff Elec Eng <hgs@...>
Date: 2000-11-29 20:20:02 UTC
List: ruby-talk #6649
On Thu, 30 Nov 2000, Dave Thomas wrote:

> Hugh Sasse Staff Elec Eng <hgs@dmu.ac.uk> writes:
> 
> > On Wed, 29 Nov 2000, Dave Thomas wrote:
> > 
> > > 
> > > gsub! and sub! give information that's fairly expensive to determine
> > 
> > But we could introduce sub? -- takes same args as sub! but doesn't change
> > anything, returns true if sub would change anything, false otherwise...
> > This would be less expensive than making the changes in a copy [it would
> > not make the copy or the changes], since as soon as one change was found
> > the thing could stop.  Similarly for sort?, gsub?, reverse?, rather than
> > checking afterwards....
> 
> OK, and that's effectively what Ruby does now. However, that isn't

Its ! ops make the changes, these would not.

> quite what the intent is. For example
> 
>     "cat".sub!(/../, 'do')   => dot
>     "dog".sub!(/../, 'do')   => dog
> 
> Should the last one be 'nil'? If not, why not?

Oh, I missed this subtlety before.  I'd say the least surprising thing
would be to not return nil, because in this case it means doing an exta
comparison on top of {match ? change : don't change}. The second pattern
could be quite complex, with \1 etc in it, so one would not want this
extra work....  I think.  Or have I missed something else?

> 
> I come back to the point, though. Is it ever used, and if so, does it
> _really_ mean that the string is unchanged, or is it taken to mean
> that the pattern did not match (in which case the language already has 
> constructs we can use).
> 

OK, suggestions for gsub? and sub? withdrawn.  I can see cases
with general objects in arrays where sort? and reverse? could
still be used, but how often and at what code bloat cost I cannot
say.
 
> 
> Dave
> 
> 
	Hugh
	hgs@dmu.ac.uk



In This Thread

Prev Next