From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Israelsson Tampe Newsgroups: gmane.lisp.guile.devel,gmane.lisp.guile.user Subject: coroutines in guile-log Date: Sat, 20 Sep 2014 20:38:15 +0200 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a1133bdc24846760503838583 X-Trace: ger.gmane.org 1411238319 17281 80.91.229.3 (20 Sep 2014 18:38:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 20 Sep 2014 18:38:39 +0000 (UTC) To: guile-devel , "guile-user@gnu.org" Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat Sep 20 20:38:34 2014 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XVPYH-0005n2-Qd for guile-devel@m.gmane.org; Sat, 20 Sep 2014 20:38:34 +0200 Original-Received: from localhost ([::1]:35656 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVPYH-0002c6-AG for guile-devel@m.gmane.org; Sat, 20 Sep 2014 14:38:33 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51790) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVPYA-0002YP-Ip for guile-devel@gnu.org; Sat, 20 Sep 2014 14:38:28 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XVPY9-0005ac-9i for guile-devel@gnu.org; Sat, 20 Sep 2014 14:38:26 -0400 Original-Received: from mail-pa0-x235.google.com ([2607:f8b0:400e:c03::235]:64737) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVPY6-0005Yy-24; Sat, 20 Sep 2014 14:38:22 -0400 Original-Received: by mail-pa0-f53.google.com with SMTP id hz1so2039405pad.26 for ; Sat, 20 Sep 2014 11:38:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=St7B07WFQD2gmD2LBhQZ14CF9ropp0qp/Ac51Ozhe+8=; b=mksabPkql0JeCCOJ0v2g8Avwr06cAsd3kj8M2mw6i5NUxkTcS2SQ6HDuto6WLyInTE Xgg4wKzJOfuzyt2iIF4bcyWDrPq9VH8a1oaBMX96O12RlORHoXmEpQD+aB+j/mEXDI7o YK7B+fIg3ddz7Gcztmh43mlVB/puR87mBwb4ZSf03q27MAhZHjJS8j6ABkmhW7XAjZgA M7XyOt9BAVA5KbaJ1RjdbZ7xcLsbvcg+H47o/w55sT6Kn+T8spwcIYMr3Ddu3zTmsS2g LNkkFd89ZuCiDqLL+EFRxdL2c1Zq+ndX7zSHSDL5xUiw4dWIbFUHXQ9K0bTjgyBGD5GU Vx0Q== X-Received: by 10.70.140.104 with SMTP id rf8mr10987593pdb.154.1411238295212; Sat, 20 Sep 2014 11:38:15 -0700 (PDT) Original-Received: by 10.70.36.48 with HTTP; Sat, 20 Sep 2014 11:38:15 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c03::235 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:17501 gmane.lisp.guile.user:11538 Archived-At: --001a1133bdc24846760503838583 Content-Type: text/plain; charset=UTF-8 I was asked on the #prolog list to implement coroutines and attributed variables, you may find swi prolog docs for these at http://www.swi-prolog.org/pldoc/man?section=extvar now this works in guile-log, scheme@(guile-user)> (use-modules (logic guile-log guile-prolog coroutine)) scheme@(guile-user)> (use-modules (logic guile-log iso-prolog)) scheme@(guile-user)> ,L prolog Happy hacking with Prolog! To switch back, type `,L scheme'. prolog@(guile-user)> freeze(X, write(hey)), X=3. hey X = 3 more (y/n/a) > n prolog@(guile-user)> The idea of freeze(Var,Goal) is for variable Var to, when it is bound execute the goal Goal, The basic tool for this is the attributed variables that in guile-log issue a callback function when unification is done on a variable, hence you can mod the unification algorithm in many many different ways, it is interesting to see how the implementation of freeze is done, basically in prolog you have do, freezeId(Val, Var, Raw, Plus) :- Plus,var(Val);attvar(Val); ( get_attr(Var,freezeId, Atts), do_all_atts(Atts), del_attr(Var, freezeId), Var = Val ). freeze(Var,Goal) :- (var(Var), ( get_attr(Var, freezeId, Att),!, Att2 = [Goal|Att], put_attr(Var, freezeId, Att2) ); ( put_attr(Var, freezeId, [Goal]) ) ); call(Goal). So feeezeId, is the tag to associate a variable with a custom behavior and at the same time the unifyier, Raw is true if unification is without occurs check and Plus is normal unification and only == match if false e.g. comparison without unification. the freezeId finds if Var is bound or non attribute, the Attribute associated with freezeId and then execute all stored goals and finally removes the attribute and set the variables value. freeze just add the attribute as a list of goals to the variable or add the goal to an already existing attributes goal list. So it's not rocket science, but still has raw edges and the deiel is in the details, e.g. if you read the documentation you my find out issues with serializing and copying terms with associated attributes. Atm all attributes will be saved and reconstructed at term writing and reading, also everything is copied at a term copy. Hot compilation of prolog code is not working atm with attributed variables. So that's the current state of this feature, I'm happy to get it working and just chimed in to share the fun, Of cause there is a scheme interface as well to this and it can be used in the kanren interface as well, so happy hacking!! yours Stefan --001a1133bdc24846760503838583 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I was asked on the #prolog list to implement coroutin= es and attributed variables, you may=C2=A0
find swi prolog docs f= or these at


now this works in guile-log,

scheme@(guile-user)> (use-modules (logic guile-log guil= e-prolog coroutine))
scheme@(guile-user)> (use-modules (logic = guile-log iso-prolog))
scheme@(guile-user)> ,L prolog
Happy hacking with Prolog!=C2=A0 To switch back, type `,L scheme'.
prolog@(guile-user)> freeze(X, write(hey)), X=3D3.
hey=
=C2=A0 =C2=A0X =3D 3
more (y/n/a) > n
pro= log@(guile-user)>=C2=A0

The idea of freeze(Var,= Goal) is for variable =C2=A0Var to, when it is bound execute the goal Goal,=
The basic tool for this is the attributed variables that in guil= e-log issue a callback function=C2=A0
when unification is done on= a variable, hence you can mod the unification algorithm in many
= many different ways, it is interesting to see how the implementation of fre= eze is done,=C2=A0
basically in prolog you have do,


freezeId(Val, Var, Raw, Plus= ) :-=C2=A0
=C2=A0 =C2=A0 Plus,var(Val);attvar(Val);
=C2= =A0 =C2=A0 (
=C2=A0 =C2=A0 =C2=A0 =C2=A0 get_attr(Var,freezeId, A= tts),=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 do_all_atts(Atts),
<= div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 del_attr(Var, freezeId),
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 Var =3D Val
=C2=A0 =C2=A0 ).

<= /div>
freeze(Var,Goal) :-
=C2=A0 =C2=A0(var(Var),
= =C2=A0 =C2=A0 =C2=A0 (=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 get_attr= (Var, freezeId, Att),!,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 Att2 =3D [Goa= l|Att],
=C2=A0 =C2=A0 =C2=A0 =C2=A0 put_attr(Var, freezeId, Att2)=
=C2=A0 =C2=A0 =C2=A0 );
=C2=A0 =C2=A0 =C2=A0 (
=C2=A0 =C2=A0 =C2=A0 =C2=A0 put_attr(Var, freezeId, [Goal])
= =C2=A0 =C2=A0 =C2=A0 )
=C2=A0 =C2=A0);
=C2=A0 =C2=A0cal= l(Goal).

So feeezeId, is the tag to associat= e a variable with a custom behavior and at the same time=C2=A0
th= e unifyier, Raw is true if unification is without occurs check and Plus is = normal unification and only =3D=3D match if false e.g. comparison without u= nification.

the freezeId finds if Var is bound or = non attribute, the Attribute associated with freezeId and then execute all = stored goals and finally removes the attribute and set the variables value.=

freeze just add the attribute as a list of goals = to the variable or add the goal to an already existing attributes goal list= .

So it's not rocket science, but still has ra= w edges and the deiel is in the details, e.g. if you read the documentation= you my find out issues with serializing and copying terms with associated = attributes. Atm all attributes will be saved and reconstructed at term writ= ing and reading, also everything is copied at a term copy. Hot compilation = of prolog code is not working atm with attributed variables.

=
So that's the current state of this feature, I'm happy t= o get it working and just chimed in to=C2=A0
share the fun, Of ca= use there is a scheme interface as well to this and it can be used in the k= anren interface as well, so happy hacking!!

yours<= /div>
Stefan


--001a1133bdc24846760503838583--