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

World: r3wp

[Core] Discuss core issues

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
Pekr
15-Oct-2005
[2317x3]
try this - found some arcane version, hopefully it will work ...
form-decimal: function [num][tmp main rest sign base][

     either found? find tmp: to-string num "E" [

              parse tmp [
                 copy main to "."
                 skip
                 copy rest to "E"
                 skip
                 mark: (sign: copy/part mark 1)
                 skip
                 copy base to end
               ]


        either sign = "-" [

                tmp: "0."

                loop ((to-integer base) - 1) [insert tail tmp "0"]
                insert tail tmp rest
        ][
                tmp: copy ""

                insert tail tmp join main rest

                loop ((to-integer base) - (length? rest)) [insert tail tmp "0"]  
                    
                           
        ] 
     
      tmp                 

     ][num] 

]
but please - take into account that my coding capabilities are, ehm, 
rather weak :-)
Geomol
15-Oct-2005
[2320]
:-) Ok, thanks Pekr!
Pekr
15-Oct-2005
[2321x7]
eh, does not seem to work ...
I will look into it and try to post correct version ...
Try this one:
form-decimal: func [num /local tmp main rest sign base][

     either found? find tmp: to-string num "E" [

              parse tmp [
                 [copy main to "." 
                  skip
                  copy rest to "E"
                  |
                  copy rest to "E"
                  (main: copy "")  
                  ]
             
                 skip
                 mark: (sign: copy/part mark 1)
                 skip
                 copy base to end
               ]


        either sign = "-" [

                tmp: copy "0."

                loop ((to-integer base) - 1) [insert tail tmp "0"]
                insert tail tmp rest
        ][
                tmp: copy ""

                insert tail tmp join main rest

                loop ((to-integer base) - (length? rest)) [insert tail tmp "0"]  
                    
                           
        ] 
     
      tmp                 

     ][num] 

]
first one did not take into account 1E-2, simply a version, where 
there is no "." in it ....
and I believe folks here will introduce just few lines version later 
:-)
On 6-October Volker posted this reply:


Pekr: "I did not find an easier way, so I parse for E, then I distinguish 
the sign, the number -5 in above case, and then I compose the string 
:-)"
!> a: 123.456 reduce[to integer! a remainder a 1]
== [123 0.456000000000003]

Maybe the base for something better (dont know how easy that parsing 
is?)
Volker
15-Oct-2005
[2328]
turned out to be http://polly.rebol.it/test/test/snippets/epad1.r
. longer and not so readable. but seems to work.
Geomol
15-Oct-2005
[2329x5]
I think, this version do the job:

form-decimal: func [n /local p d] [
	if p: find n #"E" [
		if d: remove find n #"." [d: index? d p: back p]
		if not d [if d: remove find n #"," [d: index? d p: back p]]
		if not d [d: 2]
		either p/2 = #"-" [
			insert/dup n #"0" (to-integer skip p 2) - 1
			insert n "0."
		][
			insert/dup p #"0" (to-integer next p) - (index? p) + d
		]
		clear find n #"E"
	]
	n
]
nope, not quite
This must be it:
form-decimal: func [n /local p d] [
	if p: find n #"E" [
		if d: remove find n #"." [d: index? d p: back p]
		if not d [if d: remove find n #"," [d: index? d p: back p]]
		if not d [d: index? p]
		either p/2 = #"-" [
			insert/dup n #"0" (to-integer skip p 2) - d + 1
			insert n "0."
		][
			insert/dup p #"0" (to-integer next p) - (index? p) + d
		]
		clear find n #"E"
	]
	n
]
Maybe there should be a
n: form n
in the beginning to support more datatypes.
Louis
15-Oct-2005
[2334]
Is there any way Rebol files can be made to be multi-user friendly?
Geomol
15-Oct-2005
[2335]
Louis, multi-user friendly!? What do you mean? That one user can 
lock a file for some time, so others can't access it? Or what?
Anton
16-Oct-2005
[2336x2]
Louis, in Core or View ? In View, you can read/write to the public 
cache.

This is VIEW-ROOT (the directory you selected during install, by 
default it is in a windows user profile directory).

When you click on an app from a rebsite, it is saved (by READ-THRU, 
PATH-THRU) into the public cache before running.
So, if it is your app, say at 
http://yoursite.com/app.r
then it could save prefs files to
path-thru http://yoursite.com/app-prefs.r
eg.
	save path-thru http://yoursite.com/app-prefs.r[my prefs data]
In Core, I define some of those useful functions from View (VIEW-ROOT, 
PATH-THRU etc..) in the user.r to allow the same functionality.
Louis
16-Oct-2005
[2338x2]
Geomol, I have written accounting software, and I would like for 
two or three people on a lan to be able to be intering data at once.
intering = entering
Henrik
16-Oct-2005
[2340x2]
Louis: I solved ths by having a separate Rebol task running that 
manages the file in question. It's a simple databaseserver that accepts 
requests from various clients on a LAN using Rugby. Performance is 
surprisingly good.
The database server manages the data and writes it to multiple copies 
of the database file in rotation (to avoid loss of data on write 
on power failure) every 10 seconds if there are requests from the 
clients.
Louis
16-Oct-2005
[2342x2]
Anton, I'm using encmdface from the SDK.  I am writing to an object 
database.
Henrik, so the data from different computers is sent to your dbserver 
which saves the records one at a time?
Henrik
16-Oct-2005
[2344]
basically yes
Louis
16-Oct-2005
[2345]
Sounds like what I am looking for.  Could you share the code?
Henrik
16-Oct-2005
[2346x2]
I could... but I'm going out the door in a few minutes so it's going 
to have to be later this evening.
advice: Learn Rugby :-)
Louis
16-Oct-2005
[2348x3]
Yes, I did play around with Rugby a while back, but could think of 
any way to use it at the time. Now I have a use.
cound not
could not
Geomol
16-Oct-2005
[2351]
Louis, I'm doing something similar as Henrik with a DB, I made in 
REBOL a couple of years ago. A REBOL task is listening on a TCP port 
and is handling the multiuser functionality. The clients could update 
the data in the DB themselves, or a task could do that too. My DB 
(NicomDB) isn't a product yet, but I could make it a product, if 
you're ready to pay for it?
Pekr
16-Oct-2005
[2352]
isn't it a bug that start: now wait 5 print (now - start) returns 
zero?