[REBOL] to/make datatype!
From: joel::neely::fedex::com at: 16-Oct-2002 13:30
Hi, all,
Some conversions to/from STRING! work nicely (and in the obvious,
intuitive
fashion),
>> join "" 1 == "1"
>> to-string 1 == "1"
>> mold 1 == "1"
and
>> type? to-integer "1" == integer!
>> type? to-decimal "1" == decimal!
>> type? to integer! "1" == integer!
>> type? to decimal! "1" == decimal!
>> type? make integer! "1" == integer!
>> type? make decimal! "1" == decimal!
We can convert a DATATYPE! value to a STRING! value in different
ways, with slightly different results,
>> int-type: type? 1 == integer!
>> join "" int-type == "integer"
>> to-string int-type == "integer"
>> mold int-type == "integer!"
(note the presence/absence of the trailing bang), but the
corresponding transformations *don't* work then other way,
with no TO-xxx shortcut:
>> to-datatype int-type-name
** Script Error: to-datatype has no value
** Where: halt-view
** Near: to-datatype int-type-name
and no support from TO or MAKE either:
>> to datatype! int-type-name
** Script Error: Cannot use to on datatype! value
** Where: halt-view
** Near: to datatype! int-type-name
>> make datatype! int-type-name
** Script Error: Cannot use make on datatype! value
** Where: halt-view
** Near: make datatype! int-type-name
So far the most simplest way I've come up with to create a DATATYPE!
value from a STRING! value is
to-datatype: func [s [string!]] [
first reduce load rejoin [
"[" s either #"!" = last s ["]"] ["!]"]
]
]
>> type? to-datatype "string" == datatype!
>> make to-datatype "integer" "12" == 12
There's *got* to be a better way! Any suggestions?
-jn-
--
----------------------------------------------------------------------
Joel Neely joelDOTneelyATfedexDOTcom 901-263-4446