Message from discussion
Using Templates
X-BeenThere: pyke@googlegroups.com
Received: by 10.100.17.29 with SMTP id 29ls326740anq.1.p; Wed, 16 Dec 2009
01:41:30 -0800 (PST)
Received: by 10.100.243.28 with SMTP id q28mr757200anh.20.1260956490109;
Wed, 16 Dec 2009 01:41:30 -0800 (PST)
Received: by 10.100.243.28 with SMTP id q28mr757198anh.20.1260956490085;
Wed, 16 Dec 2009 01:41:30 -0800 (PST)
Return-Path: <grp...@gmail.com>
Received: from mail-gx0-f189.google.com (mail-gx0-f189.google.com [209.85.217.189])
by gmr-mx.google.com with ESMTP id 24si90743yxe.3.2009.12.16.01.41.30;
Wed, 16 Dec 2009 01:41:30 -0800 (PST)
Received-SPF: pass (google.com: domain of grp...@gmail.com designates 209.85.217.189 as permitted sender) client-ip=209.85.217.189;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of grp...@gmail.com designates 209.85.217.189 as permitted sender) smtp.mail=grp...@gmail.com
Received: by mail-gx0-f189.google.com with SMTP id 5so1663178gxk.19
for <pyke@googlegroups.com>; Wed, 16 Dec 2009 01:41:30 -0800 (PST)
MIME-Version: 1.0
Received: by 10.101.63.12 with SMTP id q12mr68770ank.31.1260956490037; Wed, 16
Dec 2009 01:41:30 -0800 (PST)
Date: Wed, 16 Dec 2009 01:41:29 -0800 (PST)
In-Reply-To: <c9c7c65e-d2e6-45ac-83c3-7b5594df45dd@r12g2000vbm.googlegroups.com>
X-IP: 24.62.2.251
References: <c9c7c65e-d2e6-45ac-83c3-7b5594df45dd@r12g2000vbm.googlegroups.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; en-US)
AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.30 Safari/532.5,gzip(gfe),gzip(gfe)
Message-ID: <bcf3797f-9213-4d5e-8fd9-81fc04af62f3@p32g2000vbi.googlegroups.com>
Subject: Re: Using Templates
From: GRP <grp...@gmail.com>
To: PyKE <pyke@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
This would be great. I'm not doing PyKE right now but I remember
defining a rule to handle deffacts that allowed the personal-data
expression you give, and then it used assert_ and list hacking to
generate each individual (age Andrew 20) fact.
In fact, here's the rule....no idea if it still works in current PyKE
but perhaps it is helpful....what's nice is that your real rules just
match facts normally. Of course it all hinges on having a unique
ID. In your case, I'd generate a unique ID (e.g, andrew35) and have
(name andrew) as one of the pairs. Note also that the "pairs" can
be any length tuple IIRC -- e.g., (fullname, John, Quincy, Public)
# Permits a single deffacts to produce a variety of facts
#
#
# deffacts(testco, ((biztype,consulting), (location,boston),
(startyear,2001) ))
# expands to:
# biztype(testco, consulting)
# location(testco, boston)
# ...
#
expand_deffacts
foreach
xxx.deffacts($deff, (*$pairs))
xxx.infeng($infeng)
($f1,*$frest) in $pairs
assert
# wish I could just write:
# xxx.f1($frest)
# but instead I have to do the following
python
fargs =3D ($deff,) + $frest
$infeng.assert_('xxx', $f1, fargs)
On Dec 15, 11:40=A0pm, Chris <chriss...@gmail.com> wrote:
> Does Pyke support anything like the template feature in Clips?
>
> I'm running into a problem with Pyke, where reifying anything non-
> trivial becomes somewhat burdensome.
>
> For example, say I have the facts:
>
> (age Andrew 20)
> (weight Andrew 80)
> (height Andrew 188)
>
> As the number of facts about Andrew becomes large, it becomes
> considerably unwieldy. Using the string "Andrew" as an identifier is
> also problematic, since it won't scale when lots of people get added
> to the system, possibly including many Andrews.
>
> Clips has a "deftemplate" operator, to allow facts to be bound
> together in slots, without having to reify the accumulated data
> object, so you could say:
>
> (assert (personal-data (name Andrew) (age 20) (weight 80) ...)
>
> Is there any similar feature in Pyke? I suppose there's nothing
> stopping me from defining a fact in Pyke like:
>
> personal-data((uid 1234234134134),(name Andrew),(age 20),(weight 80))
>
> But the way I understand pattern matching in Pyke is that it doesn't
> support keywords, in that if I wanted to match (name $n), I'd have to
> separately test for it in the 1st, 2nd, 3rd, and however many argument
> positions my personal-data fact contains.