ForExpr

From Erights

(Difference between revisions)
Jump to: navigation, search
(Tests)
Line 21: Line 21:
* <var>collection</var> may not use nouns bound by <var>optKeyPattern</var> or <var>valuePattern</var>, or vice versa.
* <var>collection</var> may not use nouns bound by <var>optKeyPattern</var> or <var>valuePattern</var>, or vice versa.
-
== Tests ==
+
C9KOXf Got it! Thanks a lot again for hlepnig me out!
-
 
+
-
The function provided to (the value of <var>collection</var>)'s [[:Category:Message iterate/1|iterate/1]] method throws if called after iterate/1 has returned.
+
-
 
+
-
? var captured := null
+
-
? def capturer {
+
-
>  to iterate(f) :void {
+
-
>    captured := f
+
-
>    f("a", "b")
+
-
>  }
+
-
> }
+
-
# value: <capturer>
+
-
+
-
? for x => y in capturer { println(x, " -> ", y) }
+
-
# stdout: a -> b
+
-
#       
+
-
+
-
? captured("c", "d")
+
-
# problem: For-loop body isn't valid after for-loop exits.
+
-
 
+
-
The return value of iterate/1 is not the return value of the for loop; the loop returns [[null]] unless a return value is given by [[__break]].
+
-
 
+
-
? def confuser extends [1,2,3] {
+
-
>  to iterate(f) {
+
-
>    super.iterate(f)
+
-
>    return __Portrayal
+
-
>  }
+
-
> }
+
-
# value: <confuser>
+
-
+
-
? def optKeyOf(collection, toFind) {
+
-
>  return for key => val in collection {
+
-
>    if (val == toFind) {
+
-
>      break key
+
-
>    }
+
-
>  }
+
-
> }
+
-
+
-
? optKeyOf(confuser, 1)
+
-
# value: 0
+
-
+
-
? [optKeyOf(confuser, 43)]
+
-
# value: [null]
+
-
 
+
-
 
+
-
[[Category:E language specification]]
+
-
[[Category:Nonkernel-E nodes]]
+

Revision as of 10:07, 20 April 2011

ForExpr is a nonkernel node which executes code for each element in a collection or other object implementing iterate/1.

"for" (optKeyPattern "=>")? valuePattern "in" collection "{" body "}" ({optBreakCatch an EMatcher}: "catch" pattern "{" expr "}")?

XXX We need to formalize the grammar definitions used in our spec

Fields

Expansion

XXX Define the expansion of ForExpr

Static constraints

  • collection may not use nouns bound by optKeyPattern or valuePattern, or vice versa.

C9KOXf Got it! Thanks a lot again for hlepnig me out!

Personal tools
more tools