Post Reply 
FOR IN {} suggestion for HP team
11-22-2014, 01:59 PM (This post was last modified: 11-22-2014 02:02 PM by Gilles.)
Post: #1
FOR IN {} suggestion for HP team
It would be fine to have this kind of syntax with the Prime like in Mapple :

FOR n IN { } DO
END


For example :

FOR n IN {"Bleu" "Blanc" "Rouge"} Do
PRINT(n);
END

would result in

Bleu
Blanc
Rouge

This will allow things like

FOR n IN { 1 7 3 9 10 11 } DO ..

And why not { 3..10} to give easily {3 4 5 6 7 8 9 10}
Find all posts by this user
Quote this message in a reply
12-01-2014, 10:00 AM
Post: #2
RE: FOR IN {} suggestion for HP team
In programming languages that use a for-construct to do list processing, the list is often not modifiable during the loop. I usually need to add elements to the list during processing, and thus use the pattern below:


LOCAL lst = { ... whatever .. };
WHILE SIZE(lst) DO
LOCAL element=head(lst);
lst:=tail(lst);

...
END;
Find all posts by this user
Quote this message in a reply
12-01-2014, 03:54 PM (This post was last modified: 12-01-2014 03:55 PM by Tim Wessman.)
Post: #3
RE: FOR IN {} suggestion for HP team
Why would anyone ever want a loop in a programming language that iterates over a fixed sized collection of some type of object? I can't imagine how that would be useful nor any language that has something similar...


/s

TW

Although I work for HP, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
12-01-2014, 04:15 PM
Post: #4
RE: FOR IN {} suggestion for HP team
(12-01-2014 03:54 PM)Tim Wessman Wrote:  Why would anyone ever want a loop in a programming language that iterates over a fixed sized collection of some type of object? I can't imagine how that would be useful nor any language that has something similar...

/s

I think the idea was not to actually loop over a fixed sized list, but to simply enable looping over lists so that one could do something like:

Code:

  FOR j IN mylist DO
    PRINT(j);
  END;

where mylist is created dynamically.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
12-01-2014, 06:17 PM
Post: #5
RE: FOR IN {} suggestion for HP team
perhaps the /s means sarcasm off...
Find all posts by this user
Quote this message in a reply
12-01-2014, 06:41 PM
Post: #6
RE: FOR IN {} suggestion for HP team
I agree with Han, iteration over a list is useful (it is the standard way to make loops in python by the way), and it is implemented in Xcas (with maple-like syntax).
Find all posts by this user
Quote this message in a reply
12-01-2014, 06:51 PM
Post: #7
RE: FOR IN {} suggestion for HP team
Python for example :

Code:

fruits = ['banana', 'apple',  'mango']
for fruit in fruits:       
   print 'Current fruit :', fruit

Or Mapple :

Code:

chiffres := {1, 2, 3, 4, 5, 6, 7, 8, 9}; 
for a in chiffres do 
for b in chiffres minus {a} do 
for c in chiffres minus {a, b} do 
 .
 .
 .
end do end do end do;

Or Ada, C, D, Delphi, Pascal, PHP,Perl , etc etc etc :
http://en.wikipedia.org/wiki/Foreach_loop

Of course the idea was not to be limited to fixed list...
Find all posts by this user
Quote this message in a reply
12-01-2014, 06:54 PM
Post: #8
RE: FOR IN {} suggestion for HP team
(12-01-2014 06:17 PM)ndzied1 Wrote:  perhaps the /s means sarcasm off...

Ha! It went completely over my head! <blush>

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 




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