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

World: r3wp

[Rebol School] Rebol School

Steeve
7-Mar-2010
[2883]
actually it's the revese, those ones are called 'global
BrianH
7-Mar-2010
[2884]
All variables that are local to the function itself.
PatrickP61
7-Mar-2010
[2885]
I see -- got my terminology mixed up
BrianH
7-Mar-2010
[2886]
Look at the source of FUNCT, it's a good lesson on function creation 
tricks. And compare the R2 and R3 versions.
PatrickP61
7-Mar-2010
[2887]
will do -- thank you very much
BrianH
7-Mar-2010
[2888]
The source in DevBase has some comments that help explain things 
a bit, so you might start there.
PatrickP61
7-Mar-2010
[2889]
I'm an old mainframe cobol kind of guy, and I trying to setup something 
that resembles the perform statement:
debug?: on
perform: funct [paragraph] [

 if debug? [print form ["para " paragraph]]      ;<-- when debug? 
 is on, the paragraph name will be printed before it is "performed"
	do paragraph
	]
a000-mainline:
          perform b100-init
          perform b200-term
b100-init: print "init"
b200-term: print "term"
perform a000-mainline
halt

expected results:
para a000-mainline
para b100-init
init
para b200-term
term
halt


my intention is to define each paragraph and then "perform" them. 
 But I haven't figured it out yet.
Steeve
7-Mar-2010
[2890]
Houston, you've got a problem
BrianH
7-Mar-2010
[2891]
The FORM is unnecessary.
Steeve
7-Mar-2010
[2892x2]
you need to wrap your lines in some blocks
a000-mainline: [
          perform b100-init
          perform b200-term
]
b100-init: [print "init"]
b200-term: [print "term"]
perform a000-mainline
halt
PatrickP61
7-Mar-2010
[2894x2]
Stupid me -- of course!!!
if debug? [print "para " paragraph]  <-- this isn't working just 
right.  I only get "para" and nothing after that when I expect the 
paragraph name to be printed.  Do I need mold or something like that?
Steeve
7-Mar-2010
[2896]
be carefull with the typo

perform: funct ['paragraph] [
	if debug? [print  ["para " paragraph]]      
	do get paragraph
]
BrianH
7-Mar-2010
[2897]
And you can use FUNC here instead of FUNCT. FUNCT has more definition-time 
overhead.
PatrickP61
7-Mar-2010
[2898]
Perfect!!! -- Thank you again.  I didn't know about the GET function
Steeve
7-Mar-2010
[2899]
it'll be 10 $
PatrickP61
7-Mar-2010
[2900x2]
Thank you again Steeve and BrianH.  Now it is so easy for me to just 
set the DEBUG? value and see my script being executed!
Only $10 -- you got it.  maybe I can buy you a round or two if we 
ever get at a DevCon!!!
BrianH
7-Mar-2010
[2902]
Notice the use of the lit-word calling convention in the PERFORM 
function: This passes the word unevaluated and lets you get from 
it later.
PatrickP61
7-Mar-2010
[2903]
There is so much to learn from you guys!  :-)
Steeve
7-Mar-2010
[2904x3]
Or you can lend them on my Pokerstar's account :)
Jeez, i run bad currently
I should code instead, i'm better at that
PatrickP61
7-Mar-2010
[2907x2]
What is the best way to determine the number of seconds that has 
occurred between two timestamps?

I want to determine that offset, then apply it to another timestamp 
and then get a new timestamp.  
ex:
ts-bgn:		01-jan-2001/01:01:01
ts-end:		02-mar-2004/05:06:07
ts-offset:	ts-end - ts-bgn

I am hoping to get the difference in the number of days, and the 
number of hours, minutes, seconds. but I only get the number of days 
1156

Is it possible to get a fraction of a day that is accurate enough 
to the second?

ts-offset:	to-decimal (ts-end - ts-bgn)		This gives 1156.0 which 
is not right.  Any ideas?
I tried to-time, but  I get an error message
ts-offset:  to-time ts-end - to-time ts-bgn
** Script error: cannot MAKE/TO time! from: 1-Jan-2001/1:01:01
** Where: to to-time
** Near: to time! :value


Is this error because the number of seconds would be so extremely 
high due to the number of days included?
Izkata
8-Mar-2010
[2909]
Here you go:
>> difference 02-mar-2004/05:06:07 01-jan-2001/01:01:01
== 27748:05:06
PatrickP61
8-Mar-2010
[2910]
sweet!!! -- Thank you Izkata.  :-)
Reichart
8-Mar-2010
[2911]
Patrick

REBOL has a LOT of words (functions).

It really is worth it to just read all of them (even quickly) it 
is a lot of fun, and realize the amazing depth of it.


When I get a new peice of software (or even hardware) I simply read 
the whole manual from front to back.  I know I might not understand 
it all that way, BUT, I then at least know what it does, and what 
it does not do.  It is sort of like walking around a new house quickly.


You might not remember where everything is, but you mind keeps working 
even afterward, helping you fill things in.
Steeve
8-Mar-2010
[2912]
Yeah sort of Mental Health.

Even after all these years I still check the list of all words, regularly.
And I still make discoveries.
My last one ?
TRY/EXCEPT
PatrickP61
8-Mar-2010
[2913x5]
Hi all, I have a problem to figure out.


I have a special needs child that uses a talker device to speak for 
her.  It will log all of the words buttons she pushes to a file. 
 Problem is, the timestamp was not adjusted to the correct time and 
date, as a result each record with a timestamp is off by 6 years, 
3 months, 25 days, 6 hours and 17 minutes.  The format of the file 
is like this:

