Nouns in either order

I’m creating a new verb combine like so:

(grammar [combine/c [object] and [object]] for [combine $ $])

I don’t care what order they are combined in so I’d like my rule to match regardless of the order. I could define every combination like so:

(perform [combine #item1 #item2])
    (try [combine #item2 #item1]

(perform [combine #item2 #item1])
    Good job.

but I was hoping there was a more elegant generic solution, as I’ll be doing a lot of these, and there’s a possibility that I might do this with three or more items in which case defining them all will be very unwieldy.

Any suggestions?

1 Like

For this I’d make a generic rule that calls out to a helper predicate:

(perform [combine $A $B])
                (combine $A $B)
        (or)
                (combine $B $A)
        (or)
                That's preposterous.
                (tick) (stop)

And then a bunch of specific combinations:

(combine #math #alcohol)
        You drink and derive.
5 Likes

Ah, of course, the (or) predicate. I’m still learning the basic patterns of the language. I was thinking something way more complicated, involving a generic list of nouns and recursion, but this is much more simple and clear. Thanks!

:joy:

1 Like