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

World: r3wp

[Core] Discuss core issues

Bo
27-Mar-2006
[3832]
A pretty close estimate is the following: date2 - date1 / 365.25 
* 12
Jarod
27-Mar-2006
[3833x3]
interesting
difference
so that returns results in hours?
Bo
27-Mar-2006
[3836]
Difference returns the difference in hours.
Jarod
27-Mar-2006
[3837x2]
yeah, and I could continue converting that
hmm
Graham
27-Mar-2006
[3839]
>> ( difference now/date 1-Jan-2006 ) / 24:00 / 30
== 2.86666666666667
Jarod
27-Mar-2006
[3840x3]
still dividing by 30 isn't exactly accurate
all still very interesting, though
rebol still has better date management, than say perl for example
Bo
27-Mar-2006
[3843]
Over a period of time, dividing by 365.25 and multiplying by 12 is 
pretty accurate.
Izkata
27-Mar-2006
[3844]
365.24 is more accurate, though  ^.-
Bo
27-Mar-2006
[3845]
Thanks, Izkata.
Geomol
28-Mar-2006
[3846x3]
I start with 2 dates:
>> d1: now/date
== 28-Mar-2006
>> d2: 1-1-08
== 1-Jan-2008
To calculate the number of months between them:
>> months: (d2/year * 12 + d2/month) - (d1/year * 12 + d1/month)
== 22
>> if d1/day > d2/day [months: months - 1]
== 21
To calculate the number of remaining days:
>> d1/month: d1/month + months
== 24
>> d1
== 28-Dec-2007
>> d2 - d1
== 4


So there are 21 months and 4 days between the 2 dates (if I calculated 
right).
The situation with REBOL is, that you can do almost anything with 
it. If someone should document that, she could start now and not 
be finish, before she turned 100 years old. I saw myself as a very 
competent programmer with many years of experience in many different 
languages, before I discovered REBOL. It took me a year or so do 
'get' REBOL, because it's so different. I could very fast write simple 
things, but to get in under the skin of REBOL takes some time. In 
some way REBOL is a bit hard at first, and it takes some time to 
'get' it, then suddently it become very easy.
As a function:

monthdiff: func [d1 d2 /local months days] [
	months: (d2/year * 12 + d2/month) - (d1/year * 12 + d1/month)
	if d1/day > d2/day [months: months - 1]
	d1/month: d1/month + months
	days: d2 - d1
	reduce [months days]
]
Bo
28-Mar-2006
[3849]
Nice...
Gregg
28-Mar-2006
[3850x5]
Also, WRT language docs, there is the online dictionary and the Word 
Browser in Viewtop.
As far as what is included, this is tough because everybody coming 
to REBOL will want different things, and including all of it would 
make REBOL a complete mess. Is a substring function a good idea? 
Sure; I've written a lot of them. :-) I'm still working on a whole 
*bunch* of functions that might be useful, but they are hard to design 
well, so they are easy to use, flexible, and intuitive.
Fore example In the case of "substring", that's a bad name IMO, because 
you can use the same concept on any series, not just strings. Is 
"subseries" a good name? Does it read well? Not so much. It could 
mean different things to different people (e.g. are you looking for 
nested series values?). What about "extract", ah, that's used already, 
and what are the implied semantics if we do override it and add behavior? 
I like EXCERPT myself, but it's not a nice short word that's easy 
to guess if you're not sure what it might be called. Whatever the 
name, should there be a /REMOVE refinement, or should there be a 
separate function for that?


OK, so let's assume we have a good name now, how do you define the 
bounds? There is no range! or bounds! type in REBOL. Do you just 
use lower and upper bounds, or should it take an offset and length? 
Should we define a dialect for this? If so, how flexibile should 
it be? Can you get multiple "pieces" all at once? Can you handle 
2D extractions easily and clearly? Should you? Can you specify reverse 
extractions (e.g. from the tail)? Should it return the elements in 
reverse in that case, or should it throw an error if the lower bound 
is higher than the upper bound? etc.
So, you have to do this:
	COPY/PART AT xxx 5 10
instead of
	SUBSTRING xxx 5 14
	(or maybe SUBSTRING 5 10) 


