@@ -705,7 +705,7 @@ You should keep in mind that commands are evaluated in order. This means that
705
705
attempting something like the below example might not do what you expect, as @samp {i }
706
706
is assigned a value from the list after collecting @samp {i } into @samp {coll }.
707
707
708
- @float Listing ,orgfa9540f
708
+ @float Listing ,orgcd9d132
709
709
@lisp
710
710
; ; => (nil 1 2)
711
711
(loopy (collect coll i)
@@ -887,7 +887,7 @@ the flag @samp{dash} provided by the package @samp{loopy-dash}.
887
887
888
888
Below are two examples of destructuring in @code {cl-loop } and @code {loopy }.
889
889
890
- @float Listing ,orgb706e77
890
+ @float Listing ,orgf148300
891
891
@lisp
892
892
; ; => (1 2 3 4)
893
893
(cl-loop for (i . j) in '((1 . 2 ) (3 . 4 ))
@@ -902,7 +902,7 @@ Below are two examples of destructuring in @code{cl-loop} and @code{loopy}.
902
902
@caption {Destructuring values in a list. }
903
903
@end float
904
904
905
- @float Listing ,orgcc60e47
905
+ @float Listing ,orgff97ac8
906
906
@lisp
907
907
; ; => (1 2 3 4)
908
908
(cl-loop for elem in '((1 . 2 ) (3 . 4 ))
@@ -1668,13 +1668,17 @@ iterator object produced by a calling a generator function. If given, @samp{VAR
1668
1668
holds the value yielded by the iterator. The loop ends when the iterator
1669
1669
finishes.
1670
1670
1671
+ @samp {close } is whether the generator should be closed via @code {iter-close } after the
1672
+ loop ends. The default is @code {t }. Note that Emacs will eventually close
1673
+ un-closed, un-reachable generators during garbage collection. To be
1674
+ consistent with other commands, @samp {close } is evaluated at the start of the loop,
1675
+ even though it's value is only used after the loop finishes.
1676
+
1671
1677
@samp {yield-result } is the optional second argument to the function @code {iter-next },
1672
1678
which is the value of @code {iter-yield } in the iterator (not to be confused with
1673
- the value yielded by calling @code {iter-next }).
1674
-
1675
- @samp {close } is whether the generator should be closed via @code {iter-close } after the
1676
- loop ends. The default is @code {t }. Note that Emacs will eventually close
1677
- un-closed, un-reachable generators during garbage collection.
1679
+ the value yielded by calling @code {iter-next }). Unlike @samp {close }, which is evaluated
1680
+ once, @samp {yield-result } is an expression which is substituted into the loop body.
1681
+ Therefore, @samp {yield-result } can be used to repeatedly call functions.
1678
1682
1679
1683
For efficiency, when possible, @samp {VAR } is bound to the yielded value before each
1680
1684
step of the loop, which is used to detect whether the iterator signals that it
@@ -1687,6 +1691,7 @@ This command also has the name @samp{iterating}.
1687
1691
1688
1692
@lisp
1689
1693
; ; With var:
1694
+ ; ;
1690
1695
; ; => ((1 . 4) (2 . 5) (3 . 6))
1691
1696
(loopy (with (iter-maker (iter-lambda (x)
1692
1697
(while x
@@ -1696,6 +1701,7 @@ This command also has the name @samp{iterating}.
1696
1701
(collect (cons i j)))
1697
1702
1698
1703
; ; Without var:
1704
+ ; ;
1699
1705
; ; => (1 2 3)
1700
1706
(loopy (iter (funcall (iter-lambda ()
1701
1707
; ; These yielded values are all ignored.
@@ -1704,6 +1710,21 @@ This command also has the name @samp{iterating}.
1704
1710
(iter-yield 'third-yield ))))
1705
1711
(set i 1 (1+ i))
1706
1712
(collect i))
1713
+
1714
+ ; ; Using `yield-result' :
1715
+ ; ;
1716
+ ; ; => (3 2 1)
1717
+ (loopy (with (yield-results nil ))
1718
+ (set i 1 (1+ i))
1719
+ (iter (funcall (iter-lambda ()
1720
+ ; ; The value from the expression specified by
1721
+ ; ; `:yield-result' is `push' -ed:
1722
+ (push (iter-yield 'first-yield ) yield-results)
1723
+ (push (iter-yield 'second-yield ) yield-results)
1724
+ (push (iter-yield 'third-yield ) yield-results)))
1725
+ ; ; Note that the value of `i' evaluated each time:
1726
+ :yield-result i)
1727
+ (finally-return yield-results))
1707
1728
@end lisp
1708
1729
1709
1730
@quotation Warning
@@ -2306,7 +2327,7 @@ Iterate through the elements for the stream
2306
2327
@samp {EXPR }. If @samp {by } is non-nil (default: 1), then move to the next n-th element
2307
2328
during each iteration. This command is a special case of the @samp {substream }
2308
2329
command (described below), setting @samp {VAR } to the first element of each
2309
- substream. For more information, see the command @samp {substream }.
2330
+ substream. For more information on streams , see the command @samp {substream }.
2310
2331
2311
2332
This command also has the alias @samp {streaming }.
2312
2333
@@ -3678,6 +3699,9 @@ If the loop is left early and @samp{TEST} was never non-nil, this is the same as
3678
3699
normal failure and @samp {VAR } will be set to the value of @samp {ON-FAILURE }, if
3679
3700
provided.
3680
3701
3702
+ To be consistent with other commands, @samp {ON-FAILURE } is evaluated at the
3703
+ start of the loop, even though that is not necessarily where it is used.
3704
+
3681
3705
@lisp
3682
3706
; ; => (13 (1 2))
3683
3707
(loopy (list i '(1 2 3 4 5 6 7 8 ))
@@ -3701,6 +3725,13 @@ provided.
3701
3725
; ; => nil
3702
3726
(loopy (list i '(1 2 3 4 5 6 ))
3703
3727
(find nil (> i 3 ) :on-failure 27 ))
3728
+
3729
+ ; ; Value of `:on-failure' gotten at the start of the loop:
3730
+ ; ; => 27
3731
+ (loopy (with (on-fail 27 ))
3732
+ (list i '(1 2 3 ))
3733
+ (set on-fail 33 )
3734
+ (find i (> i 4 ) :on-failure on-fail))
3704
3735
@end lisp
3705
3736
@end table
3706
3737
@@ -4654,7 +4685,7 @@ using the @code{let*} special form.
4654
4685
This method recognizes all commands and their aliases in the user option
4655
4686
@code {loopy-aliases }.
4656
4687
4657
- @float Listing ,orgab882ee
4688
+ @float Listing ,org7411b6a
4658
4689
@lisp
4659
4690
; ; => ((1 2 3) (-3 -2 -1) (0))
4660
4691
(loopy-iter (arg accum-opt positives negatives other)
0 commit comments