<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: coerce code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 26 Jul 2008 20:12:01 GMT</pubDate>
    <description>DZone Snippets: coerce code</description>
    <item>
      <title>CAST function - Convert a value referenced by a word to a new datatype. Dialected</title>
      <link>http://snippets.dzone.com/posts/show/2098</link>
      <description>&lt;code&gt;&lt;br /&gt;    cast: func [ ; convert coerce&lt;br /&gt;        "Convert a value referenced by a word to a new datatype."&lt;br /&gt;        input [block!] "A word, and the target datatype."&lt;br /&gt;        /local words type val&lt;br /&gt;    ] [&lt;br /&gt;        parse input [&lt;br /&gt;            some [&lt;br /&gt;                copy words to 'to skip set type any-type! (&lt;br /&gt;                    ;while [pos: find words 'and] [remove pos]&lt;br /&gt;                    remove-each word words [word = 'and]&lt;br /&gt;                    foreach word words [&lt;br /&gt;                        val: get/any word&lt;br /&gt;                        set/any word to either word? type [get type] [type] val&lt;br /&gt;                    ]&lt;br /&gt;                )&lt;br /&gt;            ]&lt;br /&gt;        ]&lt;br /&gt;    ]&lt;br /&gt;    comment {&lt;br /&gt;        a: "A-0001"&lt;br /&gt;        b: #B002&lt;br /&gt;        c: 300&lt;br /&gt;        d: &lt;H1&gt;&lt;br /&gt;        e: 'test&lt;br /&gt;        cast [a to issue!]      print mold :a&lt;br /&gt;        cast [b to tag!]        print mold :b&lt;br /&gt;        cast [c to decimal!]    print mold :c&lt;br /&gt;        cast [a b c to string!] print remold [:a :b :c]&lt;br /&gt;        cast [a b and c to issue!] print remold [:a :b :c]&lt;br /&gt;        cast [&lt;br /&gt;            a b and c to tag!&lt;br /&gt;            and&lt;br /&gt;            d and e to issue!&lt;br /&gt;        ] print remold [:a :b :c :d :e]&lt;br /&gt;        cast [a b c to &lt;x&gt;  d e to "x"] print remold [:a :b :c :d :e]&lt;br /&gt;    } &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 25 May 2006 03:09:06 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2098</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
  </channel>
</rss>
