Group,

  Just posted to http://www.rebol.org/utility/simple-math.r a little 
library that has some nifty increment (++) and decrement (--) 
functions to use.

  To give an idea what they do, below is a run through the values 
they work on. Only using ++ in the examples. The -- function works
exactly the same in reverse.

  Suggestions are more than welcome!

  Numbers:

rbl> num: 0
== 0
rbl> ++ num
== 1
rbl> ++ num
== 2

  Decimals:

rbl> dec: 0.1
== 0.1
rbl> ++ dec
== 1.1
rbl> ++ dec
== 2.1
rbl> ++/tenth dec
== 2.2
rbl> ++/tenth dec
== 2.3
rbl> ++/hundredth dec
== 2.31
rbl> ++/hundredth dec
== 2.32
rbl> ++/thousandth dec
== 2.321
rbl> ++/thousandth dec
== 2.322

  times:

rbl> time: 00:00
== 0:00
rbl> ++ time
== 0:00:01
rbl> ++ time
== 0:00:02
rbl> ++/tenth time
== 0:00:02.1
rbl> ++/tenth time
== 0:00:02.2
rbl> ++/hundredth time
== 0:00:02.21
rbl> ++/hundredth time
== 0:00:02.22
rbl> ++/thousandth time
== 0:00:02.221
rbl> ++/thousandth time
== 0:00:02.222

  Dates:

rbl> date: now/date
== 16-Feb-2000
rbl> ++ date
== 17-Feb-2000
rbl> ++ date
== 18-Feb-2000

  Moneys:

rbl> moneys: $0
== $0.00
rbl> ++ moneys
== $1.00
rbl> ++ moneys
== $2.00
rbl> ++/tenth moneys
== $2.10
rbl> ++/tenth moneys
== $2.20
rbl> ++/hundredth moneys
== $2.21
rbl> ++/hundredth moneys
== $2.22

  Characters:

rbl> char: #"A"
== #"A"
rbl> ++ char
== #"B"
rbl> ++ char
== #"C"

  Tuples:

rbl> tup: 0.0.0.0
== 0.0.0.0
rbl> ++ tup
== 1.1.1.1
rbl> ++ tup
== 2.2.2.2

  Any-string:

rbl> string: "abc"
== "abc"
rbl> ++ string
== "bc"
rbl> ++ string
== "c"

  Any-block:

rbl> blk: [a b c]
== [a b c]
rbl> ++ blk
== [b c]
rbl> ++ blk
== [c]

  Use the /PREV refinement to return the current value before 
incrementing or decremening:

rbl> count: 0
== 0
23:29:59 rbl> while [count <> 3] [print ++ count]
1
2
3
23:30:42 rbl> count: 0
== 0
23:30:48 rbl> while [count <> 3] [print ++/prev count]
0
1
2
rbl> blk: [a b c d]
== [a b c d]
rbl> while [(first blk) <> 'd] [probe ++ blk]
[b c d]
[c d]
[d]
rbl> blk: [a b c d]
== [a b c d]
rbl> while [(first blk) <> 'd] [probe ++/prev blk]
[a b c d]
[b c d]
[c d]

  There's a simple hex2decimal function in the library too.

  Enjoy!

  Cheerfulness,

                                        -----EAT

Reply via email to