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

World: r3wp

[Core] Discuss core issues

Volker
6-Oct-2005
[2267x2]
ncie, rebol indexes our index.r's :) and word-browser was great to 
find "remainder".
short enough? http://polly.rebol.it/test/test/snippets/epad1.r
Sunanda
6-Oct-2005
[2269]
Looks good, Volker.
One problem: more than 9 leading zeroes:
 epad1 0 10 0
** Math Error: Math or number overflow

(There is a much larger limit on trailing zeroes after the decimal 
sign)
Volker
6-Oct-2005
[2270]
tricky. hmm, money should have a bigger scope?
Sunanda
6-Oct-2005
[2271]
Nine *should* be enough for most people -- I didn't have a specific 
case in mind. I was just testing the limits.
Volker
6-Oct-2005
[2272x2]
testing is good :)
Yep, money is worth its -erm, punning here.. adds more digits. (uploaded)
Sunanda
6-Oct-2005
[2274]
14 leading zeroes is probably enough for anyone :-)
One bug?
 epad1 0.09 1 2
== "0.90"   ;; 10 times too large!
Volker
6-Oct-2005
[2275x2]
thanks. will look at that.
forgot to pad remainder to. so 0.09 * 100 -> 9 . should be 09 so 
that appending 0s works. but got another bug-description on linux. 
there it is fixed.
Benjamin
9-Oct-2005
[2277]
i need to make a function wich can take n optional arguments, n can 
be from 1 to many arguments any help
Graham
9-Oct-2005
[2278x2]
I think Ladislav has done some work on this.
Otherwise supply it as a block :)
Benjamin
9-Oct-2005
[2280]
i whas thinking about the block option it seems more acurrate
Ladislav
9-Oct-2005
[2281]
supply it as a block
 is the proper solution I think
Pekr
11-Oct-2005
[2282]
btw - what you think of following? - normally we can access paths 
in several ways ... block/5 (fifth element), block/literal (literal 
element), block/(expression) (expressionn to evaluate). Nonexistant 
elements do return 'none. But try block/("some string") - it returns 
error. Now the question is, if this is correct/consistent with other 
ways of how we access block elements, or not?
RebolJohn
11-Oct-2005
[2283]
Question: <Unix Time>..   I found several functions on the web that 
show you how to create a unix-timestamp from a rebol time (now). 
 However, I am looking for the ability to convert a unix-timestamp 
back into rebol-time.  I started writing my own function but I think 
that leap-years might mess me up.  Anyone have any thought on the 
matter?
Volker
11-Oct-2005
[2284x2]
!> now + to-time 1e6
== 23-Oct-2005/13:26:16+2:00
i guess you can refine that for conversion. a unix-timestamp is an 
integer based on some date?
RebolJohn
11-Oct-2005
[2286]
1/1/1970 0:00:00
Volker
11-Oct-2005
[2287]
an then 32 bits for miliseconds or something like this?
RebolJohn
11-Oct-2005
[2288x3]
The unix-timestamp could be any date/time.. so I think I have to 
work top down.. first find the year then month, day, hour, min, sec. 
    Kind of like building a binary number from a decimal.. top-down.
Precision (ms) is used/not used depending on the OS / config.
I have some MRTG/RRDTool files that I am parsing for certain data 
and they all use the unix-timestamp format (not including ms)
Volker
11-Oct-2005
[2291]
i thought it is just an integer. So it is more complicated build, 
with year, month etc?
RebolJohn
11-Oct-2005
[2292]
Yeah.  the date -> unixTime function from someone else (maybe Gabrielle) 
is..
to-unix-time: func [date] [
  date/date - 1-1-1970 * 86400 + to-integer date/time
]
Volker
11-Oct-2005
[2293]
then you could reverse that. as my example shows, you can add times 
to dates. i think it works also in that large range.
RebolJohn
11-Oct-2005
[2294x3]
Yeah.  My problem (I think) is accounting for leap years and the 
different lengths of months.
Little casio watches know all of this info (Year/month/day/time). 
 I suspect it is in a static table inside the watch.  I have been 
looking for something like this on the web.
I could easily build a table for month lengths.. it is the leap-year 
that I just don't want to think about.
Volker
11-Oct-2005
[2297x3]
That should be inbuild. i guess rebol stores internally just a big 
integer too.
you could try
  1-1-1970 + unix-seconds
and see what happens.
1-1-1970 + to-time unix-seconds
RebolJohn
11-Oct-2005
[2300]
You might be on to something.. I did unix time (now) and it returned 
24-Dec-13007.  However, maybe I need to subtract not add.  I will 
play with this SIMPLE solution.  (I always try to look at it harder 
than it probably needs to be).  Thanks.
Izkata
11-Oct-2005
[2301]
>> 1-Jan-1970/0:0:0 + to-time to-unix-time 15-Apr-2006/15:41:0
== 15-Apr-2006/15:41

Looks like the time just needs to be inlcuded...
Benjamin
12-Oct-2005
[2302]
i've this function: f: [variable] [variable: 100]
variable: 10
f variable
== 100
variable
== 10

