HomePage HomePage
JW Davidson JW Davidson

RSS feed for the TestJwd namespace

Show Changes Show Changes
Print Print
Recent Changes Recent Changes
Subscriptions Subscriptions
Lost and Found Lost and Found
Find References Find References
Local Search

History

9/12/2007 3:27:14 PM
-10.10.192.22
7/20/2007 11:39:07 PM
-10.10.192.236
List all versions List all versions

Wiki Talk Looping Demo
.
See_also

Using functions and loops to construct a table from two arrays

 :Cell: {r,c| [r, c]}
 :Row: {r, cs| [ cs.Collect{c| ["||", Cell(r, c)]}, "||", Newline]}
 :Table: {rs, cs| rs.Collect{r|Row(r, cs)}}
 @ @ Table(["A", "B", "C", "D"], [1,2,3,4,5,6]) @ @
A1 A2 A3 A4 A5 A6
B1 B2 B3 B4 B5 B6
C1 C2 C3 C4 C5 C6
D1 D2 D3 D4 D5 D6

Loop through a static list of ages

This example converts a static list of numbers into an array, then loops through the array searching for topics that have an age equal to the number.

 @@["21", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40"].Collect
 { n | ["|| ", n, "|| ", namespace.TopicsWith("Age", n).Collect{e | e.Name}, "|| ", Newline]}
 @@

Outputs...

21
30
31
32
33
34 KorbyParnell ,
35 TopicPropertyTable ,
36 DarenMay ,
37
38
39
40

Advanced examples of looping through collected values

Example code for looping through topics searching for those with a property called "Age":

 @@namespace.Topics.Collect
 { e |
 e.HasProperty("Age").
         IfTrue {["||[", e.Name, "]||", e.GetProperty("Name"), "||", e.GetProperty("Age"), "||", Newline]}
         IfFalse { "" }
 }
 @@

Outputs...

DarenMay Daren May 36
KorbyParnell Korby 34
TopicPropertyTable 35
WardCunningham Ward Aquarius
WikiTalkLoopingDemo Bob 42

Example code for that uses the Select method on Topics to find topics with an "Age" property:

 @@namespace.Topics.
         Select { e | e.HasProperty("Age")}.
         Collect {e | ["||[", e.Name, "]||", e.GetProperty("Name"), "||", e.GetProperty("Age"), "||", Newline]}
 @@
DarenMay Daren May 36
KorbyParnell Korby 34
TopicPropertyTable 35
WardCunningham Ward Aquarius
WikiTalkLoopingDemo Bob 42
Name
Age

Make a link named "link" to topics with a property called "RightBorder"

 @@[
   namespace.TopicsWith("RightBorder")
   .Collect
      { e | [
         "||", 
            "\"link\":[", e.Name, "]",
         "||",
            e.Name,
         "||",
            e.Summary,
         "||", Newline,
      ]}

]

 @@
link OdsBorders
link _NormalBorders

Not logged in. Log in

The wiki for all things Objective Design Solutions

Recent Topics
WikiTalkLoopingDemo WikiTalkLoopingDemo
List all versions List all versions

----

Go to Google.com
Change Style
Powered by Flexwiki v2.0.0.218