• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r4wp

[#Red] Red language group

Ladislav
17-Nov-2012
[3984x6]
This is my solution of 1b):

head-index?: func [s [series!] i [integer!]] [i - 1 + index? s]
(again, a case of "working index arithmetic")
(although a bit more complicated than the 1c case)
1a) is a task for people stating that "zero does not exist"
...and also for people stating that "index arithmetic *is* working 
in R2"
Note that the difference between 1c) and 1b) seems to demonstrate 
why 0-based indexing may be found more convenient than 1-based indexing
PeterWood
17-Nov-2012
[3990]
I know this would be consiidered a "workaround" but

head-index?: func [s i] [i - (index? head s) + (index? s)]
Ladislav
17-Nov-2012
[3991x2]
Testing your implementation with:

1 = index? head s
0 = i
2 = index? s

i get:

1 = head-index? s i

, which is incorrect
(your solution is actually 1b, not 1a)
BrianH
17-Nov-2012
[3993]
It would work for 1c too.
Ladislav
17-Nov-2012
[3994x2]
yes
(but in any of those cases my solutions are simpler)
Kaj
17-Nov-2012
[3996]
In REBOL, we have an important design rule to optimise for the common 
case. Your exercise is contrived, while R2 still optimises for the 
common cases
Ladislav
17-Nov-2012
[3997x2]
OK, for Kaj: I do not insist the solution has to be "optimized".
just working
 will be OK
Kaj
17-Nov-2012
[3999]
Another case of the common case is that Red's intended common audience 
is common people, not mathematicians. While R3 "works" for mathematicians, 
R2 is the one that works for common people
Ladislav
17-Nov-2012
[4000]
So, if we consider Peter Wood a "common man"(no offense intended), 
do you state that his solution works?
Kaj
17-Nov-2012
[4001]
I already stated I'm not talking about your mathematical exercise, 
but about common programming patterns in REBOL, such as series/-1
Ladislav
17-Nov-2012
[4002]
OK, so you feel offended that Peter considered my exercise worth 
trying?
Kaj
17-Nov-2012
[4003]
Not at all
PeterWood
17-Nov-2012
[4004]
Kaj is write I wouldn't write such a function.
Ladislav
17-Nov-2012
[4005]
...but you did...?
Kaj
17-Nov-2012
[4006]
To oblige you, because Peter is such a nice commoner :-)
Ladislav
17-Nov-2012
[4007x2]
I do not think he really felt obliged?
Also, optimization (as many programmers know) is not about making 
something incorrect or non-working. It is about making something 
better in some sense.
Kaj
17-Nov-2012
[4009]
Yes, and that's what Andreas' formulation of the ordinal! proposal 
does
Ladislav
17-Nov-2012
[4010]
Well, I would state that my task looks like a "simple enough task 
to tackle", and the one even inexperienced users (surely not only 
mathematicians) should be able to tackle, and they would, as Peter 
demonstrated, if the index arithmetic weren't broken.
Kaj
17-Nov-2012
[4011]
That's not the point; as Peter said, a common REBOL programmer wouldn't 
program this function exactly because there are better solutions
BrianH
17-Nov-2012
[4012]
Give us a better solution than PICK/POKE then.
Andreas
17-Nov-2012
[4013]
One note: as far as I can tell, s/-1 is not a common pattern at all, 
but rather a quite "uncommon" one in as far as it is rarely encountered 
in real REBOL code. FIRST and /1 are the common patterns, which are 
not touched by R3.


Actually, the only thing different in R3 that arguably "works for 
common people" in R2 is this uncommon pattern of s/-1 and s/-2. Every 
other use of negative indices is broken in R2 (and as such, works 
for neither mathematicians nor common people) but works in R3.
BrianH
17-Nov-2012
[4014x2]
I really don't care about path syntax with computed indexes, it's 
ugly and awkward, and broken because of the 0 hole. I'd really rather 
use a function. As long as we get PICKZ/POKEZ, I'll be good. We already 
have SKIP to act as a non-broken AT. But at least plug the hole with 
a triggered error, so it won't mess people up silently. It's a huge 
failure, at least make not fail silently.
As Ladislav demonstrated, 0-based is better anyway for computed indexes, 
so PICKZ and POKEZ would be better to use even if PICK and POKE didn't 
have the hole
Kaj
17-Nov-2012
[4016]
Nenad already counted a lot of occurrences of /-1 in Red. Most others 
have failed to contribute analyses of real code
Andreas
17-Nov-2012
[4017]
14 occurrences of /-[1-9] in current Red sources, 1 is from makedoc2.
BrianH
17-Nov-2012
[4018]
Which means that either Doc prefers path syntax over function syntax, 
or path syntax was implemented first, or both. Nonetheless, it's 
real code of any significant complexity, so it probably includes 
backward index use.
Kaj
17-Nov-2012
[4019x2]
I just counted three occurrences in PowerMezz, and two occurrences 
of /-2
Most Red code is currently R2 code, so implementation order doesn't 
come into it
Andreas
17-Nov-2012
[4021]
Just for comparison: Red's sources are 13k lines (including whitespace 
and comments) of code.
BrianH
17-Nov-2012
[4022]
The preference then. So, at least 2 people like to use path syntax 
(PowerMezz was written by one guy). It was bound to happen that someone 
wouldn't find that syntax ugly :)
Andreas
17-Nov-2012
[4023x2]
The above counts are not about path syntax, but specifically about 
_negative indices_ in paths.
In the ancient (!!) rebol.org snapshot I have locally, I counted 
11 occurrences in 8 files (blog, new-blog, make-doc, make-doc-pro, 
makedoc2, json, translate, xml-dom) in a total of ~1000 files and 
255k lines of code.
BrianH
17-Nov-2012
[4025x3]
Yup, that's what I think is ugly, almost as bad as paths with parens. 
That's why I tend to use PICK when I'm doing negative indexes.
Personal preference :)
Same code though.
Kaj
17-Nov-2012
[4028]
People have been discouraged to use fixed path indexes because they 
are supposedly slower in R2 than FIRST and such, but I like path 
syntax because it is shorter and unambiguous
Ladislav
17-Nov-2012
[4029]
Just to make myself more clear for "common people": I think that 
the programming language should be designed so that "common people" 
should not need a specialized mathematical training to be able to 
define the HEAD-INDEX? function; rather I think that they should 
be able to successfully tackle a problem of such a low complexity 
without any problem. Also, I noticed that Kaj's opinion differs.
BrianH
17-Nov-2012
[4030]
They were slower in R2. I think that they're faster in R3.
Kaj
17-Nov-2012
[4031]
That's what I said
BrianH
17-Nov-2012
[4032]
supposedly
 :)
Andreas
17-Nov-2012
[4033]
Brian, just for the record, I find your proposal reasonable and pragmatic.


If I'm given PICKZ and POKEZ, I couldn't care less about the poor 
souls suffering from trying to use path syntax with negative indices 
and falling into the 0 hole. Maybe a bit egoistic, but well.