No, I’m not sure, but I strongly suspect that optima isn’t the right tool for my job.
My use-case is a macro I’m trying to write called DEFINE-RELATION, which, as one might suspect from a macro with this name, defines relations between instances of classes. For example:
(define-relation window <-> layout)
This means that every instance of a WINDOW is associated with an instance of a LAYOUT, and vice versa.
But not every relation can be defined simply by the classes. For example, one might want to define familial relationships among people:
(define-relation person as father <->> person as child)
This means that a single instance of a PERSON in the role of a father is associated with multiple instances of PERSON in the role of a child.
or…
(define-relation person as manager <->> person as employee)
(define-relation person as owner <->> animal as pet)
(define-relation person as owner <->> rock as pet)
(define-relation person as owner <->> rock as weapon)
The “pattern” is naturally expressed as a regex:
(define-class ($class (:optional as $role)) (:or <-> <->> <<-> <<->>) ($class2 (:optional as $role2)))
I don’t see how to express this sort of thing in optima without enumerating all the possible cases, which rather defeats the purpose (one might as well just write a little parser at that point).
Then I want to be able to say things like this:
(define-relation user <->> time-period <->> goal)
which means that a user is associated with multiple time periods, and that each user-time-period pair is in turn associated with a number of goals.
This generalization is easily expressed as a minor tweak to the above regex:
(define-class ($class (:optional as $role)) (:one-or-more (:or <-> <->> <<-> <<->>) ($classN (:optional as $roleN))))
but AFAICT this is entirely beyond what optima can do.
rg
Ron,
are you sure that a general-purpose pattern matching library like Optima (
https://github.com/m2ym/optima) would not be better than a generalized regular expression matching library for what you need to do?
-Hans