expressions in patterns

76 views
Skip to first unread message

Stacy

unread,
Dec 14, 2011, 9:45:24 PM12/14/11
to PyKE
Has anyone tried modifying Pyke to allow expressions in assertions
e.g., assuming $num is bound to a number, I am thinking of something
like the following
assert
relation($num+1)

of course there is a way around this by using a python premise in the
assert clause but the rules i am creating have numerous cases like
this and it would be simpler not to have to bind numerous additional
variables in the assert clause

Dante_Zaupa

unread,
Dec 15, 2011, 9:16:54 AM12/15/11
to py...@googlegroups.com
Can't you do it in the python code outside the call for rule matching?
For instance:

prove(num)
num += 1

Seems like something you ought to do in python itself, not on the rules.

> --
> You received this message because you are subscribed to the Google Groups "PyKE" group.
> To post to this group, send email to py...@googlegroups.com.
> To unsubscribe from this group, send email to pyke+uns...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pyke?hl=en.
>

--
Dante

http://dzaupa.notapipe.org/

"IMPUNIDADE, subst.: Riqueza."
                -- Ambrose Bierce, "The Devil's Dictionary"

Usuário Linux #459228 -- Linux Mint 11 ("Katya")

Bruce Frederiksen

unread,
Dec 15, 2011, 12:02:43 PM12/15/11
to py...@googlegroups.com
I'm a little leary of this.

Right now, Pyke does not parse the python code snippets in the .krb files.  It knows which lines are python code, and just does a simple scan on these strings looking for pattern variables (indicated by dollar signs, e.g., $num).  I would like to avoid having Pyke having to fully parse python code.  This would mean staying in sync with changes in the python grammar and probably would require mechanisms to support multiple grammars somehow so that Pyke would continue to run on multiple versions of python.

I suppose that the .krb parser could just take all the text up to the next comma (ignoring commas nested in parens, brackets or within string literals) as python code and do the same substitution as described above on it.  But then a question arises about single values within parenthesis.  What would ($num + 1) * 3 be when $num is 4?  If the parenthesis have python meaning, it would be 15.  But if the parenthesis have Pyke meaning, they would indicate a singleton tuple that would then be repeated 3 times giving (5, 5, 5), the same as doing (4 + 1,) * 3 in python.

Any ideas how to deal with this unambiguously?

-Bruce

Stacy

unread,
Dec 15, 2011, 8:31:52 PM12/15/11
to PyKE
I was wondering about the parentheses myself. Forget I asked.
It adds complications and frankly it is not a critical problem since
there are straightforward alternatives.
Reply all
Reply to author
Forward
0 new messages