Post Reply 
newRPL - build 1255 released! [updated to 1299]
06-07-2019, 04:57 PM
Post: #492
RE: newRPL - build 1255 released! [official and unofficial]
(06-07-2019 02:45 PM)Gilles Wrote:  
(06-04-2019 08:46 PM)Claudio L. Wrote:  I like it as an alternative format for FOR. NEXT would simply advance in the list. Is there any use for STEP? Perhaps add the number to the index within the list, so you can skip backwards or more than one item forward. The loop ends whenever the index is out of bounds.

I thinked about STEP. It coud be something like this

{ 1 2 3 4 7 9 } FOR 'MyDigit' ... NEXT
'MyDigit' is 1 for the first loop, 2 for the next loop etc.

{ 1 2 3 4 7 9 } FOR 'MyDigits' ... 2 STEP
'MyDigits' is { 1 2 } for the fisrt loop and { 3 4 } for the second loop etc.

{ 1 { "a" "b"} 4 7 9 } FOR 'MyStuff' ... 2 STEP
'MyStuff' is { 1 {"a" "b"} } for the fisrt loop and { 4 7 } for the second loop etc.

I like this because you can't do this easily with DOSUBS (with dosub we get 1 2 and 2 3 and 3 4 etc...
For the last loop, the list may content less elements but it's not a problem.

Negative step could do the same beginning by the end of the list. In this case, perhaps { 7 9 } and {3 4 } is better than { 9 7 } and { 4 3 } ?

The keyword could be FOR or FOREACH.

Nice idea, unfortunately it's not doable. When FOREACH is executed, the quantity that STEP will receive on the stack is not known yet (and may vary throughout the loop) so how many elements do we assign on the first run? Also, creating intermediate lists is expensive.
The loop would save the list and index on a local unnamed variable, so we can just give it a name (@LIST, @INDEX perhaps?) that the user can use within the loop. We can assign the given variable the current single element, but the user can get any other elements from the list with GET as needed. Another option would be a command that gives you the next or previous element but it's more limited.
STEP would just add to the index.

Anoooother option is for FOREACH to accept a list of variables instead of a single one:

Code:
{ a b c d e f } FOREACH { I J } ... NEXT
In the syntax above, FOREACH will take n elements from the list and assign them to the variables in the list. NEXT would skip n places so the next run in the example I==c and J==d.
STEP would skip the given elements (1 STEP would make the next run be I==b J==c) and could even accept negative values.
Loop would end when there's not enough values left on the list to fill all variables.[/code]
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: newRPL - build 1001 released! - pier4r - 12-16-2017, 08:03 AM
newRPL - on Hp 39gs - Martin Hepperle - 06-05-2019, 06:51 AM
RE: newRPL - build 1001 released! - pier4r - 12-23-2017, 10:16 AM
RE: newRPL - build 1001 released! - pier4r - 01-01-2018, 09:42 AM
t - Claudio L. - 01-01-2018, 03:06 PM
RE: newRPL - build 1001 released! - pier4r - 01-01-2018, 03:41 PM
RE: newRPL - build 1001 released! - pier4r - 01-02-2018, 04:54 PM
RE: newRPL - build 1001 released! - pier4r - 01-02-2018, 06:58 PM
newRPL - brickviking - 10-05-2018, 06:01 AM
RE: newRPL - build 1255 released! [official and unofficial] - Claudio L. - 06-07-2019 04:57 PM
How to participate? - erazor - 12-13-2019, 07:12 AM



User(s) browsing this thread: 2 Guest(s)