<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: type code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 08 Aug 2008 04:54:05 GMT</pubDate>
    <description>DZone Snippets: type code</description>
    <item>
      <title>DATATYPE-NAME?</title>
      <link>http://snippets.dzone.com/posts/show/3007</link>
      <description>&lt;code&gt;&lt;br /&gt;datatype-name?: func [val [string!]] [datatype? get/any load val]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 16 Nov 2006 05:08:31 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3007</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>CAST</title>
      <link>http://snippets.dzone.com/posts/show/3006</link>
      <description>&lt;code&gt;&lt;br /&gt;cast: func [value type] [to type value]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 16 Nov 2006 05:07:50 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3006</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>CAN-CAST?</title>
      <link>http://snippets.dzone.com/posts/show/3005</link>
      <description>&lt;code&gt;&lt;br /&gt;can-cast?: func [value type] [not error? try [to type value]]]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 16 Nov 2006 05:07:28 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3005</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <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>
    <item>
      <title>A dynamic form of the class statement.</title>
      <link>http://snippets.dzone.com/posts/show/1708</link>
      <description>These 2 methods are equivalent.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# method 1&lt;br /&gt;class X(object):&lt;br /&gt;    a = 1&lt;br /&gt;&lt;br /&gt;# method 2&lt;br /&gt;X = type('X', (object,), dict(a=1))&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 17 Mar 2006 20:21:27 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1708</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>isinstance and issubclass</title>
      <link>http://snippets.dzone.com/posts/show/1662</link>
      <description>&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; class P(object):  # parent class&lt;br /&gt;	pass&lt;br /&gt;&lt;br /&gt;&gt;&gt;&gt; class K(P):       # subclass&lt;br /&gt;	pass&lt;br /&gt;&lt;br /&gt;&gt;&gt;&gt; k = K()           # instace&lt;br /&gt;&gt;&gt;&gt; isinstance(k, K)&lt;br /&gt;True&lt;br /&gt;&gt;&gt;&gt; isinstance(k, P)&lt;br /&gt;True&lt;br /&gt;&gt;&gt;&gt; isinstance(K, P)  # K is a class&lt;br /&gt;False&lt;br /&gt;&lt;br /&gt;&gt;&gt;&gt; issubclass(K, P)&lt;br /&gt;True&lt;br /&gt;&gt;&gt;&gt; issubclass(k, P)  # k is not a class&lt;br /&gt;&lt;br /&gt;TypeError: issubclass() arg 1 must be a class&lt;br /&gt;&lt;br /&gt;&gt;&gt;&gt; isinstance(K, type)  # a class is an instace of type&lt;br /&gt;True&lt;br /&gt;&gt;&gt;&gt; isinstance(k, type)  # not a class&lt;br /&gt;False&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 09 Mar 2006 07:23:50 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1662</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>get line break type (mac, linux, win and binary file)</title>
      <link>http://snippets.dzone.com/posts/show/435</link>
      <description>this code analyses the first 5*1024 bytes of data from a file and tells which break type it uses, or if it's a binary file...&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;//+ Jonas Raoni Soares Silva&lt;br /&gt;//@ http://jsfromhell.com&lt;br /&gt;&lt;br /&gt;type&lt;br /&gt;  TBreakType = ( btNone, btWin, btMac, btLin, btBin );&lt;br /&gt;&lt;br /&gt;---------&lt;br /&gt;&lt;br /&gt;function GetBreakType( const Filename: string; const MaxDataToRead: Cardinal = 5*1024 ): TBreakType;&lt;br /&gt;var&lt;br /&gt;  FS: TFileStream;&lt;br /&gt;  Buffer, BufferStart, BufferEnd: PChar;&lt;br /&gt;begin&lt;br /&gt;  Result := btNone;&lt;br /&gt;  if not FileExists( Filename ) then&lt;br /&gt;    raise Exception.Create( 'GetBreakType: nome de arquivo inv&#225;lido' );&lt;br /&gt;  try&lt;br /&gt;    FS := TFileStream.Create( Filename, fmOpenRead );&lt;br /&gt;    GetMem( Buffer, MaxDataToRead+1 );&lt;br /&gt;    BufferEnd := ( Buffer + FS.Read( Buffer^, MaxDataToRead ) );&lt;br /&gt;    BufferStart := Buffer;&lt;br /&gt;    BufferEnd^ := #0;&lt;br /&gt;  except&lt;br /&gt;    raise Exception.Create( 'GetBreakType: erro alocando mem&#243;ria.' );&lt;br /&gt;  end;&lt;br /&gt;  try&lt;br /&gt;    while Buffer^ &lt;&gt; #0 do begin&lt;br /&gt;      if Result = btNone then&lt;br /&gt;        if Buffer^ = ASCII_CR then begin&lt;br /&gt;          if (Buffer+1)^ = ASCII_LF then begin&lt;br /&gt;            Result := btWin;&lt;br /&gt;            Inc( Buffer );&lt;br /&gt;          end&lt;br /&gt;          else&lt;br /&gt;            Result := btMac;&lt;br /&gt;        end&lt;br /&gt;        else if Buffer^ = ASCII_LF then&lt;br /&gt;          Result := btLin;&lt;br /&gt;      Inc( Buffer );&lt;br /&gt;    end;&lt;br /&gt;    if Buffer &lt;&gt; BufferEnd then&lt;br /&gt;      Result := btBin;&lt;br /&gt;  finally&lt;br /&gt;    FreeMem( BufferStart, MaxDataToRead+1 );&lt;br /&gt;    FS.Free;&lt;br /&gt;  end;&lt;br /&gt;end;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 02 Jul 2005 03:45:22 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/435</guid>
      <author>jonasraoni (Jonas Raoni Soares Silva)</author>
    </item>
  </channel>
</rss>
