----- Puvodn� zpr�va -----
Od: <[EMAIL PROTECTED]>
Komu: <[EMAIL PROTECTED]>
Odesl�no: 28. brezna 2000 2:56
Predmet: [REBOL] Newbie question #2 - Pattern making and using?
Re:(8)


> Look, this works, but...
>
> REBOL[]
>
> catx: false
> dogx: false
>
> dog: [["black" "mutt"]["mangy" "dog"]]
> cat: [["fat" "cat"] ["furry" "feline"]]
>
> foo: "My tiger has swallowed a mangy dog and a fat
> cat."
>
> words: parse foo "."
> foreach val cat [if found? find words val [catx:
> true]]
> foreach val dog [if found? find words val [dogx:
> true]]
>
> if dogx = true and catx = true [print "OK"]
>
> unfortunately, you cant use AND on a string, so i need
> to create non string values (catx and dogx)... i just
> thought there  must be some tighter code.  Also, if i
> have 100,000 catx and dogx values, do i need to give
> them all a initial value of 'false' first?
> TB

First, I must tell you, that Rebol/View uses more advanced parse,
than Rebol/Core. In Rebol/Core you can go like this:

match?: func [
    sentence [block!]
    pattern [block!]
] [
    foreach val pattern [
        if find sentence val [return true]
    ]
    false
]

cat: [["fluffy" "kitty"]["orange" "tabby"]]
dog: [["mangy" "mutt"]["black" "lab"]]

dogcat: func [
    foo [string!]
    /local words
] [
    words: parse foo "."
    (match? words cat) and (match? words dog)
]

>> dogcat "I have a fluffy kitty and a black lab"
== true
>> dogcat "I have a fluffy kitty and a orange tabby"
== false
>> dogcat "Where is my mangy mutt?"
== false
>> dogcat "Where can I buy a book on programming REBOL?"
== false

Regards,
    Ladislav

Reply via email to