Comments on: A New Datatype: Typeset!
This article has been changed from its original posting. The
word "typemap" has been changed to "typeset".
In REBOL 3.0, a typeset is essentially a set of datatypes.
For example, when you define a function, you specify the datatypes of arguments in this way:
f: func [arg1 [integer! number!] arg2 [string! url!]] ...
What follows each arg word is a set of accepted datatypes.
REBOL 3.0 adds a new datatype called a typeset! A typeset is
simply a compact, high-performance method of storing the datatype sets
as a new kind of datatype. Typesets are important because the
interpreter uses them to quickly validate function arguments.
The typeset! datatype knows how to convert a block of datatype names
such as [integer! decimal! money!] into an internal representation
(similar to the bitset datatype). It can also convert the internal
format back to a block for output or changes.
The addition of typesets eliminates the need for the special REBOL
pseudo-datatypes like series! and number!. These are now
implemented as typesets, but you can use them the same way as before.
They can be used in function argument specifications:
f: func [arg1 [number!] arg2 [series!]] ...
and also for datatype tests:
if series? value [....]
Note, however, this difference. In REBOL 2.*:
in REBOL 3.0 becomes:
For advanced users, REBOL 3.0 will provide a way to create and manage
your own custom typesets.
tmp-type: make typeset! [time! money! percent!]
f: func [arg1 [tmp-type]] [...]
I will post more soon about a few issues related to typesets.
why call it a typemap when it really is a set rather than a map?|
I considered calling it a typeset, and that is still possible. It is a good question, and I will answer it in a blog.|
thanks for the quick response, carl! keep up the good work!|
I assume this will be of use not only for function generation, but also block parsing, and 'find operations amongst others.
Also, How would one set a typemap query, eg:
mytype: make typemap! [string! issue!]
Yes: on parsing and find.
On building of the query, it would require a constructor function such as:
mytype?: make-query mytype
(I would hope we could find a better name than make-query too.)
if not match? integer! 0.5 [..]
mytype?: matches mytype
something like that?|
Can typemap also handle ranges [integer! 0-9] ? And further restrictions on strings such as the maxlength? [string! min 0 max 20]
Very simple way to build in data validation
Post a Comment:
You can post a comment here. Keep it on-topic.