Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: On ordinal and cardinal numbers...

From: agem:crosswinds at: 8-Jul-2001 7:00

RE: [REBOL] Re: On ordinal and cardinal numbers... [joel--neely--fedex--com] wrote:
> [agem--crosswinds--net] wrote: > > > > reading Joel he really complains two things: > > > > Me??? Complain??? 8-O >
'complain looked so pretty in the dictionary.. no? :(
> > > > i suggest a ring! > > > > Handily done with an object... > > ring: make object! [ > _data: [0 1] > _pos: 1 > _len: length? _data > data: func [b [block!]] [_len: length? _data: copy b skip 0] > curr: does [pick _data _pos] > next: does [pick _data _pos: _pos // _len + 1] > prev: does [pick _data _pos: _pos + _len - 2 // _len + 1] > skip: func [n [integer!]] [ > pick _data _pos: _pos - 1 + n // _len + _len // _len + 1 > ] > at: func [n [integer!]] [ > pick _data _pos: n - 1 // _len + _len // _len + 1 > ] > at?: does [_pos] > ] > > which behaves as: > > >> nursery-rhyme: make ring [] > >> nursery-rhyme/data ["eenie" "meenie" "mienie" "moe"] > == "eenie" > >> loop 5 [prin [nursery-rhyme/next " "]] print "" > meenie mienie moe eenie meenie > >> loop 5 [prin [nursery-rhyme/prev " "]] print "" > eenie moe mienie meenie eenie > >> nursery-rhyme/curr > == "eenie" > >> nursery-rhyme/at? > == 1 > >> nursery-rhyme/skip 7 > == "moe" > >> nursery-rhyme/at 38 > == "meenie" > >> nursery-rhyme/at? > == 2 > >> nursery-rhyme/skip -5 > == "eenie" > > The slight awkwardness of using /DATA to configure the content > (instead of e.g. MAKE RING [...]) is the price for having > LENGTH? _DATA cached instead of being re-evaluated all over > the place. >
pretty :) but you wanted something native. since we have hash! and list! for special purposes, i thought a datatype! could be more clean than two ways of indexing. a ring! would share the zeroth and the last element. every other index would stay the same. drawback: no range-check. and it would fail with repeat based on 1, hm.. nobody has an idea? :( you used 0-base for simple scaling counting (when categories are with 1-increment instead of 0-9 10-19 ..). which you call a very common job, so some support would make sense. and for modulo-stuff like circular counters, which you apply very clever, but which is a bit harder to read (yes, users shouldn't code, but then they are to stupid to mouse too after all..). something like skip and next for its values would be more friendly. hm, is more friendly with your ready-made example ;-) but modulo-stuff is common also in clocks, foot/yards/miles, some old money-systems, maybe more. so i invented half-joking the clock!, which would be [24 60 60] with clocks, and the miles/yards/foot i don't know yet (metric zone here). we have support for urls and that. nobody want's help for miles? (well, the very common date! is there). since random is so smart to understand series
>> loop 15[random "Hello Jeff"]
== " JoelfeHlf" ;(but what is "feHlf"?!) why not something for crazy-scale-users? make ring! [24 60 60] (but i used that form for the ring-buffer..) BTW could something native like b0: func[index][ index + 1 ] ;base-zero pick block b0 0 help? or to slow/ugly too?
> > > > ;-) Volker > > --zero is the highest number > > > > ROFL!!! >
Thank you. with modulo (0 .. (length? n) - 1) it indexes the same element as length?? :) and for experienced programmers it is far far far more superior to 1 or others as the base, ground, whatever, which makes it highest/greatest/best,.. :) (for deep programming i agree BTW. for simple counting jobs and talking with computers and people iam reluctant )