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: guile-log and delimeted continuations Date: Thu, 26 Sep 2013 17:14:17 +0200 Message-ID: <14379934.SjYjgA6kID@warperdoze> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7Bit X-Trace: ger.gmane.org 1380208491 9667 80.91.229.3 (26 Sep 2013 15:14:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 26 Sep 2013 15:14:51 +0000 (UTC) To: guile-devel@gnu.org, guile-user@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Sep 26 17:14:53 2013 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 1VPDHI-0001q5-EY for guile-devel@m.gmane.org; Thu, 26 Sep 2013 17:14:52 +0200 Original-Received: from localhost ([::1]:58424 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VPDHH-0003ra-SB for guile-devel@m.gmane.org; Thu, 26 Sep 2013 11:14:51 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35579) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VPDH8-0003rH-0y for guile-devel@gnu.org; Thu, 26 Sep 2013 11:14:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VPDGz-0000ti-Jj for guile-devel@gnu.org; Thu, 26 Sep 2013 11:14:41 -0400 Original-Received: from mail-lb0-x230.google.com ([2a00:1450:4010:c04::230]:53099) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VPDGz-0000tT-6O; Thu, 26 Sep 2013 11:14:33 -0400 Original-Received: by mail-lb0-f176.google.com with SMTP id y6so1186167lbh.21 for ; Thu, 26 Sep 2013 08:14:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:user-agent:mime-version :content-transfer-encoding:content-type; bh=bBLux/aXLvAg+UnEergq3J8Nio+7MENx+9Ws2Kv57LA=; b=sYGKdoBK/ybDKI/+6iU6sh2G+5vW6tWYhaQHM9L34yZk5+7a/aADkI1Kot3xawWH8P eE4rhKzav4orJgDvdlDjJvamvcQF5pKMVxBnisA5dLite4HzZegTPfDM2dd+yC4ApNSr yyLtXkETlBud6DebjblL89nfAccCnzahKg7oK+0/hwl7gkE4dO81HK+0+7kUwy7aSqJ3 IKSgolkA6eDGrvR1uXaFZOgBBaatfBAmz15uwTOP9f9h0H07/SaVDQnIB20bqnCZwpEo cP4g/g7nxsp6aBaTDz1NB130jNlEIkhoHXNy9Z4qmTa9cHVphEh5zMSOUCXww/hBaqQT Wr3Q== X-Received: by 10.152.87.143 with SMTP id ay15mr1145328lab.2.1380208471060; Thu, 26 Sep 2013 08:14:31 -0700 (PDT) Original-Received: from warperdoze.localnet (1-1-1-39a.veo.vs.bostream.se. [82.182.254.46]) by mx.google.com with ESMTPSA id ur6sm2706959lbc.5.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 26 Sep 2013 08:14:29 -0700 (PDT) User-Agent: KMail/4.9.5 (Linux/3.5.0-30-generic; KDE/4.9.5; x86_64; ; ) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c04::230 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:16644 gmane.lisp.guile.user:10823 Archived-At: Hi all, I just wanted to chime in with a discussion, regarding logic programminung in scheme. Most scheme folks would like to use kanren for this and I would say a huge chunk of written logic programs have been done in prolog. So wouldn't it be cool to combine the two iterfaces. This is what I'm currently working on in guile-log. I already have a kanren interface and I would like to get at least iso-prolog up and running before I release a new version of guile-log. So what's interesting with this task. 1. Function references and scheme hygiene. 2. How to support prolog exceptions. Prolog has a way of using, it looks, symbols in datastructures to represent function predicate and function goals. This is not the scheme way and I am trying to insert the function objects directly in the data structures. That in the end is much saner. But I suspect that this imply some deviation from iso-prolog intentions. With this approach hygiene and sanity is preserved to some degree. One could get a unified and theoretically ok foundation by demanding that all symbols are quoted, just as in scheme, or if one uses defined functions it yields the function refernces else the symbol. These twosolutions means that not many prolog code will need to be rewritten. The approach I've taken is to mainly force less common (I suspect) prolog code written that transfers a definition written in list context where symbols are used into a functor context e.g. code like prolog: X = [a | _]. #a -> 'a Y =.. X. will not work. If we had written in stead prolog; Y =.. [a | _]. # a -> a e.g. the second case will import a as a object. The problem is that [] is not treated uniformly and is just the best hack I could think of to solve the issue. --------------------------------- 2) Exceptions is interesting in the kanren world. It's one of the benefits of guile-log that always track thingies in a stack, although a large body may be pushed out to a funcitonal list construct just as in vanilla kanren, but some control stuff is always managed by, in practice a small stack. Implementing Exceptions in kanren with ordinary schme expressions may lead to the tree search to explode memory wise (everything is tail call's in kanren), so we need a special catch and throw like construct. Now to implement this we should look how guile does it in principle and boorow the semantcs. Now what guile is using is delimeted continuations. And a good idea would be to implement a prolog version if that. How? Well we stor a pair (tag, fkn) in the stack and at abort we will just scan the stack for the fisrt match and issue fkn, fkn has the signature (fkn next args ...) next is a data-structure that can be used skan to the next match in the stack and args are the args comming from the abort. The nice thingie with guile-log is that we can get the continuation directly in scheme via and restore the state via so we do not need to construct the continuation at this low level. next can be used if we find out that want to re-abort without doing anything. This is what's needed in the lower level at an abort, at an instantiation we just need to hookin the pair in the control stack. We would like to construct a continuation, howso? This will demand some trickery but in the end we would get it to work like (with-delimeted-continuation-tag tag (lambda () code ...) (lambda (kk a ...) ...)) kk will be a meta continuation e.g. the state will be stored and a real continuation will be made by issuing k = (kk), we would still need to unwind explicitly (we will be at the state of the abort) and the we can use k just as a normal fact e.g. (k X Y Z). the meaning of issuing the continuation is that we will continue at the old state and when the (lambda () code ...) successes it will copy X Y Z to their values, reinstantiate the state at the beginning of (k X Y Z) and then unify the interpretation of X Y Z with the copied values. and continue after (k X Y Z) NICE! Anyway this is all words, I need to go into the fog and implement the stuff. All cheers and have a nice day/night! /Stefan