Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Types & runtime

From: carl:cybercraft at: 26-Aug-2002 0:52

On 25-Aug-02, Robert M. Muench wrote:
> Hi, can some help me with this: > list: [name string! birthday date!] > field: pick list 1 > type: pick list 2 >>> type? Type > == word! > What I want to do is to set field to a value of type 'type. > Something like: > switch type [ > string! [value: "test"] > ] > to-set-word field reduce[make to-type type value] > Is something like this possible? Robert
Indeed it is, as I've just found out... to-type: func [type [datatype!] value [any-type!]][ make type value ]
>> to-type string! [me--here--com]
== "[me--here--com]"
>> to-type string! 'hello
== "hello"
>> to-type integer! "999"
== 999 Converting a word in a block to the datatype! type is slightly tricky though...
>> blk: [string!]
== [string!]
>> type? blk/1
== word!
>> blk: reduce blk
== [string!]
>> type? blk/1
== datatype! So to do what you were attempting at the start...
>> list: [name string! birthday date!]
== [name string! birthday date!]
>> field: pick list 1
== name
>> type: first reduce reduce [pick list 2]
== string! That makes 'type a datatype!...
>> type? type
== datatype! so we can now use it in the above function...
>> to-type type field
== "name" HTH. -- Carl Read