Yeah, it's a few extra characters, but it's actually pretty expressive 
and clear.
And maybe someday we'll have one, who knows.
Pekr
28-Mar-2006
[3855]
substring is easy one ... give me easy 'pad oneliner :-)
Gregg
28-Mar-2006
[3856]
Sorry, mine is way more than a one-liner. :-)
Pekr
28-Mar-2006
[3857x2]
never mind ... it is just it makes me think each time I need it. 
The same goes for float conversion to number based, not that 1-E 
ble format ....
IIRC Carl had once some formatting functions in his mind, maybe those 
would be good to have included into Core at mezzanine level?
Gregg
28-Mar-2006
[3859x2]
I can give you mine, and I do have some one-liner versions around 
I think, but I assume you already have some, and are just talking 
about having a standard one.
I think FORMAT is on many lists. That's a *really* hard one to design 
though. So many ways it could go.
Sunanda
28-Mar-2006
[3861]
. [apologies for dotting, but I can see from rebol.net that I'm not 
synced in this group]
[unknown: 10]
28-Mar-2006
[3862x3]
What is the quickest routine  in rebol to compare 2 series of values 
based on position of the value against data of the value.. i.e. a: 
[ 1 2 3 4 5 ]  b:[ 5 6 7 8 9 ]
Mmm how do i exmaplain this correctly... ;-)
How do i check If a value in serie a does occeur in b on a specific 
position ? Currently im doing that with a foreach including a for 
loop..But somehow rebol should have something buildin i thought? 
or not.. unqiue intersect and difference are not good enough for 
this...and speed is a concern too..
DideC
28-Mar-2006
[3865x2]
an exemple?
an example?
Allen
28-Mar-2006
[3867]
Rebolinth: Need you to show an example with the expected results. 
Also are A and B of fixed length or varied?
Gregg
29-Mar-2006
[3868]
Use FIND + INDEX? maybe?
[unknown: 10]
29-Mar-2006
[3869x2]
yes well find and index where not what i searched for...ill drop 
an example...hold on a few hours ;-) back ltr...
...an example...


I build in lisp a latin-square example and rebuil it in rebol.. the 
bottle neck is not the random generator

but its for me the function called 'clean? (can this function be 
exchanged with a rebol buildin funtion? or
even be made smaler?)


; a latin square in rebol

random/seed now

clean?: func [ x /local bb i ][ 

 catch [ foreach bb b [for i 1 9 1 [ if = pick bb i pick x i [throw 
 false] true ]]]]

print "---- running ----"

T1: now/time/precise
insert/only b: copy [] random/seed [ 1 2 3 4 5 6 7 8 9 ]
print first b

while [ < length? b 9 ][  

 if clean? set 'x random [ 1 2 3 4 5 6 7 8 9 ] [ print x insert/only 
 b x ]]

print rejoin [ "Timed: " now/time/precise - T1 ]

wait 0:0:5
quit
Allen
29-Mar-2006
[3871]
As a general rule, try to use native! looping functions, they are 
faster. In the above the native! "repeat" could replace the use of 
"for"
[unknown: 10]
30-Mar-2006
[3872]
talking about speed improvement!! that 'for loop is very slow compaired 
to the 'repeat ;-) thanks..
DideC
30-Mar-2006
[3873]
; Try :
	source for
	source repeat
; and see !!!
Oldes
1-Apr-2006
[3874x2]
Is there someone using a Rebol script to send IF_MODIFIED_SINCE in 
HTTP get header?
ech, I forgot I can use read/custom to set the header easily:-)

read/custom page [header [If-Modified-Since: "Sat, 1 Apr 2006 14:42:13 
GMT"]]
Anton
1-Apr-2006
[3876]
:)
Thør
1-Apr-2006
[3877]
.
Thør
2-Apr-2006
[3878]
,
Anton
2-Apr-2006
[3879x2]
Greetings Thør.
Ok I have a question.


I would like to catch an error inside a function and throw it out 
so the error position is reported "near"

the function itself. As far as I understand we should do that with 
something like this:

check: func [

 [catch]  ; <-- function spec attribute flag which changes the reported 
 position of the error.
][
	load "http://("  ; <-- cause an error on purpose
]

Now I have tried various things:

>> check: func [][load "http://("]
>> check
** Syntax Error: Missing ) at end-of-script
** Near: (line 1) http://(

>> check: func [[catch]][load "http://("]
>> check
** Syntax Error: Missing ) at end-of-script
** Near: (line 1) http://(

>> check: func [[catch]][throw-on-error [load "http://("]]
>> check
** Syntax Error: Missing ) at end-of-script
** Near: 



But none of these seems to be reporting the "Near:" position that 
I'm expecting.

(Indeed, the last one looks kind of buggy reporting to me. Anyone?)
Volker
2-Apr-2006
[3881]
>> check: func [][throw-on-error[load "http://("]]
>> check
** Throw Error: ** Syntax Error: Missing ) at end-of-script
** Near: (line 1) http://(
>