the question is 1 why do i never noticed this :) and second how do 
i pass values by reference
Graham
12-Oct-2005
[2303]
You're not talking about this ?

 f: func ['word][ set word 10 ]
Sunanda
12-Oct-2005
[2304]
This might do it -- change the way you define f:
 use [variable] [f: [variable] [variable: 100]]
variable: 10
== 10
f variable
== 10
variable
== 10
Benjamin
12-Oct-2005
[2305]
note: "variable" is a global value still i get no results from this 
:(
Graham
12-Oct-2005
[2306]
>> f: func ['variable][ set variable 100 ]
>> variable: 10
== 10
>> f variable
== 100
>> variable
== 100
Benjamin
12-Oct-2005
[2307]
thanks graham it worked well
Volker
12-Oct-2005
[2308]
I rarely change values by reference, only series/objects. values 
i simply assign new.
 f: func[variable][100]
 variable: variable 100
If not, i at least mark the word, like
 f: func[variable][ set variable 100]
 f 'variable

Its style, but in rebol i rarely see a function changes a word, so 
i am avoiding to be surprised.
RebolJohn
12-Oct-2005
[2309]
O.K.
Thanks to everyone for their help.

I offer my final (not that it's the best) rendition of these conversion 
functions.


to-unix-time: func [
  "Create unix-timestamp.  Author: Gabriele_3-Aug-2002."
  date [date!] "Rebol-format date. (non-Milisecond type)."
][
  date/date - 1-1-1970 * 86400 + to-integer date/time
]

from-unix-time: func [

  "Create rebol-timestamp from unix-timestamp.  Author: Rebolers-Altme_2005."
  utime [integer!] "Unix timestamp."
][
  unixTimestampConstant + to-time utime
]  

-- OR an all-in-one --

unixTimestamp: func [

  "Rebol date to/from unix timestamp conversion.  Authors: Many rebolers.."

  varIn "Enter either a Date!type or Integer!type to convert to/from 
  unix/rebol."
][

   unixTimestampConstant: 1970-01-01/00:00:00           ;Reference.
   varOut: "ERR"

   if ((type? varIn) = date!) [                         ;from rebol, 
   to unix.

     varOut: varIn/date - 1-1-1970 * 86400 + to-integer varIn/time
   ]

   if ((type? varIn) = integer!) [                      ;from unix to 
   rebol.

     if (varIn >= 0) [                                  ;B.U.  (before 
     Unix.)
       varOut: unixTimestampConstant + to-time utime
     ]
   ]
   return varOut
]

John.
Gabriele
12-Oct-2005
[2310]
>> difference now 1-1-1970
== 313646:34:14
>> to integer! difference now 1-1-1970
== 1129127658
RebolJohn
12-Oct-2005
[2311]
BIG TYPO on the last post.. 

unixTimestamp: func [

  "Rebol date to/from unix timestamp conversion.  Authors: Many rebolers.."

  varIn "Enter either a Date!type or Integer!type to convert to/from 
  unix/rebol."
][

   unixTimestampConstant: 1970-01-01/00:00:00           ;Reference.
   varOut: "ERR"

   if ((type? varIn) = date!) [                         ;from rebol, 
   to unix.

     varOut: varIn/date - 1-1-1970 * 86400 + to-integer varIn/time
   ]

   if ((type? varIn) = integer!) [                      ;from unix to 
   rebol.

     if (varIn >= 0) [                                  ;B.U.  (before 
     Unix.)
       varOut: unixTimestampConstant + to-time varIn
     ]
   ]
   return varOut
]

John.
BIG TYPO on the last post.. 

unixTimestamp: func [

  "Rebol date to/from unix timestamp conversion.  Authors: Many rebolers.."

  varIn "Enter either a Date!type or Integer!type to convert to/from 
  unix/rebol."
][

   unixTimestampConstant: 1970-01-01/00:00:00           ;Reference.
   varOut: "ERR"

   if ((type? varIn) = date!) [                         ;from rebol, 
   to unix.

     varOut: varIn/date - 1-1-1970 * 86400 + to-integer varIn/time
   ]

   if ((type? varIn) = integer!) [                      ;from unix to 
   rebol.

     if (varIn >= 0) [                                  ;B.U.  (before 
     Unix.)
       varOut: unixTimestampConstant + to-time varIn
     ]
   ]
   return varOut
]

John.
Geomol
15-Oct-2005
[2312]
Is there a way to have small decimal numbers shown, as you write 
them, when converted to a string? Instead of this:
>> to-string 0.08
== "8E-2"
I would like the output to be "0.08".
Pekr
15-Oct-2005
[2313x3]
:-)) last week or so there was rather long discussion here :-)
I have form-decimal function for that, but others might have posted 
other solutions ...
wait a bit - will look into my flash disk if I have it here, otherwise 
I have it at my work on my PC ...
Geomol
15-Oct-2005
[2316]
ok