[REBOL] Antwort: Re: [REBOL]
From: sharriff:aina:med-iq at: 25-Oct-2000 14:15
Great functions Erin! Thanks
Regards
Sharriff Aina
med.iq information & quality in healthcare AG
Gutenbergstr. 42
Erin Thomas
<[timewarp--sir] An: [rebol-list--rebol--com]
ius.com> Kopie:
Gesendet von: Thema: [REBOL] Re: [REBOL]
rebol-bounce@
rebol.com
25.10.00
12:33
Bitte
antworten an
rebol-list
I've found the attached REBOL library useful for things like
this. It's overkill if you just want to use it for dates, but
it can be used for a lot of other values.
Cheerfulness,
------EAT
[Sharriff--Aina--med-iq--de] wrote:
> Hi List!
>
> One cannot use the "+" or "-" operators on a Date! value, how does one
> increase or step through date! values then? I´m trying to construct a
> graphical calender.
>
> Best regards
>
> Sharriff Aina
> med.iq information & quality in healthcare AG
>
> --
> To unsubscribe from this list, please send an email to
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
-- Attached file included as plaintext by Listar --
-- File: word-gradation.r
REBOL [
Title: "Increment and Decrement (++) and (--) Functions"
File: %word-gradation.r
Author: "EAT"
Date: 16-Feb-2000
Purpose: {Provide polymorphic ++ and -- gradation functions.}
Usage: {
Increment or decrement the value of a word by using the word
as the argument to ++ or --.
Examples:
int: 1
probe ++ int
block: [a b c d e f g]
probe ++ block
money: $1.00
++ money
time: 11:11:11
--/skip time (60 * 60) ; hourly decrement
}
Category: [util 3]
]
increment: func [
"increment a value by one"
val [number! time! date! money! char! tuple! pair! series! port!]
"value to increment"
/prev "return value before incrementing"
/skip n [number!] "amount to skip per iteration"
][
jump: get bind 'skip 'rebol
if not skip [n: 1]
either any [port? val series? val] [jump val to-integer n][val + n]
]
decrement: func [
"decrement a value by one"
val [number! time! date! money! char! tuple! pair! series! port!]
"value to decrement"
/prev "return value before decrementing"
/skip n [number!] "amount to skip per iteration"
][
jump: get bind 'skip 'rebol
if not skip [n: 1]
either any [port? val series? val] [jump val negate to-integer n][val -
n]
]
decimal-increment: func [
"increment decimal, money, or time value (default is by one tenth)"
val [decimal! time! money!] "decimal, money, or time value"
/prev "return value before incrementing"
/hundredth "increment by one hundredth"
/thousandth "increment by one thousandth"
][
if hundredth [return val + 0.01]
if thousandth [return val + 0.001]
val + 0.1
]
decimal-decrement: func [
"decrement decimal, money, or time value (default is by one tenth)"
val [decimal! time! money!] "decimal, money, or time value"
/prev "return value before decrementing"
/hundredth "decrement by one hundredth"
/thousandth "decrement by one thousandth"
][
if hundredth [return val - 0.01]
if thousandth [return val - 0.001]
val - 0.1
]
++: func [
"set word referenced by 'word to an incremented value"
'word [word!]
"supports number! time! date! money! char! tuple! pair! series! port!"
/prev "return value before incrementing"
/skip n [number!] "amount to skip each iteration - rounds n with
series"
/tenth "supports decimal! time! money! - ignores /skip"
/hundredth "supports decimal! time! money! - ignores /skip"
/thousandth "supports decimal! time! money! - ignores /skip"
/local v
] [
if not any [
if tenth [set word decimal-increment v: get word]
if hundredth [set word decimal-increment/hundredth v: get word]
if thousandth [set word decimal-increment/thousandth v: get word]
] [
set word either skip [
increment/skip v: get word n][increment v: get word]
]
either prev [return v] [return get word]
]
--: func [
"set word referenced by 'word to a decremented value"
'word [word!]
"supports number! time! date! money! char! tuple! pair! series! port!"
/prev "return value before decrementing"
/skip n [number!] "about to skip each iteration - rounds n with series"
/tenth "supports decimal! time! - ignores /skip"
/hundredth "supports decimal! time! - ignores /skip"
/thousandth "supports decimal! time! - ignores /skip"
/local v
] [
if not any [
if tenth [set word decimal-decrement v: get word]
if hundredth [set word decimal-decrement/hundredth v: get word]
if thousandth [set word decimal-decrement/thousandth v: get word]
] [
set word either skip [
decrement/skip v: get word n][decrement v: get word]
]
either prev [return v] [return get word]
]