World: r3wp
[Core] Discuss core issues
older newer | first last |
Graham 27-Mar-2006 [3801] | Jarod - yes. |
Jarod 27-Mar-2006 [3802] | I like that function a bit more Graham, I basically think I understand what that is doig |
Graham 27-Mar-2006 [3803] | the ".." is synatactic sugar. |
Jarod 27-Mar-2006 [3804x4] | doing |
having to write a function to do that is a pain, but I can probably live with it, knowing exactly what it is doing | |
I mean, all languages have quirks | |
hehe | |
Graham 27-Mar-2006 [3808] | I don't use substr much at all either .. but your complaint was one I also felt :) |
Jarod 27-Mar-2006 [3809x4] | I mean, there are times when parse will work |
but honestly, I could actually see parse having the ability to substring | |
I am surprised it doesn't | |
how can you do more with dates than just add days to them? | |
Bo 27-Mar-2006 [3813] | So why doesn't someone write a .r file you can run that adds common functions for other languages (i.e. basic.r would have 'substr, |
Jarod 27-Mar-2006 [3814] | I guess there are several ways it could be implemented |
Graham 27-Mar-2006 [3815] | user.r ? |
Jarod 27-Mar-2006 [3816] | putting it in user.r? |
Bo 27-Mar-2006 [3817] | Someone (or a group of someones) should write a .r file for the common languages (i.e. basic.r would include 'substr, 'peek, 'poke, etc.; rexx.r would include 'mid, etc.). That way, new users from other languages could move into Rebol with the knowledge they already have. Of course, the script flow would be different, but their favorite functions would be available, and they could see how to implement their favorite functions natively using 'source. There could also be a %c.r for those coming straight from C. :-) |
Graham 27-Mar-2006 [3818] | and things like .. cd, dir and other common dos functions |
Bo 27-Mar-2006 [3819x4] | Ah, but to implement dos.r, you would have to remove about 90% of Rebol's functionality ;-) |
Just kidding...I was being mean about how bad DOS really is as a scripting language. :-) | |
Jarod...I guess you are asking about how to add to dates. Here is an example: | |
>> b: now/date == 27-Mar-2006 >> b/month: b/month + 6 == 9 >> b == 27-Sep-2006 | |
Jarod 27-Mar-2006 [3823x2] | that adds months, what about weeks? |
hmm | |
Bo 27-Mar-2006 [3825] | >> week: 7 ;Defining a "constant" here == 7 >> b/date: b/date + (6 * week) == 8-Nov-2006 |
Jarod 27-Mar-2006 [3826] | hmm |
Bo 27-Mar-2006 [3827x2] | I guess I didn't need to use 'b/date, just 'b would have worked. |
>> b: b + (6 * week) == 8-Nov-2006 | |
Jarod 27-Mar-2006 [3829x2] | yeah, but I mean, let's say I took two dates, and I wanted to know the number of months between them, the date/month thing doesn't work |
maybe if I take the number of days and divide by 12 | |
Graham 27-Mar-2006 [3831] | use 'difference to get the difference between two dates |
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 [3850] | Also, WRT language docs, there is the online dictionary and the Word Browser in Viewtop. |
older newer | first last |