{"action":"created","issue":{"url":"https://api.github.com/repos/vermaseren/form/issues/187","repository_url":"https://api.github.com/repos/vermaseren/form","labels_url":"https://api.github.com/repos/vermaseren/form/issues/187/labels{/name}","comments_url":"https://api.github.com/repos/vermaseren/form/issues/187/comments","events_url":"https://api.github.com/repos/vermaseren/form/issues/187/events","html_url":"https://github.com/vermaseren/form/issues/187","id":229967955,"number":187,"title":"What is the fastest equivalent of Foreach in FORM?","user":{"login":"tueda","id":1481665,"avatar_url":"https://avatars3.githubusercontent.com/u/1481665?v=3","gravatar_id":"","url":"https://api.github.com/users/tueda","html_url":"https://github.com/tueda","followers_url":"https://api.github.com/users/tueda/followers","following_url":"https://api.github.com/users/tueda/following{/other_user}","gists_url":"https://api.github.com/users/tueda/gists{/gist_id}","starred_url":"https://api.github.com/users/tueda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tueda/subscriptions","organizations_url":"https://api.github.com/users/tueda/orgs","repos_url":"https://api.github.com/users/tueda/repos","events_url":"https://api.github.com/users/tueda/events{/privacy}","received_events_url":"https://api.github.com/users/tueda/received_events","type":"User","site_admin":false},"labels":[{"id":55951994,"url":"https://api.github.com/repos/vermaseren/form/labels/question","name":"question","color":"cc317c","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2017-05-19T13:01:14Z","updated_at":"2017-05-19T20:35:25Z","closed_at":"2017-05-19T20:33:28Z","body":"\"Modern\" programming languages (C++, Java, Bourne Shell, AWK, Perl, Python, Ruby, Rust, Mathematica etc.) have [Foreach](https://en.wikipedia.org/wiki/Foreach_loop)-like loop statements that iterate over a list or group of objects:\r\n```c++\r\nfor (const auto &element : my_list) {\r\n  // do something for each element...\r\n}\r\n```\r\n\r\nSuppose we want to do a similar thing for terms stored in a $-variable. For definiteness, we consider finding one element matching to some condition. Is there any good way to do this?\r\n\r\nIf there would be a special `do-in` statement and `breakdo` statement, I could write\r\n```\r\n$list = x*y + y*z + z*x;\r\n$result = 0;\r\ndo $n in $list;\r\n  if (<some condition>);\r\n    $result = <result>;\r\n    breakdo;\r\n  endif;\r\nenddo;\r\n```\r\n\r\nBut for now I may write\r\n```\r\n$list = x*y + y*z + z*x;\r\n$result = 0;\r\n$list_copy = $list;\r\nlabel loop;\r\n$n = termsin_($list_copy);\r\nif ($n);\r\n  $element = firstterm_($list_copy);\r\n  if (<some condition>);\r\n    $result = <result>;\r\n  else;\r\n    $list_copy = $list_copy - $element;\r\n    goto loop;\r\n  endif;\r\nendif;\r\n```\r\nwhich looks rather miserable, especially when `$list` has many terms ~ O(10^3-10^4). Probably a code with a `do`-loop will be messier."},"comment":{"url":"https://api.github.com/repos/vermaseren/form/issues/comments/302805023","html_url":"https://github.com/vermaseren/form/issues/187#issuecomment-302805023","issue_url":"https://api.github.com/repos/vermaseren/form/issues/187","id":302805023,"user":{"login":"vermaseren","id":5435666,"avatar_url":"https://avatars2.githubusercontent.com/u/5435666?v=3","gravatar_id":"","url":"https://api.github.com/users/vermaseren","html_url":"https://github.com/vermaseren","followers_url":"https://api.github.com/users/vermaseren/followers","following_url":"https://api.github.com/users/vermaseren/following{/other_user}","gists_url":"https://api.github.com/users/vermaseren/gists{/gist_id}","starred_url":"https://api.github.com/users/vermaseren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vermaseren/subscriptions","organizations_url":"https://api.github.com/users/vermaseren/orgs","repos_url":"https://api.github.com/users/vermaseren/repos","events_url":"https://api.github.com/users/vermaseren/events{/privacy}","received_events_url":"https://api.github.com/users/vermaseren/received_events","type":"User","site_admin":false},"created_at":"2017-05-19T20:35:25Z","updated_at":"2017-05-19T20:35:25Z","body":"Effectively what you want is to have some flag(s) that can stop further foliation at a point in\nthe tree. Like (this is science fiction)\n   ….. = distrib_(…..);\n   if ( whatever ) setstopflag distrib;\nThis might be implementable and possibly useful for more things\n\nJos\n\n> On 19 mei 2017, at 22:19, Takahiro Ueda <notifications@github.com> wrote:\n> \n> Yes, better to exit the loop. Maybe something like\n> \n> do $n = 1, $m;\n>   $found = 0;\n>   term;\n>     id f(x?) = distrib_(1,$n,f,dummy_,?a);\n>     if ($found == 0);\n>       ...\n>     endif;\n>   endterm;\n>   if ($found) $n = $m + 1;\n> enddo;\n> would be fast enough. (Depends on the speed of distrib_ vs. complicated repeat-id).\n> \n> —\n> You are receiving this because you commented.\n> Reply to this email directly, view it on GitHub <https://github.com/vermaseren/form/issues/187#issuecomment-302801640>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AFLxEuD-6HrwKt9KmJhLPsf86YGOKFERks5r7fk7gaJpZM4Ngfke>.\n> \n\n"}}
{"actor":{"display_login":"vermaseren"}}