On Thursday 13 September 2007, Sabu Francis wrote:
> Hi
> Yes Prolog is quite a useful language. The concept of 'backtracking' is
> very powerful. In fact, I think (not verified) many important concepts
> originated in Prolog and Lisp, two of the oldest languages. It also
> handles data and meta-data structures very nicely.
>
> I had used a variant of XML in Prolog (which I used to call 'proXML')
> that overcame many of the problems that Carl had pointed out in XML.
> Anyway, I am probably digressing ...
>
> I find Rebol also a very good language to work with. I think it can also
> handle data+code together (data turning into code, code back into data)
> which can be very useful. Now if someone has figured out a way to do
> backtracking in Rebol and do things like 'findall' ( a predicate in most
> Prolog to collect data together)... well that would be really wonderful.

  I'm a web programmer and despite then popularity of python (my other
  scripting tool) and the depend for python scripters, I do more and more
  in rebol. The change is accelerated by the growth in rebol assets such as
  those at rebol.org
 
  I'm not sure *exactly* what findall does, but what follows is 
  first - a rebol function that I wrote based on earlier code by Marco
  ( I think that is the same Marco that wrote prolog.r) - and after that is
  a simple console session.
  cheers
  tim
;; =========== code =====================
 every: def[  
    "Evaluates code following any expression that is not FALSE or NONE."
        "  Accumulates return values of code (if 'set)."
    "  Returns a block if at least one code set is evaluated."
        "  If no code block is evaluated, returns 'false."
        "  Handles unset! values"
     cases [block!] "Block of cases to evaluate."  
        ][  
        _n: func ["Check for unset values and return 'none if found"
                v [any-type!]][either unset? get/any 'v [none][v]]
        res: false
        data: copy[]
     while [not empty? cases][  
         set [condition cases] do/next cases  
         if condition [  
                 res: true 
             body: first cases  
                    if T: _n do body[append data T]
                        ]  
         cases: next cases  
                ]  
        either res[
                either empty? data[res][data]
                ][res]
        ]
;; NOTES: 1)'def is a subroutine variant that automatically generates
;;                local variables
;;             2)Multiple docstrings
;; console session:
>> res: every[1[1] false[2] true[3]]
== [1 3]

-- 
To unsubscribe from the list, just send an email to 
lists at rebol.com with unsubscribe as the subject.

Reply via email to