Re: A better way then just "$" -- !

new topic     » topic index » view thread      » older message » newer message

On Wed, 24 Sep 2003 00:29:43 +0100 (09/24/03 09:29:43)
, Pete Lomax <petelomax at blueyonder.co.uk> wrote:

>
>
> On Tue, 23 Sep 2003 07:42:15 +1000, Derek Parnell
> <ddparnell at bigpond.com> wrote:
>
>> From: "Pete Lomax" <petelomax at blueyonder.co.uk>
> <snip>
>>> Hmm. consider the common expression:
>>> s=s[1..idx-1]&s[idx+1..length(s)]
> <snip>
>>> However, I did get to think what would be the easiest way to express
>>> this common idiom and came up with:
>>>
>>> x[not idx]
>>> or
>>> x[not 3..5]
>>>
>>> which is a lot neater than
>>> x[1..idx-1]&s[idx+1..length(x)]
>>>
>>> or even
>>> x[1..2]&[6..$]
>>>
>>
>> Pete, I like this idiom. And I'd support either X[not Y] or X[! Y]
> x[!y] is not as Euphorian imo..

As in "x != y" then, or maybe we should be writting "not x = y", or change 
Eu to be able to say "x not = y" blink


>> The idiom is short, meaningful, and still euphoric. Well done.
>
> In the interests of fair play, democratic voting, and all that, I
> should point out that there *IS* a fair use of "not" immediately
> following "[" which this change might break:
>
> sequence x
> 	x={"No","Yes"}
> for i = 0 to 1 do
> 	printf(1,"%s\n",{x[not i+1]})
> end for
>
> .. My vote would be to let that very unusual case break, I seriously
> doubt anyone has ever used this, or at least in the rare cases they
> have, it should be easy enough to change (and easy to search for),
> however what do other people think?


But x[! i+1] will not break any existing code.

> Pete
> PS x[not 0] should give an index out of bounds error, imo.

Yeah, that sort of makes sense. Anything after the 'not' should be a valid 
index for the given sequence. But on the other hand, wouldn't it be useful 
to do this ...

   x = x[! find(a,x) ] -- to strip out an element based on its value, and 
if its not in the sequence, the whole sequence is returned intact. If find 
myself doing this operation a fair number of times.

The more I think about this, the more it appeals.

-- 

cheers,
Derek Parnell

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu