r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Core] Discuss core issues

Henrik
16-Jun-2005
[1269]
ah well.... :-) but I think there is a point in it, don't you? or 
maybe there ought to be some conventions, like: "Never change a block 
to a none!" or things like that
Gabriele
16-Jun-2005
[1270]
henrik: i added your wish to rambo. will probably be implemented.
Henrik
16-Jun-2005
[1271]
thanks
Ladislav
17-Jun-2005
[1272x3]
Henrik: your wish looks unnatural, I prefer the following:

    default [index? find [a b c] 'd] [none]


the Default function is available and it has been in Rambo for quite 
some time
Otoh, your example can be written using Attempt too as follows:

    attempt [index? find [a b c] 'd]
Re default: (a user poll) I wonder whether it is useful to have it 
like: 


    default [trial code here] 'error-variable [print disarm error-variable]

or in a shorter form like:

    default [trial code here] [print disarm error]


, in the last case the error variable will always be 'error, which 
will be local to the error handling block, i.e. if you want any other 
variable you have to explicitly assign the value of the 'error variable 
to it
Gabriele
17-Jun-2005
[1275x2]
my suggestion: if the arg is a block, use 'error. if it's a function, 
assume it has one argument and pass it the error. so i can write 
default [trial code] func [myerr] [print disarm myerr] if i really 
need to.
anyway, index? none returning none doesn't seem bad to me. will probably 
be faster than using attempt or default.
Volker
17-Jun-2005
[1277x2]
Carl did similar with 'remove, for failing "remove find". but may 
be better for error-checking to be explicit (rest of code expects 
dealing only with numbers, better bail out immediate.
about default, i prefer implicit error-var too. if not, at least 
put the error-var first. maybe together with an assignment?
 default 'var [index? find [a b c] 'd] [none] 
instead of
 var: default [index? find [a b c] 'd] [none]
but i prefer the second (old) version.
JaimeVargas
17-Jun-2005
[1279x2]
The problem I see is that it complicates debugging.

>> 1 + index? find "abc" "e"

** Script Error: index? expected series argument of type: series 
port
** Near: 1 + index? find "abc"

>> 1 + attempt[index? find "abc" "e"]
** Script Error: Cannot use add on none! value
** Near: 1 + attempt [index? find "abc" "e"]
So if INDEX? returns none the error of not finding the element propagates 
to the add function. In a longer expression the programmer will start 
debuging int the wrong place.
Volker
17-Jun-2005
[1281]
(thats what i wanted to say too. just wrong wording. should be "but 
<no-none> may be better for error-checking .."
Gabriele
17-Jun-2005
[1282x5]
compare:
1 + index? any [find "abc" "e" #]
to:
1 + any [index? find "abc" "e" 0]
maybe index? should directly return zero.
JaimeVargas
17-Jun-2005
[1287]
But then you need to have a test against zero in order to catch a 
not found result.
Volker
17-Jun-2005
[1288]
but when you found nothing, there is no index. 0 would give syntactically 
valid results, letting the rest of the program run. just doing wrong 
things. none will at least led to trapping it.

thinking about it, when using series instead of indices, it bails 
out on using, not immediate too. maybe index? pasing none is k.
JaimeVargas
17-Jun-2005
[1289]
The problem with returning zero is that is an attempt to handle implcitely 
something that should be explicit, that is error catching.
Ammon
17-Jun-2005
[1290]
I vote to leave it like it is.  It makes the most sense to have Index? 
fail on a non-series value.  I've found ANY to be a very handy function 
for handling things like that.  I initially just used it with EITHER 
and IF but its starting to show up in a lot of places in my code 
because it is just nice and concise. ;-)
Gabriele
17-Jun-2005
[1291x2]
is not finding a value an error? i think it isn't.
ammon: see above, if you use ANY you get 1 which is hardly what you 
want.
JaimeVargas
17-Jun-2005
[1293x2]
Not finding a value is not necesarily and error, that the reason 
find returns NONE. But it is an error to request the index of none.
Changing the semantics of INDEX? NONE is what is at stake.
Ammon
17-Jun-2005
[1295x2]
That is true but that just means that it may not be the way you want 
to handle it.  I think Ladislav is correct here.  In some situations 
it may not be bad to continue with a bad index value but I think 
the majority of the time then you need to cancel what you are doing 
if the index is not available, hence an error.
Jaime, Agreed!
Gabriele
18-Jun-2005
[1297x4]
Jaime: for INDEX? used alone, that may be true. But asking the position 
of a value in a series and asking the index of a value in a series 
are, IMHO, the same question.
pos: find series value
idx: index? find series value
so if the former should not cause an error, neither should the latter.
Volker
18-Jun-2005
[1301]
but then give 'none, not 0.
JaimeVargas
18-Jun-2005
[1302]
That sounds better. NONE = INDEX? NONE
Ammon
18-Jun-2005
[1303]
But then you run right back into the problem of having to check for 
a NONE value on the index variable because the code using it is undoubtedly 
going to fail on NONE because it is expecting a Number.  Any way 
you look at it you are going to end up needing to check for that 
NONE value.
BrianH
18-Jun-2005
[1304]
Checking for a none value is easy with the ANY native. It's just 
like using COALESCE in SQL.
Ammon
18-Jun-2005
[1305]
Yes, there are many ways to check for NONE and most of them are easy 
I'm just not sure how much value it would actually add to have Index? 
return NONE when passed a NONE value.
Volker
18-Jun-2005
[1306x3]
as gabriele says, we have the same problem with series. can be none 
too and fail then.
and Henrik likes better flow. i guess something like
 if index? find data value [ .. ]
or 
 any[ index? find data value  default ]
since i rarely use index when i can use series, i don't know how 
important thatis.
BrianH
18-Jun-2005
[1309]
The only time I've found it useful to use index is when using values 
in one series as a key to values in another series. Kind of rare 
when you have select/skip, but sometimes you don't want to modify 
the data series. All right, since RAMBO says that there are problems 
with select/skip right now, maybe not so rare.
Volker
18-Jun-2005
[1310]
IIRC that problems relate to select/skip on strings, which is not 
very common anyway.
BrianH
18-Jun-2005
[1311]
The reply said the bug applies to blocks too.
Volker
18-Jun-2005
[1312x3]
Using Select/Skip on a String! doesn't behave in a manner consistant 
with the way that it acts on a Block! which leads to a state where 
it freezes the REBOL Interpreter.
iOops, ok, i cant read.. yes, you are right.
(no freeze, but wrong result with blocks, ok, ok.. )
BrianH
18-Jun-2005
[1315x4]
For 8bit character strings I often prefer using a 256 byte binary 
lookup string indexed by the integer equivalent of the relevant character.
That doesn't work too well with Unicode though, unless you implement 
sparse lookup tables.
Still, what is the difference really between any [index? find data 
value 1 + length? data]  and  index? any [find data value tail data] 
 ?
The former being the version you could do if null handling were added 
to index?, the latter being the way you can do the same thing now.