[REBOL] Extended-Load was Percent! an new datatype! request
From: robbo1mark::aol::com at: 13-Jun-2002 11:39
further to my earlier post, here's a quick hack at source code
transformation which allows you to type "10%" in source and
REBOL sees a "percent!" object value / functions.
extended-load: func [source [string!] /local digits percent-rule val][
digits: charset [#"0" - #"9"]
percent-rule: [some digits 0 1 "." any digits 1 "%"]
source: parse source none
while [not tail? source] [if parse first source percent-rule [
val: to-decimal head remove at tail first source -1 remove source
insert source reform ["make-percent!" val]
] source: next source
]
load reform head source
]
percent!: context [ datatype: "percent!" value: 0 ]
make-percent!: func [ n [number!]] [ make percent! [value: n / 100] ]
some example usage;
>> extended-load "10%"
== [make-percent! 10
]
>> extended-load " print 5 * 10%"
== [print 5 * make-percent! 10 ]
Of course you would still have to extend everything else to interact
properly with the new percent! objects.
cheers,
Mark Dickson