* coroutines in guile-log
@ 2014-09-20 18:38 Stefan Israelsson Tampe
0 siblings, 0 replies; only message in thread
From: Stefan Israelsson Tampe @ 2014-09-20 18:38 UTC (permalink / raw
To: guile-devel, guile-user@gnu.org
[-- Attachment #1: Type: text/plain, Size: 2599 bytes --]
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
[-- Attachment #2: Type: text/html, Size: 3510 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2014-09-20 18:38 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-20 18:38 coroutines in guile-log Stefan Israelsson Tampe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).