Skip to content

Basic Construction

CodingUnit edited this page Dec 21, 2011 · 11 revisions

Basic Construction

  • Category: Sequences
  • Description: This sample demonstrates basic sequence construction.
  • Comment: You must include ComputationExpressions.dll and ComputationExpressions.Macros.dll references from Nemerle distribution to project
  • Code:
using System;
using System.Console;
using Nemerle;
using Nemerle.Collections;
using Nemerle.ComputationExpressions;
using System.Linq;

  // Create an empty sequence
def emptySeq = Enumerable.Empty.[int]();

// Create a simple sequence
def simpleSeq = Enumerable.Range(1, 50); 
// sequence terms are not evaluated until needed

def seq = Enumerable.Range(1, 5);
// Create a sequence using a sequence expression
def squaresSeq = comp enumerable { foreach (i in seq) yield i * i; }
    
    

// Another sequence expression example
def getDirs(dir)
{
    comp enumerable { foreach (folder in System.IO.Directory.GetDirectories(dir)) yield folder }
}
    
WriteLine($"emptySeq = ..$emptySeq");
WriteLine($"simpleSeq = ..$simpleSeq" );
WriteLine($"squaresSeq = ..$squaresSeq" );
WriteLine($<#get directories in C: ..$(getDirs(@"C:\ ")) #>);
Clone this wiki locally