You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This command affects those which accumulate values or which would exit a loop.
This is based on the Iterate's in clause:
(iter outer (for i below (array-dimension ar 0))
(iter (for j below (array-dimension ar 1))
(in outer (collect (aref ar i j)))))
In Loopy, we would want this to look something like
(loopy-iter outer
(forlist i (number-sequence0 (array-dimension ar 0)))
(loopy (list j (number-sequence0 (array-dimension ar 1)))
(as outer (collect (aref ar i j)))))
The current way of achieving the above is to use the sub-loop command:
(loopy (list i (number-sequence0 (array-dimension ar 0)))
(sub-loop (list j (number-sequence0 (array-dimension ar 1)))
(collect (aref ar i j))))
This works well for accumulation commands, because sub-loop cannot have their
own return values. However, sub-loops also have a generated name, which affects
commands which exit the loop, like leave and return.
An easy way to deal with this situation is to have at set loopy--loop-name
in a let-binding. However, this doesn't help with accumulation commands,
which have no reference to the loop they are in. Therefore, we need a way to
pass instructions back up to higher levels in the parsing process and to
identify which loop the instructions belong to.
One way to identify the loop to which an instruction belongs is to change
instructions from cons pairs to proper lists of at least 3 elements. This
third element would be a symbol identifying the loop. Lists with no third
symbol would be understood to belong to the current loop. In this scheme, the at command would be able to add the third element itself, without us needing
to change any of the existing command parsers.
Such an approach would not work with a loopy macro inside in a do command,
but that can be an acceptable limitation now that we have loopy-iter. It
might also be worth adding a loopy loop command, which could allow for special
macro arguments in sub-loops.
TODO List
Change instruction format to a proper list. Tedious, but not difficult.
The tests should quickly capture any problems caused by this.
Change the cl-tagbody tags to be based on the loop name. Maybe
introduce let-bound variables to store these tags.
Along with above, add a leave-from command.
Add an at command.
Sets loopy--loop-name and loopy--in-sub-level.
Adds the loop name as the third element in instructions.
Can take multiple expressions.
Maybe if first argument not symbol, default to loop name nil?
Maybe add a loopy loop command?
Maybe change in from an alias of list to an alias of at, to be
consistent with Iterate?
Changes needed for parsing
There might be some for how loopy-iter processes instructions.
loopy-iter calls macroexpand-all on its arguments, which won't work if
we're wrapping a loopy-iter call with an at command.
We might need to check of any wrapping of loopy-iter or loopy in the
tree, operate on it, and then return to the top-level and expand any
macros.
Examples
;; => (1 2 3)
(loopy outer
(list i '((123) (456)))
(sub-loop (list j i)
(at outer
(if (= j 4)
(leave)
(collect j)))))
;; Same as above, due to `sub-loop' not having return values.
(loopy outer
(list i '((123) (456)))
(sub-loop (list j i)
(if (= j 4)
(at outer (leave))
(collect j))))
;; => (1 2 3)
(loopy-iter outer
(forlist i '((123) (456)))
(loopy-iter (forlist j i)
(at outer
(if (= j 4)
(leave)
(collect j)))))
The text was updated successfully, but these errors were encountered:
We're now working on this in the at-cmd branch. Depending on how macroexpand-all works with variables let-bound during this expansion, this
might be simpler to implement than previously thought.
In this change, it makes sense to remove the current form of the sub-loop
command, since it was a work-around to not having an at command. Instead, it
should be a call to the loopy macro, which the macro will now to expand while
processing commands.
That would behave differently than arguments to the do command, which are
inserted literally into the loop body.
This command affects those which accumulate values or which would exit a loop.
This is based on the Iterate's
in
clause:In Loopy, we would want this to look something like
The current way of achieving the above is to use the
sub-loop
command:This works well for accumulation commands, because sub-loop cannot have their
own return values. However, sub-loops also have a generated name, which affects
commands which exit the loop, like
leave
andreturn
.An easy way to deal with this situation is to have
at
setloopy--loop-name
in a
let
-binding. However, this doesn't help with accumulation commands,which have no reference to the loop they are in. Therefore, we need a way to
pass instructions back up to higher levels in the parsing process and to
identify which loop the instructions belong to.
One way to identify the loop to which an instruction belongs is to change
instructions from
cons
pairs to proper lists of at least 3 elements. Thisthird element would be a symbol identifying the loop. Lists with no third
symbol would be understood to belong to the current loop. In this scheme, the
at
command would be able to add the third element itself, without us needingto change any of the existing command parsers.
Such an approach would not work with a
loopy
macro inside in ado
command,but that can be an acceptable limitation now that we have
loopy-iter
. Itmight also be worth adding a
loopy
loop command, which could allow for specialmacro arguments in sub-loops.
TODO List
Change instruction format to a proper list. Tedious, but not difficult.
The tests should quickly capture any problems caused by this.
Change the
cl-tagbody
tags to be based on the loop name. Maybeintroduce
let
-bound variables to store these tags.leave-from
command.Add an
at
command.loopy--loop-name
andloopy--in-sub-level
.nil
?Maybe add a
loopy
loop command?Maybe change
in
from an alias oflist
to an alias ofat
, to beconsistent with Iterate?
Changes needed for parsing
There might be some for how
loopy-iter
processes instructions.loopy-iter
callsmacroexpand-all
on its arguments, which won't work ifwe're wrapping a
loopy-iter
call with anat
command.loopy-iter
orloopy
in thetree, operate on it, and then return to the top-level and expand any
macros.
Examples
The text was updated successfully, but these errors were encountered: