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

World: r3wp

[Core] Discuss core issues

BrianH
9-Mar-2009
[12860]
For one thing, it would not be FOREACH that does this - it would 
be another function.
Gregg
9-Mar-2009
[12861]
Gabriele has an NFOREACH func that iterates over multiple blocks.

http://www.mail-archive.com/[rebol-list-:-rebol-:-com]/msg18682.html
http://www.rebol.it/giesse/utility.r
BrianH
9-Mar-2009
[12862x2]
I was thinking that would make a good start, yes :)
Pekr, I was thinking that the outer join approach would fit in the 
best with the R3 treatment of series changes and none. There are 
fewer occasions where errors are triggered in R3, and those occasions 
are carefully chosen (except for bugs, of course).
Steeve
9-Mar-2009
[12864]
btw, i had the same need than Pekr, several in the past. I think 
it's common pattern. should be studied IMHO.
Henrik
9-Mar-2009
[12865]
the question might also be whether to include an NFORALL.
Steeve
9-Mar-2009
[12866x2]
tried to made nforeach for R3: 
- missing do/next to evaluate functions in the data block

- probably speed optimizations can be made (not probably, certainly)

nforeach: func [
	data [block!] body [block!]
	/local vars
][
	vars: make block! (length? data) / 2
	data: copy data
	forskip data 2 [
		append vars data/1 			;* extract vars

  change/only data to block! data/1 	;* convert vars to block (if needed)

  if word? data/2 [poke data 2 get data/2];* get serie from word (do/next 
  much relevant if available) 
	]	

 vars: bind? first use vars reduce [vars]	;* create a context with 
 vars
	bind head data vars
	while [
		also not tail? second data: head data 
		forskip data 2 [
			poke data 2 skip set data/1 data/2 length? data/1
		]
	] bind/copy body vars
]
>> nforeach [a [1 2 3] [b c] [4 5 6 7 8 9]] [print [a b c]]
1 4 5
2 6 7
3 8 9
BrianH
9-Mar-2009
[12868x2]
Nothing about a function like nforeach should require DO/next. If 
it does, that would be the first thing to fix.
The next thing to fix would be having the words and data interleaved 
- they should be separate for easier data processing.
Gabriele
10-Mar-2009
[12870x2]
Brian, right, if we had DO in PARSE, there would be no need for DO/NEXT.
If you prefer using 'a instead of a in the example above, thus being 
different from FOREACH, then you can just use reduce.
Steeve
10-Mar-2009
[12872]
Brian, by separating words and data, do you mean this format ?
>> nforeach [a [b c]]  [[123][456789]]  [print [a b c]]
BrianH
11-Mar-2009
[12873x4]
Yes, Steeve. The implementation wouldn't need DO/next at all, or 
anything like it.
Gabriele, if we had DO in PARSE we would still need DO/next. Just 
not for nforeach - neither DO/next nor DO in PARSE would be appropriate 
there. Nor would REDUCE be needed. All you'd need would be BIND/copy 
and SET, and some loop function.
We would probably want to skip the set-word behavior of R3's FOREACH, 
but if we need it it can be compiled - I did so for MAP in R2.
Gabriele, I'm having a little trouble finding your request for the 
DO operation in R3 chat, under the R3/Parse heading (28). I already 
added your DO proposal to the official Parse Proposals page months 
ago (with some semantic cleanup) but if you don't speak up in the 
discussion forum then I will have more trouble convincing Carl. Any 
requests for it here might as well be thrown away - they will be 
long gone before we get to PARSE.
Steeve
11-Mar-2009
[12877]
Was lazzy, so  i made the nforeach brian's version.

nforeach: func [
	vars [block!]  data [block!] body [block!]
	/local ctx n 
][
	data: copy data
	vars: copy vars
	ctx: make object! 5

 forall vars [change/only vars bind/new to block! vars/1 ctx]   ;** 
 convert all vars to blocks of vars (set need it)
	while [
		n: 1
		also not tail? first data
		forall vars [

   poke data n skip set first vars pick data ++ n length? first vars
		]
	] bind/copy body ctx
]
Graham
12-Mar-2009
[12878x6]
this is Ladislav's function to find out if your PC is out.

get-nist-correction: func [/local nist-time cpu-time mjd hms] [
 nist-time: read daytime://time.nist.gov
 cpu-time: now

 parse/all nist-time [skip copy mjd 5 skip 2 thru " " copy hms 8 skip]
 nist-time: 17/Nov/1858 + to integer! mjd
 nist-time/time: to time! hms
 nist-correction: difference nist-time cpu-time
]
it basically parses the text string returned by the daytime server, 
and works out what utc is ( nist-time )
it then displays the difference between utc and your pc time.
now, when I set my pc clock to canadian time, or EDT ( -0400 ), on 
vista, Rebol says timezone is -3 and not -4
Dunno what it does in XP ...
anyway, now the nist correction is now 1 hour out :(
Gregg
12-Mar-2009
[12884x2]
connecting to: time.nist.gov
== 0:00:03
XP x64
Graham
12-Mar-2009
[12886]
what time zone?
Gregg
12-Mar-2009
[12887]
US Mountain time (-6:00 right now)
Graham
12-Mar-2009
[12888]
what happens if you change to EDT ?  Does Rebol report the time zone 
correctly?
Maxim
12-Mar-2009
[12889x2]
on my system, with the patch installed yes.
(XP)
Graham
12-Mar-2009
[12891]
what patch?
Maxim
12-Mar-2009
[12892x4]
the XP fixing of timezones...
if you have updates, it should have been rolled in a long time ago.
the tz rules have to be updated every few years...
it seems.
Graham
12-Mar-2009
[12896x2]
I'm on Vista
so are you at -3 or -4 now?
Maxim
12-Mar-2009
[12898x2]
since vista crapped on reboot... I have turned away.  I mean destroying 
your own MBR while booting is a pretty bad bug... It was partway 
booting.
-4
Gregg
12-Mar-2009
[12900]
Last year was the big TZ update here.
Maxim
12-Mar-2009
[12901]
so I installed XP  (30 hours of work mind you)
Graham
12-Mar-2009
[12902]
Hmm..  so why when I change to canadian time in vista, does Rebol 
say I'm at -3 ?
Maxim
12-Mar-2009
[12903x3]
when it normally takes me 1-2 hours...
EST?
EDT?
Graham
12-Mar-2009
[12906]
Atlantic time
Maxim
12-Mar-2009
[12907x2]
thats correct.
-3 is the current atlantic time... eastern is at -4
Graham
12-Mar-2009
[12909]
Atlantic time is -3 ?