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

World: r3wp

[Rebol School] Rebol School

Henrik
20-Oct-2009
[2859]
you were first, because it took 3 minutes to swap into textmate. 
:-) have too many things running here.
CharlesW
20-Oct-2009
[2860]
Thank guys.
Graham
1-Jan-2010
[2861x4]
The Rebol School site is now working again after 4 years of malfunctions.
Andreas helped me today to debug the vanilla issue that was causing 
a server error for most pages ...
http://www.compkarori.com/vanilla/
Basically the data about the user Graham was set to a zero byte file 
when my site was hacked .. and vanilla looks at the user file when 
it displays a snip authored  by that user.  It was unable to load 
this data causing an error, and since I authored many of the snips, 
it caused most of the site to go down.
PatrickP61
7-Mar-2010
[2865x5]
Question:  I'd like to define a function that essentially prints 
out a stored message like this:
debug?: on
debug: func [a] [print a]
but I want it to print only when debug? is on.  Since debug? is outside 
of the function, how can I define it so that it checks this value 
before printing a
debug: funct [a] [if debug? print a]
Steeve
7-Mar-2010
[2870x2]
Kidding ?
debug: funct [a] [if debug? [print a]]
PatrickP61
7-Mar-2010
[2872]
Hi Steeve, it doesnt work.  If debug? is on or off, it still prints 
a
Steeve
7-Mar-2010
[2873]
hmm...
PatrickP61
7-Mar-2010
[2874x2]
oops I made a mistake
Sorry steve,  You were right, I did a typo on my test.  Thank you
BrianH
7-Mar-2010
[2876]
And you don't need funct here because there are no locals (though 
it's a cool function) :)
PatrickP61
7-Mar-2010
[2877]
So the main difference between FUNC and FUNCT is that variables outside 
of the function can be referenced ... right?
Steeve
7-Mar-2010
[2878x2]
not exactly
funct "Defines a function with all set-words as locals"
Henrik
7-Mar-2010
[2880]
so you don't have to write func [/local blahblah]...
PatrickP61
7-Mar-2010
[2881]
to clarify, locals is all variables that is local to the main script, 
 outside of the function.  Is that a good way to describe it?
Steeve
7-Mar-2010
[2882x2]
no :)
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?