Iterative Statement Extension - Question 1 and 2 Electric Boogaloo #2672
Replies: 3 comments
|
Looking at the IRM and the current source, I would not use
For this array case, the simpler non-generator form is probably the best baseline: (for I from (ARRAYORIG A)
to (IPLUS (ARRAYSIZE A) (ARRAYORIG A) -1)
collect (ELT A I))That pattern is also used in the tree today, for example in If you want an
|
|
Thanks for the response @krotname I've been meaning to get back to this thread. I did look at the source and it became a struggle programming session to try and divine if it was possible to do the ACROSS extension. Maybe you can demo what you were thinking? At any rate, I think It's OK for the most part writing out that pattern.
|
|
Sure. The shape I had in mind was not a generator, but a small Source-level sketch, following the pattern in (I.S.OPR 'across NIL
'[SUBST (GETDUMMYVAR)
'$$ARRAY
'(bind $$ARRAY _ BODY $$INDEX $$LAST
declare (LOCALVARS $$ARRAY $$INDEX $$LAST)
first (SETQ $$INDEX (ARRAYORIG $$ARRAY))
(SETQ $$LAST (IPLUS (ARRAYSIZE $$ARRAY)
(ARRAYORIG $$ARRAY)
-1))
eachtime (AND (IGREATERP $$INDEX $$LAST)
(GO $$OUT))
(SETQ I.V. (ELT $$ARRAY $$INDEX))
repeatwhile (PROGN (SETQ $$INDEX (ADD1 $$INDEX))
T))]
T)Conceptually this would let: (for X across A collect X)mean the same thing as: (for I from (ARRAYORIG A)
to (IPLUS (ARRAYSIZE A) (ARRAYORIG A) -1)
collect (ELT A I))The important part is where the state lives. I have not run this in a Medley image, so treat it as a sketch rather than a drop-in patch. If I were turning it into a real extension, I would start with only 1-D arrays, add it to the file package's |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I've been tinkering a bit with the iterative statement. I think I've got the hang of generators they're a very cool way to abstract iterating over a process or container of unknown origin.
The IRM gives a recursive example - which is fine. I was able to bend it to make a generator for Fibonacci sequences and also a neat iterator over a Bezier curve.
I was able to do an array stepper this way just fine, though I fear it conses more than necessary.
Usually I'd do a LET over LAMBDA and use a lexical closure with mutation but I'm not sure if that'd be dangerous. As it stands I believe I either need to push the bindings into optional parameters or keep recalculating them from scratch each recursion.
Maybe I can
(DECLARE (LOCALVARS ORIGIN START LASTINDEX))?I called mine ARRAYGEN after the pattern given in the IRM.
I can then do:
(FOR N OUTOF (ARRAYGEN FOO) <do whatever with N> )ETC.I currently have been poking at the IS extension section of the IRM and feel there isn't quite enough in that section for me to grok how I might do an "ACROSS" like functionality. Perhaps it's just beyond the intent, and if so that's OK.
So step II: New Clause Electric Boogaloo...
All reactions