<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: dialect code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 16 May 2008 02:29:11 GMT</pubDate>
    <description>DZone Snippets: dialect code</description>
    <item>
      <title>SET+</title>
      <link>http://snippets.dzone.com/posts/show/2116</link>
      <description>&lt;code&gt;&lt;br /&gt;    set+: func [ ; Inspired by Erlang's list model.&lt;br /&gt;        "Like SET, but words block is dialected."&lt;br /&gt;        words  [any-block!] "Word after | gets remainder of series."&lt;br /&gt;        series [series!]&lt;br /&gt;        /local word= rule=&lt;br /&gt;    ][&lt;br /&gt;        word=: [set word word!]&lt;br /&gt;        rule=: [&lt;br /&gt;            any [&lt;br /&gt;                '| word= (set word series) to end&lt;br /&gt;                | word= (&lt;br /&gt;                    set word pick series 1&lt;br /&gt;                    series: next series&lt;br /&gt;                )&lt;br /&gt;            ]&lt;br /&gt;        ]&lt;br /&gt;        parse words rule=&lt;br /&gt;    ]&lt;br /&gt;    ;set+ [a | rest] [1 2 3 4 5]&lt;br /&gt;    ;set+ [a b | rest] [1 2 3 4 5]&lt;br /&gt;    ;set+ [a b c] [1 2]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 29 May 2006 22:35:02 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2116</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>file-size-comparison-ctx - find files matching size criteria; dialected interface</title>
      <link>http://snippets.dzone.com/posts/show/2091</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;file-size-comparison-ctx: context [&lt;br /&gt;    =negate-op?: none&lt;br /&gt;    =or-equal?: none&lt;br /&gt;    =op: none&lt;br /&gt;    =size: 0&lt;br /&gt;    =size-mul: 1&lt;br /&gt;    =parse-end-mark: none&lt;br /&gt;&lt;br /&gt;    make-lit-word: func [val] [to lit-word! :val]&lt;br /&gt;    lit-lesser: make-lit-word "&lt;"&lt;br /&gt;    lit-greater: make-lit-word "&gt;"&lt;br /&gt;    lit-lesser-or-equal: make-lit-word "&lt;="&lt;br /&gt;    lit-greater-or-equal: make-lit-word "&gt;="&lt;br /&gt;&lt;br /&gt;    size=: [&lt;br /&gt;        (=size-mul: 1)&lt;br /&gt;        set =size number!&lt;br /&gt;        opt [&lt;br /&gt;            'bytes ; no change to size-mul&lt;br /&gt;            | ['kilobytes | 'KB] (=size-mul: 1024.0)&lt;br /&gt;            | ['megabytes | 'MB] (=size-mul: 1048576.0)&lt;br /&gt;            | ['gigabytes | 'GB] (=size-mul: 1073741824.0)&lt;br /&gt;        ]&lt;br /&gt;        (=size: =size * =size-mul)&lt;br /&gt;    ]&lt;br /&gt;    word-comparison=: [&lt;br /&gt;        [&lt;br /&gt;            ['more | 'bigger | 'larger | 'greater] (=op: 'greater)&lt;br /&gt;            | ['less | 'smaller] (=op: 'lesser)&lt;br /&gt;        ] 'than&lt;br /&gt;        opt ['or 'equal 'to (=or-equal?: true)]&lt;br /&gt;    ]&lt;br /&gt;    lit-comparison=: [&lt;br /&gt;        lit-lesser             (=or-equal?: false  =op: 'lesser)&lt;br /&gt;        | lit-greater          (=or-equal?: false  =op: 'greater)&lt;br /&gt;        | lit-lesser-or-equal  (=or-equal?: true   =op: 'lesser)&lt;br /&gt;        | lit-greater-or-equal (=or-equal?: true   =op: 'greater)&lt;br /&gt;    ]&lt;br /&gt;    rules=: [&lt;br /&gt;        (=negate-op?: =or-equal?: =op: =parse-end-mark: none)&lt;br /&gt;        opt 'if opt ['size | size?]&lt;br /&gt;        opt [['no | 'not] (=negate-op?: true)]&lt;br /&gt;        [word-comparison= | lit-comparison=]&lt;br /&gt;        (if =negate-op? [=op: pick [greater lesser] =op = 'lesser])&lt;br /&gt;        (=op: to word! rejoin [=op either =or-equal? ['-or-equal] [""] '?])&lt;br /&gt;        size=&lt;br /&gt;        =parse-end-mark:&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;    set 'size-comparison-cmd? func [input [block!]] [&lt;br /&gt;        parse input rules=&lt;br /&gt;        return =parse-end-mark&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;    set 'make-file-size-comparison-func func [spec] [&lt;br /&gt;        parse spec rules=&lt;br /&gt;        either =parse-end-mark [&lt;br /&gt;            func [file] reduce [=op 'size? 'file =size]&lt;br /&gt;        ] [none]&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;    set 'files-matching-size-spec func [&lt;br /&gt;        files [block!]&lt;br /&gt;        spec [block!]&lt;br /&gt;    ][&lt;br /&gt;        if match?: make-file-size-comparison-func spec [&lt;br /&gt;            collect 'keep [&lt;br /&gt;                foreach file files [if match? file [keep: file]]&lt;br /&gt;            ]&lt;br /&gt;        ]&lt;br /&gt;    ]&lt;br /&gt;]&lt;br /&gt;;foreach file files-matching-size-spec read %. [&gt;= 64 kb] [print [file size? file]]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 23 May 2006 21:43:57 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2091</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>file-date-comparison-ctx - find files matching date criteria; dialected interface</title>
      <link>http://snippets.dzone.com/posts/show/2090</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;file-date-comparison-ctx: context [&lt;br /&gt;    =negate-op?: none&lt;br /&gt;    =or-equal?: none&lt;br /&gt;    =op: none&lt;br /&gt;    =parse-end-mark: none&lt;br /&gt;    =attr: 'modification-date&lt;br /&gt;    =date: none&lt;br /&gt;&lt;br /&gt;    make-lit-word: func [val] [to lit-word! :val]&lt;br /&gt;    lit-equal: make-lit-word "="&lt;br /&gt;    lit-lesser: make-lit-word "&lt;"&lt;br /&gt;    lit-greater: make-lit-word "&gt;"&lt;br /&gt;    lit-lesser-or-equal: make-lit-word "&lt;="&lt;br /&gt;    lit-greater-or-equal: make-lit-word "&gt;="&lt;br /&gt;&lt;br /&gt;    attr=: [&lt;br /&gt;        ['changed | 'modified | 'upated | 'modification-date]&lt;br /&gt;        | ['created | 'creation-date | 'create-date] (=attr: 'creation-date)&lt;br /&gt;        | ['accessed | 'access-date] (=attr: 'access-date)&lt;br /&gt;    ]&lt;br /&gt;    date=: [&lt;br /&gt;        [&lt;br /&gt;            set =date date!&lt;br /&gt;            | set =date file!      (=date: get-modes =date =attr)&lt;br /&gt;            | 'yesterday (=date: now/date - 1)&lt;br /&gt;            | 'today     (=date: now/date)&lt;br /&gt;            | 'tomorrow  (=date: now/date + 1)&lt;br /&gt;        ]&lt;br /&gt;    ]&lt;br /&gt;    word-comparison=: [&lt;br /&gt;        [&lt;br /&gt;            ['after | 'since | 'newer 'than] (=op: 'greater)&lt;br /&gt;            | ['before | 'older 'than] (=op: 'lesser)&lt;br /&gt;        ]&lt;br /&gt;        opt ['or 'equal 'to (=or-equal?: true)]&lt;br /&gt;    ]&lt;br /&gt;    lit-comparison=: [&lt;br /&gt;        lit-equal              (=or-equal?: false  =op: 'equal)&lt;br /&gt;        | lit-lesser           (=or-equal?: false  =op: 'lesser)&lt;br /&gt;        | lit-greater          (=or-equal?: false  =op: 'greater)&lt;br /&gt;        | lit-lesser-or-equal  (=or-equal?: true   =op: 'lesser)&lt;br /&gt;        | lit-greater-or-equal (=or-equal?: true   =op: 'greater)&lt;br /&gt;    ]&lt;br /&gt;    rules=: [&lt;br /&gt;        (&lt;br /&gt;            =negate-op?: =or-equal?: =op: =parse-end-mark: =date: none&lt;br /&gt;            =attr: 'modification-date&lt;br /&gt;        )&lt;br /&gt;        opt 'if opt ['date | 'date?]&lt;br /&gt;        opt [['no | 'not] (=negate-op?: true)]&lt;br /&gt;        opt ['date | 'date?]&lt;br /&gt;        opt attr=&lt;br /&gt;        [word-comparison= | lit-comparison=]&lt;br /&gt;        (if =negate-op? [=op: pick [greater lesser] =op = 'lesser])&lt;br /&gt;        (=op: to word! rejoin [=op either =or-equal? ['-or-equal] [""] '?])&lt;br /&gt;        date=&lt;br /&gt;        =parse-end-mark:&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;    set 'date-comparison-cmd? func [input [block!]] [&lt;br /&gt;        parse input rules=&lt;br /&gt;        return =parse-end-mark&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;    set 'make-file-date-comparison-func func [spec] [&lt;br /&gt;        parse spec rules=&lt;br /&gt;        either =parse-end-mark [&lt;br /&gt;            func [file] reduce [=op  'get-modes 'file to lit-word! =attr  =date]&lt;br /&gt;        ] [none]&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;    set 'files-matching-date-spec func [&lt;br /&gt;        files [block!]&lt;br /&gt;        spec [block!]&lt;br /&gt;    ][&lt;br /&gt;        if match?: make-file-date-comparison-func spec [&lt;br /&gt;            collect 'keep [&lt;br /&gt;                foreach file files [if match? file [keep: file]]&lt;br /&gt;            ]&lt;br /&gt;        ]&lt;br /&gt;    ]&lt;br /&gt;]&lt;br /&gt;;foreach file files-matching-date-spec read %. [accessed after 1-jan-2006] [print [file modified? file]]&lt;br /&gt;;foreach file files-matching-date-spec read %. [date &lt; 1-jan-2006] [print [file modified? file]]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 23 May 2006 21:42:36 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2090</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>Parse multiple, independently fixed length, integer values from a string</title>
      <link>http://snippets.dzone.com/posts/show/1494</link>
      <description>&lt;code&gt;&lt;br /&gt;parse-int-values: func [&lt;br /&gt;    "Parses and returns integer values, each &lt;n&gt; chars long in a string."&lt;br /&gt;    input [any-string!]&lt;br /&gt;    spec [block!] "Dialected block of commands: &lt;n&gt;, skip &lt;n&gt;, done, char, or string"&lt;br /&gt;    /local&lt;br /&gt;        gen'd-rules ; generated rules&lt;br /&gt;        result      ; what we return to the caller&lt;br /&gt;        emit emit-data-rule emit-skip-rule emit-literal-rule emit-data&lt;br /&gt;        digit= n= literal=&lt;br /&gt;        int-rule= skip-rule= literal-rule= done= build-rule=&lt;br /&gt;        data-rule skip-rule&lt;br /&gt;][&lt;br /&gt;    ; This is where we put the rules we build; our gernated parse rules.&lt;br /&gt;    gen'd-rules: copy []&lt;br /&gt;    ; This is where we put the integer results&lt;br /&gt;    result: copy []&lt;br /&gt;&lt;br /&gt;    ; helper functions&lt;br /&gt;    emit: func [rule n] [append gen'd-rules replace copy rule 'n n]&lt;br /&gt;    emit-data-rule: func [n] [emit data-rule n]&lt;br /&gt;    emit-skip-rule: func [n] [emit skip-rule n]&lt;br /&gt;    emit-literal-rule: func [value] [append gen'd-rules value]&lt;br /&gt;    emit-data: does [append result to integer! =chars]&lt;br /&gt;&lt;br /&gt;    ; Rule templates; used to generate rules&lt;br /&gt;    ;data-rule: [copy =chars n digit= (append result to integer! =chars)]&lt;br /&gt;    data-rule: [copy =chars n digit= (emit-data)]&lt;br /&gt;    skip-rule: [n skip]&lt;br /&gt;&lt;br /&gt;    ; helper parse rules&lt;br /&gt;	digit=: charset [#"0" - #"9"]&lt;br /&gt;    n=: [set n integer!]&lt;br /&gt;    literal=: [set lit-val [char! | any-string!]]&lt;br /&gt;&lt;br /&gt;    ; Rule generation helper parse rules&lt;br /&gt;    int-rule=: [n= (emit-data-rule n)]&lt;br /&gt;    skip-rule=: ['skip n= (emit-skip-rule n)]&lt;br /&gt;    literal-rule=: [literal= (emit-literal-rule lit-val)]&lt;br /&gt;    done=: ['done (append gen'd-rules [to end])]&lt;br /&gt;&lt;br /&gt;    ; This generates the parse rules used against the input&lt;br /&gt;    build-rule=: [some [skip-rule= | int-rule= | literal-rule=] opt done=]&lt;br /&gt;&lt;br /&gt;    ; We parse the spec they give us, and use that to generate the&lt;br /&gt;    ; parse rules used against the actual input. If the spec parse&lt;br /&gt;    ; fails, we return none (maybe we should throw an error though);&lt;br /&gt;    ; if the data parse fails, we return false; otherwise they get&lt;br /&gt;    ; back a block of integers. Have to decide what to do if they&lt;br /&gt;    ; give us negative numbers as well.&lt;br /&gt;    either parse spec build-rule= [&lt;br /&gt;        either parse input gen'd-rules [result] [false]&lt;br /&gt;    ] [none]&lt;br /&gt;]&lt;br /&gt;comment {&lt;br /&gt;    test: func [val spec] [print mold parse-int-values val spec]&lt;br /&gt;    test "20060228T190000" [4 2 2 skip 1 2 2 2]&lt;br /&gt;    test "20060228T190000" [4 2 2 #"T" 2 2 2]&lt;br /&gt;    test "20060228T190000Z" [4 2 2 #"T" 2 2 2 #"Z"]&lt;br /&gt;    test "20060228T190000Z" [4 2 2 #"T" 2 2 2 done]&lt;br /&gt;    test %2006021509450004.jpg [4 2 2 2 2 4 skip 4]&lt;br /&gt;    test %2006021509450004.jpg [4 2 2 2 2 4 done]&lt;br /&gt;    ; tests that *should* fail&lt;br /&gt;    ; Bad spec&lt;br /&gt;    test "20060228T190000Z" [4 2 x #"T" 2 2 2]&lt;br /&gt;    test "20060228T190000Z" [4 2 2 #"T" 2.5 2 2]&lt;br /&gt;    ; Bad input&lt;br /&gt;    test "20060228T190000Z" [4 2 2 #"T" 2 2 2]&lt;br /&gt;    test "2000228T190000Z" [4 2 2 #"T" 2 2 2 done]&lt;br /&gt;    test "20060228x190000Z" [4 2 2 #"T" 2 2 2 done]&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 16 Feb 2006 00:28:44 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1494</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>Localizing a dialect with ALIAS</title>
      <link>http://snippets.dzone.com/posts/show/1201</link>
      <description>&lt;code&gt;&lt;br /&gt;; Localizing a dialect; obviously just a basic idea.&lt;br /&gt;&lt;br /&gt;alias 'who   "welche"&lt;br /&gt;alias 'where "wo"&lt;br /&gt;alias 'when  "wann"&lt;br /&gt;&lt;br /&gt;rule: [&lt;br /&gt;    some [&lt;br /&gt;        'who   set persons [word! | block!] |&lt;br /&gt;        'where set place string! |&lt;br /&gt;        'when  set time time!&lt;br /&gt;    ]&lt;br /&gt;    to end&lt;br /&gt;]&lt;br /&gt;&lt;br /&gt;time: place: persons: none&lt;br /&gt;parse [&lt;br /&gt;    who   Fred&lt;br /&gt;    where "Your house"&lt;br /&gt;    when  9:30&lt;br /&gt;] rule&lt;br /&gt;print [time place persons]&lt;br /&gt;&lt;br /&gt;time: place: persons: none&lt;br /&gt;parse [&lt;br /&gt;    welche Karl&lt;br /&gt;    wo     "Euer Haus"&lt;br /&gt;    wann   11:30&lt;br /&gt;] rule&lt;br /&gt;print [time place persons]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 19 Jan 2006 03:17:36 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1201</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>DEFINE dialect</title>
      <link>http://snippets.dzone.com/posts/show/1151</link>
      <description>&lt;code&gt;&lt;br /&gt;REBOL [&lt;br /&gt;    Title:   "#define dialected function"&lt;br /&gt;    File:    %define-dialect.r&lt;br /&gt;    Author:  "Gregg Irwin"&lt;br /&gt;    Version: 0.0.1&lt;br /&gt;    Date:    23-sep-2003&lt;br /&gt;    Purpose: {&lt;br /&gt;        Make it easier to map C #define statements. Eliminates&lt;br /&gt;        the need to manually call datatype conversion functions &lt;br /&gt;        for each item.&lt;br /&gt;    }&lt;br /&gt;    Comment: {&lt;br /&gt;        The block you pass to the function is a dialect. In the&lt;br /&gt;        dialect you can specify word-value pairs and functions&lt;br /&gt;        used to map different types of values as they are&lt;br /&gt;        processed.&lt;br /&gt;&lt;br /&gt;        MAP is used to tell the processor what function to call&lt;br /&gt;        when it encounters a particular datatype value. The&lt;br /&gt;        function specified should take a single value.&lt;br /&gt;&lt;br /&gt;            'map datatype function-name&lt;br /&gt;&lt;br /&gt;            ; call to-integer when a binary! value is found.&lt;br /&gt;            [map binary! to-integer]&lt;br /&gt;&lt;br /&gt;        Other than that, just specify a word followed by a value.&lt;br /&gt;        The resulting block will contain set-word! values for&lt;br /&gt;        each word, followed by its value - which may have been&lt;br /&gt;        converted by a function that was mapped to its original&lt;br /&gt;        datatype.&lt;br /&gt;    }&lt;br /&gt;    Example: {&lt;br /&gt;        do define [&lt;br /&gt;            map binary! to-integer&lt;br /&gt;            map issue!  to-integer&lt;br /&gt;&lt;br /&gt;            my-name "Gregg"&lt;br /&gt;            mapped-binary  #{00000001}&lt;br /&gt;            mapped-issue   #000fffff&lt;br /&gt;        ]&lt;br /&gt;        print [my-name mapped-binary mapped-issue]&lt;br /&gt;    }&lt;br /&gt;    library: [&lt;br /&gt;        level:    'intermediate&lt;br /&gt;        platform: 'all&lt;br /&gt;        type:     [function]&lt;br /&gt;        domain:   [dialect parse external-library]&lt;br /&gt;        tested-under: [view 1.2.8.3.1 on W2K]&lt;br /&gt;        support:  none&lt;br /&gt;        license:  none&lt;br /&gt;        see-also: none&lt;br /&gt;    ]&lt;br /&gt;]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;define: func [&lt;br /&gt;    block [any-block!]&lt;br /&gt;    /local type fn word val result map&lt;br /&gt;] [&lt;br /&gt;    result: make block length? block&lt;br /&gt;    map: copy []&lt;br /&gt;    either parse block [&lt;br /&gt;        some [&lt;br /&gt;            'map set type word! set fn word! (&lt;br /&gt;                type: do type&lt;br /&gt;                either word: find/skip map type 2 [&lt;br /&gt;                    change next word get fn&lt;br /&gt;                ][&lt;br /&gt;                    append map reduce [type get fn]&lt;br /&gt;                ]&lt;br /&gt;            )&lt;br /&gt;            | set word any-word! set val any-type! (&lt;br /&gt;                append result reduce [&lt;br /&gt;                    to set-word! word&lt;br /&gt;                    either fn: select map type? val [fn val][val]&lt;br /&gt;                ]&lt;br /&gt;            )&lt;br /&gt;        ]&lt;br /&gt;        to end&lt;br /&gt;    ] [result][none]&lt;br /&gt;]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;comment [ ; test examples&lt;br /&gt;    print mold defs: define [&lt;br /&gt;        map binary!  to-integer&lt;br /&gt;        map issue!   to-integer&lt;br /&gt;&lt;br /&gt;        PFD_DOUBLEBUFFER  #{00000001}&lt;br /&gt;        PFD_STEREO  #{00000002}&lt;br /&gt;        PFD_DRAW_TO_WINDOW  #00000004&lt;br /&gt;        GL_ALL_ATTRIB_BITS  #000fffff&lt;br /&gt;    ]&lt;br /&gt;    do defs&lt;br /&gt;    print [&lt;br /&gt;        PFD_DOUBLEBUFFER&lt;br /&gt;        PFD_STEREO&lt;br /&gt;        PFD_DRAW_TO_WINDOW&lt;br /&gt;        GL_ALL_ATTRIB_BITS&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;    halt&lt;br /&gt;]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 13 Jan 2006 04:20:44 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1151</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>Library interface dialect</title>
      <link>http://snippets.dzone.com/posts/show/1146</link>
      <description>&lt;code&gt;&lt;br /&gt;REBOL [&lt;br /&gt;    Title:  "Library Interface Dialect"&lt;br /&gt;    File:   %lib-dialect.r&lt;br /&gt;    Author: "Gregg Irwin"&lt;br /&gt;    Purpose: {&lt;br /&gt;        Allow for a more concise way to define library routine &lt;br /&gt;        interfaces.&lt;br /&gt;    }&lt;br /&gt;]&lt;br /&gt;&lt;br /&gt;lib-dialect-ctx: context [&lt;br /&gt;;     lib-ctx: make object! [file: lib: none free: does [free lib]]&lt;br /&gt;;     lib-spec: none&lt;br /&gt;&lt;br /&gt;    lib: none&lt;br /&gt;    def-rtn-type: none&lt;br /&gt;&lt;br /&gt;    name-mods: copy []&lt;br /&gt;    mod-name: func [name] [do join name-mods name]&lt;br /&gt;&lt;br /&gt;    ; dump/trace option to show generated code?&lt;br /&gt;&lt;br /&gt;    ;has-rtn-type?: does [all [rtn-type  'none &lt;&gt; rtn-type]]&lt;br /&gt;    ; lib is a global word reference in this func.&lt;br /&gt;    make-dll-func: func [reb-name spec rtn-type name] [&lt;br /&gt;        spec: copy any [spec []]&lt;br /&gt;        if all [rtn-type  'none &lt;&gt; rtn-type] [&lt;br /&gt;            append spec compose/deep [return: [(rtn-type)]]&lt;br /&gt;        ]&lt;br /&gt;        ;print ['make-dll-func reb-name mold spec rtn-type mold  mod-name any [name  form reb-name]]&lt;br /&gt;        set reb-name make routine! spec lib  mod-name any [name  form reb-name]&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;    data-type: [&lt;br /&gt;        'none | 'char | 'short | 'long | 'integer! | 'string! | 'decimal!&lt;br /&gt;        ; TBD add struct support ?&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;    func-decl: [&lt;br /&gt;        (spec: name: none  rtn-type: def-rtn-type)&lt;br /&gt;        set reb-name word!          ;(print reb-name)&lt;br /&gt;        any [&lt;br /&gt;              [set spec block!]     ;(print mold spec)&lt;br /&gt;            | [opt ['returns | 'as] set rtn-type data-type]  ;(print rtn-type)&lt;br /&gt;            | [opt 'calls set name string!]    ;(print name)&lt;br /&gt;        ]&lt;br /&gt;        (make-dll-func reb-name spec rtn-type name)&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;    ; You can use this multiple times, e.g. grouping functions by return&lt;br /&gt;    ; type and using it before each group.&lt;br /&gt;    set-def-rtn-type: [&lt;br /&gt;        opt 'set ['def-rtn-type | 'default-return-type]&lt;br /&gt;        set def-rtn-type data-type&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;    rules: [&lt;br /&gt;        ['lib | 'library] set file file! (lib: load/library file) ;append lib-spec compose [file: (file)]&lt;br /&gt;        opt [&lt;br /&gt;            ['modify-import-names | 'mod-imports] set name-mods block!&lt;br /&gt;        ]&lt;br /&gt;        any [set-def-rtn-type | func-decl]&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;    set 'make-routines func [spec [any-block!]] [&lt;br /&gt;        clear name-mods&lt;br /&gt;        parse spec rules&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;;     set 'make-library-interface func [spec] [&lt;br /&gt;;         lib-spec: copy []&lt;br /&gt;;         clear name-mods&lt;br /&gt;;         parse spec rules&lt;br /&gt;;     ]&lt;br /&gt;&lt;br /&gt;]&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 13 Jan 2006 04:11:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1146</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>excerpt function</title>
      <link>http://snippets.dzone.com/posts/show/1131</link>
      <description>&lt;code&gt;&lt;br /&gt;    ;-- collect-based EXCERPT ----------------------------------&lt;br /&gt;    ; Could also change EXTRACT to accept a block value for WIDTH&lt;br /&gt;    ; (renamed to, e.g., SPEC).&lt;br /&gt;    ; The dialect allows you to use commas in the block, but how they&lt;br /&gt;    ; are interpreted is not how you might think. Coming after a number,&lt;br /&gt;    ; they are a valid lexical form, but they denote a decimal! rather&lt;br /&gt;    ; than being seen as a separator, which means you can't use them too&lt;br /&gt;    ; flexibly.&lt;br /&gt;    excerpt: func [&lt;br /&gt;        {Returns the specified items and/or ranges from the series.}&lt;br /&gt;        series  [series!]&lt;br /&gt;        offsets [block!] {Offsets of the items to extract; dialected.}&lt;br /&gt;        /only "return sub-block ranges as blocks"&lt;br /&gt;        /local&lt;br /&gt;            emit-range rules&lt;br /&gt;            from* to* index*    ; parse vars&lt;br /&gt;    ][&lt;br /&gt;        ; always uses ONLY right now; it's a prototype.&lt;br /&gt;        collect/only val [&lt;br /&gt;            emit-range: func [start end] [&lt;br /&gt;                start: to integer! start&lt;br /&gt;                if number? end [end: to integer! end - start + 1]&lt;br /&gt;                val: either end = 'end [copy at series start][&lt;br /&gt;                    copy/part at series start end&lt;br /&gt;                ]&lt;br /&gt;            ]&lt;br /&gt;            rules: [&lt;br /&gt;                some [&lt;br /&gt;                    opt 'from set from* number! 'to set to* number! (&lt;br /&gt;                        emit-range from* to*&lt;br /&gt;                    )&lt;br /&gt;                  | opt 'from set from* number! 'to 'end (emit-range from* 'end)&lt;br /&gt;                  | 'to set to* number! (emit-range 1 to*)&lt;br /&gt;                  | set index* number!  (val: pick series index*)&lt;br /&gt;                  | into rules&lt;br /&gt;                ]&lt;br /&gt;            ]&lt;br /&gt;            parse offsets rules&lt;br /&gt;        ]&lt;br /&gt;    ]&lt;br /&gt;    comment {&lt;br /&gt;        b: [1 2 3 4 5 6 7 8 9 10 11 12 13 14]&lt;br /&gt;        excerpt b [1 3 5]&lt;br /&gt;        excerpt b [1 3 to 6 8]&lt;br /&gt;        excerpt/only b [1, 3 to 6, 8]&lt;br /&gt;        excerpt b [1 [5 to 7] 8]&lt;br /&gt;        excerpt/only b [1 (from 5 to 7) 8]&lt;br /&gt;        excerpt b [(to 2) [4 to 6] 8, 10, from 12 to end]&lt;br /&gt;        excerpt/only b [to 2, 4 to 6, 8, 10, (12 to end)]&lt;br /&gt;        ; Can't use a comma after 'end&lt;br /&gt;        excerpt/only b [to 2 to 6 8 10 to end 12 to end]&lt;br /&gt;        excerpt/only b [to 2, to 6, 8 [10 to end] 12 to end]&lt;br /&gt;        excerpt/only trim {&lt;br /&gt;            REBOL is my favorite language&lt;br /&gt;        } [&lt;br /&gt;            to 5, 10 to 11, 13, 14, 15, 22 to end&lt;br /&gt;        ]&lt;br /&gt;        excerpt/only to binary! {REBOL is my favorite language} [&lt;br /&gt;            to 5, 10 to 11, 13, 14, 15, 22 to end&lt;br /&gt;        ]&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 10 Jan 2006 06:27:53 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1131</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>collect function</title>
      <link>http://snippets.dzone.com/posts/show/1130</link>
      <description>&lt;code&gt;&lt;br /&gt;    ; What about extending this to work on string values?&lt;br /&gt;    collect: func [  ; a.k.a. gather ?&lt;br /&gt;        [throw]&lt;br /&gt;        {Collects block evaluations.}&lt;br /&gt;        'word "Word to collect (as a set-word! in the block)"&lt;br /&gt;        block [any-block!] "Block to evaluate"&lt;br /&gt;        /into dest [series!] "Where to append results"&lt;br /&gt;        /only "Insert series results as series"&lt;br /&gt;        ;/debug&lt;br /&gt;        /local code marker at-marker? marker* mark replace-marker rules&lt;br /&gt;    ] [&lt;br /&gt;        block: copy/deep block&lt;br /&gt;        dest: any [dest make block! []]&lt;br /&gt;        ; "not only" forces the result to logic!, for use with PICK.&lt;br /&gt;        ; insert+tail pays off here over append.&lt;br /&gt;        ;code: reduce [pick [insert insert/only] not only 'tail 'dest]&lt;br /&gt;        ; FIRST BACK allows pass-thru assignment of value. Speed hit though.&lt;br /&gt;        ;code: reduce ['first 'back pick [insert insert/only] not only 'tail 'dest]&lt;br /&gt;        code: compose [first back (pick [insert insert/only] not only) tail dest]&lt;br /&gt;        marker: to set-word! word&lt;br /&gt;        at-marker?: does [mark/1 = marker]&lt;br /&gt;        ; We have to use change/part since we want to replace only one&lt;br /&gt;        ; item (the marker), but our code is more than one item long.&lt;br /&gt;        replace-marker: does [change/part mark code 1]&lt;br /&gt;        ;if debug [probe code probe marker]&lt;br /&gt;        marker*: [mark: set-word! (if at-marker? [replace-marker])]&lt;br /&gt;        parse block rules: [any [marker* | into rules | skip]]&lt;br /&gt;        ;if debug [probe block]&lt;br /&gt;        do block&lt;br /&gt;        head :dest&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;    comment {&lt;br /&gt;        ;collect/debug zz [repeat n 10 [zz: n * 100]]&lt;br /&gt;        collect zz []&lt;br /&gt;        collect zz [repeat i 10 [if (zz: i) &gt;= 3 [break]]]&lt;br /&gt;        collect zz [repeat i 10 [zz: i  if i &gt;= 3 [break]]]&lt;br /&gt;        collect zz [repeat i 10 [either i &lt;= 3 [zz: i][break]]]&lt;br /&gt;        dest: copy []&lt;br /&gt;        collect/into zz [repeat n 10 [zz: n * 100]] dest&lt;br /&gt;        collect zz [for i 1 10 2 [zz: i * 10]]&lt;br /&gt;        collect zz [for x 1 10 1 [zz: x]]&lt;br /&gt;        collect zz [foreach [a b] [1 2 3 4] [zz: a + b]]&lt;br /&gt;        collect zz [foreach w [a b c d] [zz: w]]&lt;br /&gt;        collect zz [repeat e [a b c %.txt] [zz: file? e]]&lt;br /&gt;        iota: func [n [integer!]][collect zz [repeat i n [zz: i]]]&lt;br /&gt;        iota 10&lt;br /&gt;        collect zz [foreach x first system [zz: to-set-word x]]&lt;br /&gt;        x: first system&lt;br /&gt;        collect zz [forall x [zz: length? x]]&lt;br /&gt;        x: first system&lt;br /&gt;        collect zz [forskip x 2 [zz: length? x]]&lt;br /&gt;        collect zz [forskip x 2 [zz: (length? x) / 0]]&lt;br /&gt;        collect/only zz [foreach [a b] [1 2 3 4] [zz: a zz: b zz: reduce [a b a + b]]]&lt;br /&gt;        collect/only zz [&lt;br /&gt;            foreach [a b] [1 2 3 4] [&lt;br /&gt;                zz: a zz: b zz: reduce [a b a + b]&lt;br /&gt;                foreach n reduce [a b a + b] [zz: n * 10]&lt;br /&gt;            ]&lt;br /&gt;        ]&lt;br /&gt;&lt;br /&gt;        dest: copy ""&lt;br /&gt;        collect/into zz [repeat n 10 [zz: n * 100 zz: " "]] dest&lt;br /&gt;&lt;br /&gt;        dest: copy []&lt;br /&gt;        collect/into zz [&lt;br /&gt;            foreach [num blk] [1 [a b c] 2 [d e f] 3 [g h i]] [&lt;br /&gt;                zz: num&lt;br /&gt;                collect/only/into yy [&lt;br /&gt;                    zz: blk&lt;br /&gt;                    foreach word blk [zz: yy: num  yy: word]&lt;br /&gt;                    yy: blk&lt;br /&gt;                ] dest&lt;br /&gt;            ]&lt;br /&gt;        ] dest&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 10 Jan 2006 06:25:51 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1130</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
  </channel>
</rss>
