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.*:
type? series!
datatype!
in REBOL 3.0 becomes:
type? series!
typeset!
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.
7 Comments Comments:
Anonymous 9-Apr-2006 13:00 |
why call it a typemap when it really is a set rather than a map? | Carl Sassenrath 9-Apr-2006 13:11 |
I considered calling it a typeset, and that is still possible. It is a good question, and I will answer it in a blog. | Anonymous 9-Apr-2006 13:20 |
thanks for the quick response, carl! keep up the good work! | Chris 9-Apr-2006 13:20 |
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!]
mytype? "Foo"
mytype? #Foo | Carl Sassenrath 9-Apr-2006 14:40 |
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.) | Volker Nitsch 9-Apr-2006 18:24 |
:)
match?
if not match? integer! 0.5 [..]
or
mytype?: matches mytype
something like that? | Allen Kamp 10-Apr-2006 21:16 |
:)
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.
|