Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generator function unknown #24

Closed
lispm opened this issue Aug 3, 2018 · 1 comment
Closed

generator function unknown #24

lispm opened this issue Aug 3, 2018 · 1 comment

Comments

@lispm
Copy link

lispm commented Aug 3, 2018

(defun |tee| (iterable &optional (n 2))
  "Create N independent generators"
  (check-type n integer)
  (cond ((zerop n)
         (make-tuple-from-list ()))
        (t
         (let ((iter-func (clpython::get-py-iterate-fun iterable))
               (deques (loop repeat n collect (clpython.module._collections:|deque|))))
           (flet ((generator (deque)
                    (clpython::make-iterator-from-function
                     :name :tee-iterator
                     :func (lambda () 
                             (if (clpython::py-val->lisp-bool deque)
                                 (clpython.module._collections::deque.popleft deque)
                               (let ((new-val (funcall iter-func)))
                                 ;; also continue if NEW-VAL is NIL
                                 (dolist (d deques)
                                   (unless (eq d deque)
                                     (clpython.module._collections::deque.append d new-val)))
                                 new-val))))))
             (make-tuple-from-list (mapcar 'generator deques)))))))

Probably the MAPCAR should use #'generator and not 'generator

metawilm added a commit that referenced this issue Sep 2, 2018
@metawilm
Copy link
Owner

metawilm commented Sep 2, 2018

Thanks, it's corrected in commit 0f47bf7.
Allegro CL did the wrong thing by using the FLET binding, hiding the error for me.

@metawilm metawilm closed this as completed Sep 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants