var numbersOneThroughTen = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
//With imperative programming, we'd step through this, and decide what we want:
var evenNumbers = new List<int>();
foreach (var number in numbersOneThroughTen)
{ if (number % 2 == 0)
{
evenNumbers.Add(number);
}
}
//The following code uses declarative programming to accomplish the same thing.
// Here, we're saying "Give us everything where it's even"
var evenNumbers = numbersOneThroughTen.Where(number => number % 2 == 0);
private static Scanner input;
public static void main(String[] args)
{
input = new Scanner(System.in);
System.out.println();
System.out.print("Enter an integer value for x: ");
int x = input.nextInt();
System.out.print("Enter an integer value for y: ");
int y = input.nextInt();
System.out.println();
System.out.printf("%d == %d? %s\n", x, y, x == y);
}
P. S.框架介于DSL和必要之间。作为所有的中途解决方案…他们结合了不足,而不是好处。他们不太安全,也不太快:)看看万事通haskell——它介于强大的简单ML和灵活的元程序Prolog之间…这是一个多么巨大的怪物。你可以把Prolog看做一个只有布尔函数/谓词的Haskell。以及它对Haskell的灵活性有多简单…