30th 6pm
*[YY-MM-DD=03-06-30]*
18:04:38 RECORD ON
22:55:13 CTL "Switch User Area from ..."
...
*[YY-MM-DD=03-07-01]*
06:19:12 CTL "..."
06:19:37 PAG "..."
...


As you can see, it is a simple text file that contains a header record 
for the date, and then each line has a time along with various info.

What I would like to do is this:

1.  Compute the offset time (to adjust the erroneous timestamp to 
the correct time)
2.  Go through the file record by record.

3.  When you find a date header record, "*[YY-MM-DD=" grab the erroneous 
date (pos 12-19 as yy-mm-dd), but do NOT write it out.

4.  When you find a time record (hh:mm:ss in pos 1-8), put the bad 
date and time together and then subtract the offset time from it 
to get the right date and time.

5.  If the right date has changed from the prior record, write out 
the corrected date header record.

6.  write out the corrected time record (replacing the wrong time 
with the right time)

7.  Any other records other than a date header or time trailer, just 
write out as is.
So far this is what I have:

Rebol []
pr:	:probe
	ts-wrong:		29-jun-2003/23:51:00
	ts-right:		04-feb-2010/06:08:00
pr	ts-diff:		difference ts-right ts-wrong
pr	cutoff-12pm:	ts-wrong/time - ts-right/time
pr	time-offset:	24:00 - cutoff-12pm
	log-recs: read/lines %Madison-log-100204-blk.txt
	new-recs:	[]
	foreach rec log-recs [
		fields:		parse rec none
		log-rec:	load fields
		if time? log-rec/1 [print log-rec/1]
		append new-recs rec
		append new-recs newline
	]
	write %Madison-new-100204-blk.txt new-recs
I havent figured out LOAD or PARSE just yet, nor the other part of 
capturing / changing the dates and times
I'm open to any comments or ways to better handle this problem
I'm thinking LOAD is not something I should use.  It is choking on 
records that don't conform to rebol datatypes
Steeve
8-Mar-2010
[2918]
>> to-date form reverse parse copy/part at "*[YY-MM-DD=03-06-30]*" 
12 8 "-"
== 30-Jun-2003
PatrickP61
8-Mar-2010
[2919x2]
Steeve,  should the last "-" be a "=" instead?
to-date form parse copy/part at "*[YY-MM-DD=03-06-30]*" 12 8 none 
 This gives the same results as above but the year is wrong 2030 
intead of 2003.
BrianH
8-Mar-2010
[2921x2]
Break it down:
>> at "*[YY-MM-DD=03-06-30]*" 12
== "03-06-30]*"
>> copy/part at "*[YY-MM-DD=03-06-30]*" 12 8
== "03-06-30"
>> parse copy/part at "*[YY-MM-DD=03-06-30]*" 12 8 "-"
== ["03" "06" "30"]
>> reverse parse copy/part at "*[YY-MM-DD=03-06-30]*" 12 8 "-"
== ["30" "06" "03"]

>> form reverse parse copy/part at "*[YY-MM-DD=03-06-30]*" 12 8 "-"
== "30 06 03"

That's as far as I got on R3; I don't have R2 yet on this computer.
TO-DATE is more strict in R3. Let me see if I can figure out something 
that will work there too.
PatrickP61
8-Mar-2010
[2923]
Steve's formula is really close, but I need some way to put "-" inbetween 
the yy mm dd
BrianH
8-Mar-2010
[2924]
>> to-date map-each x reverse parse head insert copy/part at "*[YY-MM-DD=03-06-30]*" 
12 8 "20" "-" [to-integer x]
== 30-Jun-2003

>> to-date replace/all form reverse parse copy/part at "*[YY-MM-DD=03-06-30]*" 
12 8 "-" " " "-"
== 30-Jun-2003
PatrickP61
8-Mar-2010
[2925]
Two solutions  -- Thanks!
BrianH
8-Mar-2010
[2926x2]
Be sure to break them down as above so you know what they're doing.
And profile them to see which is better:


>> dp [to-date map-each x reverse parse head insert copy/part at 
"*[YY-MM-DD=03-06-30]*" 12 8 "20" "-" [to-integer x]]
== make object! [
    timer: 0:00:00.000023
    evals: 43
    eval-natives: 14
    eval-functions: 5
    series-made: 11
    series-freed: 0
    series-expanded: 0
    series-bytes: 731
    series-recycled: 0
    made-blocks: 6
    made-objects: 0
    recycles: 0
]


>> dp [to-date replace/all form reverse parse copy/part at "*[YY-MM-DD=03-06-30]*" 
12 8 "-" " " "-"]
== make object! [
    timer: 0:00:00.00004
    evals: 103
    eval-natives: 30
    eval-functions: 5
    series-made: 8
    series-freed: 0
    series-expanded: 0
    series-bytes: 530
    series-recycled: 0
    made-blocks: 2
    made-objects: 0
    recycles: 0
]
PatrickP61
8-Mar-2010
[2928]
BrianH or Steve,   I have seen some example code showing the following:

x:	copy []
y:	[]

These are both equal right,  Why do one over the other?
BrianH
8-Mar-2010
[2929]
They are not equal. The first makes a copy, the second references 
the original.
PatrickP61
8-Mar-2010
[2930]
but the original is empty block.
BrianH
8-Mar-2010
[2931x2]
Right, but it is the specific empty block. If x is modified it won't 
change the original, but if y is modified it will.
This matters more in code in a function. That function might get 
called again.