[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: general lazy list facility for Emacs Lisp?
From: |
Tassilo Horn |
Subject: |
Re: general lazy list facility for Emacs Lisp? |
Date: |
Wed, 23 Mar 2011 20:03:06 +0100 |
User-agent: |
Gnus/5.110016 (No Gnus v0.16) Emacs/24.0.50 (gnu/linux) |
Ted Zlatanov <address@hidden> 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
- general lazy list facility for Emacs Lisp?, Ted Zlatanov, 2011/03/23
- Re: general lazy list facility for Emacs Lisp?, Tassilo Horn, 2011/03/23
- Re: general lazy list facility for Emacs Lisp?, Ted Zlatanov, 2011/03/23
- Re: general lazy list facility for Emacs Lisp?, Thierry Volpiatto, 2011/03/23
- Re: general lazy list facility for Emacs Lisp?, Ted Zlatanov, 2011/03/23
- Re: general lazy list facility for Emacs Lisp?, Thierry Volpiatto, 2011/03/23
- Re: general lazy list facility for Emacs Lisp?, Ted Zlatanov, 2011/03/23
- Re: general lazy list facility for Emacs Lisp?, Ted Zlatanov, 2011/03/23
- Re: general lazy list facility for Emacs Lisp?,
Tassilo Horn <=
- Re: general lazy list facility for Emacs Lisp?, Tassilo Horn, 2011/03/23
- Re: general lazy list facility for Emacs Lisp?, Ted Zlatanov, 2011/03/23
- Re: general lazy list facility for Emacs Lisp?, Eric Schulte, 2011/03/24
- Re: general lazy list facility for Emacs Lisp?, Ted Zlatanov, 2011/03/24
- Re: general lazy list facility for Emacs Lisp?, Eric Schulte, 2011/03/25
- Re: general lazy list facility for Emacs Lisp?, Stefan Monnier, 2011/03/23
- Re: general lazy list facility for Emacs Lisp?, Jason Earl, 2011/03/23
- Re: general lazy list facility for Emacs Lisp?, Tassilo Horn, 2011/03/23
- Re: general lazy list facility for Emacs Lisp?, Tassilo Horn, 2011/03/23
- Re: general lazy list facility for Emacs Lisp?, Tassilo Horn, 2011/03/23