unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Tassilo Horn <tassilo@member.fsf.org>
To: Ted Zlatanov <tzz@lifelogs.com>
Cc: emacs-devel@gnu.org
Subject: Re: general lazy list facility for Emacs Lisp?
Date: Wed, 23 Mar 2011 20:03:06 +0100	[thread overview]
Message-ID: <87tyetfymt.fsf@member.fsf.org> (raw)
In-Reply-To: <87oc51rcal.fsf@lifelogs.com> (Ted Zlatanov's message of "Wed, 23 Mar 2011 12:12:34 -0500")

Ted Zlatanov <tzz@lifelogs.com> 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



  parent reply	other threads:[~2011-03-23 19:03 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-23 15:07 general lazy list facility for Emacs Lisp? Ted Zlatanov
2011-03-23 16:45 ` Tassilo Horn
2011-03-23 17:12   ` Ted Zlatanov
2011-03-23 17:46     ` Thierry Volpiatto
2011-03-23 18:09       ` Ted Zlatanov
2011-03-23 18:27         ` Thierry Volpiatto
2011-03-23 20:33           ` Ted Zlatanov
2011-03-23 20:43             ` Ted Zlatanov
2011-03-23 19:03     ` Tassilo Horn [this message]
2011-03-23 19:10       ` Tassilo Horn
2011-03-23 19:42         ` Ted Zlatanov
2011-03-24  5:27           ` Eric Schulte
2011-03-24 15:43             ` Ted Zlatanov
2011-03-25 12:30               ` Eric Schulte
2011-03-23 20:03         ` Stefan Monnier
2011-03-23 20:14           ` Jason Earl
2011-03-23 20:19             ` Tassilo Horn
2011-03-23 20:18           ` Tassilo Horn
2011-03-23 20:41             ` Tassilo Horn
2011-03-23 21:51               ` Stefan Monnier
2011-03-24  7:26                 ` Tassilo Horn
2011-03-23 20:26       ` Ted Zlatanov
2011-03-23 17:13   ` Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tyetfymt.fsf@member.fsf.org \
    --to=tassilo@member.fsf.org \
    --cc=emacs-devel@gnu.org \
    --cc=tzz@lifelogs.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).