From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Amirouche Boubekki Newsgroups: gmane.lisp.guile.user Subject: Re: Hash table cursor with delimited continuations Date: Sat, 03 Oct 2015 23:21:13 +0200 Message-ID: References: <877fn6y9of.fsf@T420.taylan> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1443907310 3138 80.91.229.3 (3 Oct 2015 21:21:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 3 Oct 2015 21:21:50 +0000 (UTC) Cc: guile-user@gnu.org, guile-user-bounces+amirouche=hypermove.net@gnu.org To: taylanbayirli@gmail.com Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Oct 03 23:21:41 2015 Return-path: Envelope-to: guile-user@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 1ZiUFJ-00086l-6K for guile-user@m.gmane.org; Sat, 03 Oct 2015 23:21:33 +0200 Original-Received: from localhost ([::1]:40052 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZiUFI-00086M-Kh for guile-user@m.gmane.org; Sat, 03 Oct 2015 17:21:32 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60041) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZiUFA-00085o-1T for guile-user@gnu.org; Sat, 03 Oct 2015 17:21:25 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZiUF8-0004St-TF for guile-user@gnu.org; Sat, 03 Oct 2015 17:21:24 -0400 Original-Received: from relay2-d.mail.gandi.net ([217.70.183.194]:56267) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZiUF4-0004Rm-6w; Sat, 03 Oct 2015 17:21:18 -0400 Original-Received: from mfilter25-d.gandi.net (mfilter25-d.gandi.net [217.70.178.153]) by relay2-d.mail.gandi.net (Postfix) with ESMTP id CC7B9C5A3C; Sat, 3 Oct 2015 23:21:15 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter25-d.gandi.net Original-Received: from relay2-d.mail.gandi.net ([IPv6:::ffff:217.70.183.194]) by mfilter25-d.gandi.net (mfilter25-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id AJj4mUtV_rml; Sat, 3 Oct 2015 23:21:14 +0200 (CEST) X-Originating-IP: 10.58.1.145 Original-Received: from webmail.gandi.net (unknown [10.58.1.145]) (Authenticated sender: amirouche@hypermove.net) by relay2-d.mail.gandi.net (Postfix) with ESMTPA id 182B2C5A3A; Sat, 3 Oct 2015 23:21:13 +0200 (CEST) In-Reply-To: <877fn6y9of.fsf@T420.taylan> X-Sender: amirouche@hypermove.net User-Agent: Roundcube Webmail/1.1.2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 217.70.183.194 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:12076 Archived-At: Le 2015-10-01 15:56, taylanbayirli@gmail.com a =C3=A9crit=C2=A0: > Out of interest, I tried implementing a hash table cursor using > hash-for-each and delimited continuations: >=20 As Mark noted on IRC this is related to=20 http://mumble.net/~campbell/scheme/foof-loop.txt I've hit a similar problem in wiredtiger. wiredtiger is built out=20 hashmaps called tables which can be queried using cursors with the=20 following procedures: (cursor-set-key cursor key) (cursor-search cursor) Then you can navigate using: (cursor-next cursor) (cursor-prev cursor) One important thing do while scanning a table is to (cursor-reset=20 cursor) before re-using the cursor for another scan. The thing is that my procedure is a composition of stream procedure=20 starting with a stream built out of a hashmap cursor. I don't know in=20 advance when the cursor must be reset. Let's say (stream-wiredtiger=20 "prefix") is a stream over all key/value pairs where key starts with=20 "prefix". If I do: ((compose (stream-take 10) stream-wiredtiger) "prefix") I take only the first 10 elements of the stream and the stream must be=20 closed but there is no stream-close procedure. Instead of using call/cc somehow, I make a list out of=20 (stream-wiredtiger "prefix"), reset the cursor and return a stream with=20 (list->stream LIST). Here is the implementation of the list that is used to build=20 stream-wiredtiger: (define (lookup prefix cursor) (with-cursor cursor (cursor-key-set cursor prefix) (if (cursor-search-near cursor) (let loop ((atoms (list))) ;; make sure it did not go beyond the keys ;; we are interested in (if (prefix? prefix (cursor-key-ref cursor)) (let ((atoms (cons (cursor-value-ref cursor) atoms))) ;; is there any other key in the hashmap? (if (cursor-next cursor) (loop atoms) atoms)))) (list)))) The advantage is that I don't need to use call/cc. The problem is that=20 the stream must fit into memory. Also another approach would be to only=20 reset the cursor if we fully consume the stream. This will have a small=20 performance impact on scanning but will save memory. This went a little off-topic. I'll just add that outside the fact that=20 srfi-41 procedures don't support currying it's basically gremlin=20 traversal=20 http://tinkerpop.incubator.apache.org/docs/3.0.0-incubating/#traversal --=20 Amirouche ~ amz3 ~ http://www.hypermove.net