-
Notifications
You must be signed in to change notification settings - Fork 89
Basic List Construction
NN--- edited this page Apr 11, 2012
·
4 revisions
- Category: Lists, Tuples and Options
- Description: This sample demonstrates basic list construction
- Code:
using Nemerle;
using System;
using System.Console;
// Create an empty list
def emptyL = [];
// Create a simple floating-point number list
def smallFloatsL = [1.0, 2.0, 3.0, 4.0];
// Create a list using a range expression - same rules as with arrays, step is optional
def listRngExp = $[0, 2 .. 10];
// Create a list using a function based on index
def listByInit = $[i * i * i, i in [0 .. 5]];
// Create a list using list comprehension
def listLC = $[i * 2, i in [1 .. 5]];
// Another example of list comprehension
def listLC2 = $[p, p in [(0, 0), (1, 1), (2, 4), (3, 9), (4, 16), (5, 25), (6, 36)], p[0] % 2 == 0];
WriteLine($"emptyL = $emptyL");
WriteLine($"smallFloatsL = $smallFloatsL");
WriteLine($"listRngExp = $listRngExp");
WriteLine($"listByInit = $listByInit");
WriteLine($"listLC = $listLC");
WriteLine($"listLC2 = $listLC2")
- Execution Result:
emptyL = []
smallFloatsL = [1, 2, 3, 4]
listRngExp = [0, 2, 4, 6, 8, 10]
listByInit = [0, 1, 8, 27, 64, 125]
listLC = [2, 4, 6, 8, 10]
listLC2 = [(0, 0), (2, 4), (4, 16), (6, 36)]
[Copyright ©](Terms of use, legal notice)