CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

Archetype: stream property syntax

234 Views
Copy Code Show/Hide Line Numbers
   1:  // Define a list by enclosing the item type in brackets [int]
   2:  // and initialize its value.
   3:   
   4:  Scores : [int] = [ 92, 100, 85, 62, 81, 100 ];
   5:   
   6:  // Option A
   7:   
   8:  // require the stream type to be specified on a property
   9:  PassingScores : int*
  10:  {
  11:      from s in Scores
  12:      where s >= 70
  13:      select s;
  14:  }
  15:   
  16:  // Option B
  17:   
  18:  // define a property
  19:  // infer its type from the enclosed query
  20:  PassingScores 
  21:  {
  22:      from s in Scores
  23:      where s >= 70
  24:      yield s
  25:  }
  26:   
  27:  // Learn more about the Archetype language here:
  28:  // http://archetype.codeplex.com/
by Dan Vanderboom
  June 16, 2010 @ 1:07pm
Tags:
Description:
Option A. This illustrates recent thinking on Archetype's property stream syntax. A stream property in Archetype is equivalent to an IEnumerable<T> iterator in C#, and is indicated by adding an asterisk to the item type. Noticeable here is the lack of an explicit return of values, as well as explicit execution of the query with the appropriate call to yield each value to the iterator.

Making the return keyword optional for a single statement functions (including properties) is a no-brainer. Allowing any expression that isn't being assigned or passed into something to trigger a function return, however, seems like a recipe for unpredictable behavior.

Option B. This is one possible future for Archetype property stream syntax, which replaces the query's select clause for a stream-aware yield clause that otherwise works the same way. The trailing semi-colon is removed as superfluous.

This option would force you to be somewhat careful about the overlap among properties, built-in code blocks, and custom code blocks. However, by controlling the import of custom code blocks with specific namespaces and the ability to create aliases for code constructs that may conflict, this probably isn't a big deal.

What do you think?

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate