[REBOL] Re: Annabelle Content Management System
From: tim-johnsons::web::com at: 13-Sep-2007 13:28
On Thursday 13 September 2007, Sabu Francis wrote:
> 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.
;; =========== code =====================
"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]]
while [not empty? cases][
set [condition cases] do/next cases
if condition [
body: first cases
if T: _n do body[append data T]
cases: next cases
either empty? data[res][data]
;; NOTES: 1)'def is a subroutine variant that automatically generates
;; local variables
;; 2)Multiple docstrings
;; console session:
>> res: every[1 false true]
== [1 3]