Function: iter-defun

iter-defun is a macro defined in generator.el.gz.

Signature

(iter-defun NAME ARGLIST &rest BODY)

Documentation

Create a generator NAME that accepts ARGLIST as its arguments.

When called as a function, NAME returns an iterator value that encapsulates the state of a computation that produces a sequence of values. Callers can retrieve each value using iter-next.

View in manual

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/generator.el.gz
(defmacro iter-defun (name arglist &rest body)
  "Create a generator NAME that accepts ARGLIST as its arguments.
When called as a function, NAME returns an iterator value that
encapsulates the state of a computation that produces a sequence
of values.  Callers can retrieve each value using `iter-next'."
  (declare (indent defun)
           (debug (&define name lambda-list lambda-doc &rest sexp))
           (doc-string 3)
           (autoload-macro expand)) ; expand to the defun on autoload gen
  (cl-assert lexical-binding)
  (let* ((parsed-body (macroexp-parse-body body))
         (declarations (car parsed-body))
         (exps (cdr parsed-body)))
    `(defun ,name ,arglist
       ,@declarations
       ,(cps-generate-evaluator exps))))