From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.devel Subject: Re: general lazy list facility for Emacs Lisp? Date: Wed, 23 Mar 2011 20:03:06 +0100 Message-ID: <87tyetfymt.fsf@member.fsf.org> References: <87pqphswn3.fsf@lifelogs.com> <877hbpzsy8.fsf@member.fsf.org> <87oc51rcal.fsf@lifelogs.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1300907006 27137 80.91.229.12 (23 Mar 2011 19:03:26 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 23 Mar 2011 19:03:26 +0000 (UTC) Cc: emacs-devel@gnu.org To: Ted Zlatanov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Mar 23 20:03:21 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Q2TKy-0001rn-Hy for ged-emacs-devel@m.gmane.org; Wed, 23 Mar 2011 20:03:20 +0100 Original-Received: from localhost ([127.0.0.1]:60753 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q2TKx-0006Pb-QN for ged-emacs-devel@m.gmane.org; Wed, 23 Mar 2011 15:03:19 -0400 Original-Received: from [140.186.70.92] (port=57382 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q2TKt-0006PM-A3 for emacs-devel@gnu.org; Wed, 23 Mar 2011 15:03:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q2TKo-0005sJ-06 for emacs-devel@gnu.org; Wed, 23 Mar 2011 15:03:15 -0400 Original-Received: from out3.smtp.messagingengine.com ([66.111.4.27]:32781) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q2TKn-0005s4-To for emacs-devel@gnu.org; Wed, 23 Mar 2011 15:03:09 -0400 Original-Received: from compute3.internal (compute3.nyi.mail.srv.osa [10.202.2.43]) by gateway1.messagingengine.com (Postfix) with ESMTP id F15DF20581; Wed, 23 Mar 2011 15:03:08 -0400 (EDT) Original-Received: from frontend2.messagingengine.com ([10.202.2.161]) by compute3.internal (MEProxy); Wed, 23 Mar 2011 15:03:08 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=messagingengine.com; h=from:to:cc:subject:references:date:in-reply-to:message-id:mime-version:content-type; s=smtpout; bh=kac55LRBJEup/DWHFITuAG5uWvw=; b=noV9EKfc18oGRiFmSM3KLv1K0/PhR0mX4QNCgCK7Bm7lE+UIDagxCMTVCyBvmJFRp+3AdfoXTn6Ssye4J+2ss4/GwjHa50AMdN6xufWKrF0elwOAwyKtGh07bVEtu4xXdNaztHwin6E85bwrDEPm/2z1aGNP2CCHfjQlJLwQv2w= X-Sasl-enc: vAkhU5uNSCKbxtLymKKfhS9MUpiAW8foWh3u+WRtyitq 1300906988 Original-Received: from thinkpad (88-134-173-46-dynip.superkabel.de [88.134.173.46]) by mail.messagingengine.com (Postfix) with ESMTPA id 2EB2A440FFC; Wed, 23 Mar 2011 15:03:07 -0400 (EDT) In-Reply-To: <87oc51rcal.fsf@lifelogs.com> (Ted Zlatanov's message of "Wed, 23 Mar 2011 12:12:34 -0500") User-Agent: Gnus/5.110016 (No Gnus v0.16) Emacs/24.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.111.4.27 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:137599 Archived-At: Ted Zlatanov writes: Hi Ted, > Yes, that's what I mean. In Haskell such lists are simply part of the > core language; Perl 5 can hack them together with list accessors; Perl > 6 has them in the core too... I think "lazy list" is a popular term > for the general facility? I'm surprised no one has needed them, > whatever the name :) Lately, I do some Clojure coding for fun, and I really enjoy lazy seqs there. However, I don't see a real use case in emacs. So, pants off, what are you planning to do? > Slightly related: is there a general memoization package or standard > approach to memoizing functions? I think for "real" memoization, you need clojures. However, I think you can simulate memoization with a macro like that (tested only very briefly). --8<---------------cut here---------------start------------->8--- (defmacro memoize (name fun) (let ((map-name (gensym "memo-map")) (args-name (gensym)) (val-name (gensym))) `(progn (defvar ,map-name (make-hash-table :test 'equal)) (defun ,name (&rest ,args-name) (let ((,val-name (gethash ,args-name ,map-name))) (if ,val-name ,val-name (puthash ,args-name (apply (quote ,fun) ,args-name) ,map-name))))))) ;; Create a memoized version of + (memoize memo-+ +) ;; Call it (memo-+ 1 1) ;; ==> 2 (memo-+) ;; ==> 2, not computed by looked up in the hash table --8<---------------cut here---------------end--------------->8--- Bye, Tassilo