Hi
Thanks for the code. That would be useful. Though I did not understand
how 'def works (Maybe it is in the scripts?). 'findall' does that and
something more: It can walk through possible logical alternatives and
present those as a list, as can be seen in this example:
cat("tammy").
cat("fatcat").
cat("garfield").
....
....
findall(A,cat(A),Alst)
The above findall invocation will yield the following
Alst= ["tammy","fatcat","garfield"]
In the above example the facts about cats were presented in the code. In
usual use, the programmer would not know what facts are being collected
. findall will automatically do the list collection. 'findall' can also
take parts of a fact individually and make them into a list, etc.
Maybe if you give an additional argument to the 'every func which is
actually a function call, the above things can be met. Something like
how 'sort works
Regards
Sabu Francis
> 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.