Types & runtime
[1/7] from: robert:muench:robertmuench at: 25-Aug-2002 12:49
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
[2/7] from: gscottjones:mchsi at: 25-Aug-2002 7:31
From: "Robert M. Muench"
> Hi, can some help me with this:
> list: [name string! birthday date!]
<<quoted lines omitted: 9>>
> to-set-word field reduce[make to-type type value]
> Is something like this possible? Robert
Is this what you are looking for?
list: [name string! birthday date!]
foreach [field type] list [
switch type [
string! [value: "test"]
date! [value: "1-1-1"]
]
do reduce [to-set-word :field make do type value]
]
After execution, yielding:
>> name
== "test"
>> birthday
== 1-Jan-2001
Hope that helps.
--Scott Jones
[3/7] 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!]
<<quoted lines omitted: 9>>
> 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
[4/7] from: g:santilli:tiscalinet:it at: 25-Aug-2002 15:17
Hi Robert,
On Sunday, August 25, 2002, 12:49:15 PM, you wrote:
RMM> to-set-word field reduce[make to-type type value]
What about:
set field reduce [make get type value]
(Just out of curiosity, why having the value in a block?)
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r
[5/7] from: carl:cybercraft at: 26-Aug-2002 1:42
Ahem. (: As you would've worked out from Scott's post, a simple 'do
is enough to turn a word into type datatype! ...
>> list: [name string! birthday date!]
== [name string! birthday date!]
>> type: do pick list 2
== string!
>> type? type
== datatype!
Carl.
On 26-Aug-02, Carl Read wrote:
> On 25-Aug-02, Robert M. Muench wrote:
>> Hi, can some help me with this:
<<quoted lines omitted: 44>>
> == "name"
> HTH.
--
Carl Read
[6/7] from: robert:muench:robertmuench at: 25-Aug-2002 15:55
> -----Original Message-----
> From: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]]
> On Behalf Of Carl Read
> Sent: Sunday, August 25, 2002 2:53 PM
> To: [rebol-list--rebol--com]
> Subject: [REBOL] Re: Types & runtime
Hi, thanks a lot :-)) Great stuff! It's really tricky sometimes... And
if you got on the wrong track it's even harder to go back and think
again. Thanks again. Robert
[7/7] from: robert::muench::robertmuench::de at: 25-Aug-2002 15:58
> -----Original Message-----
> From: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]]
<<quoted lines omitted: 3>>
> Subject: [REBOL] Re: Types & runtime
> set field reduce [make get type value]
Hi, looks very elegant...
> (Just out of curiosity, why having the value in a block?)
Because it was hacked in quick & dirty ;-)? Robert
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted