Syntax decision

向雅 fyaoxy at gmail.com
Fri Sep 30 03:14:41 PDT 2011


Happy to see the thread like fair:-) It should be.
for sake of your eye, the post converted to DM html, (Through at this
moment it's not DM).

What I emphasize again and again, is CONTEXT.
Almost all compiler or cc, is Context-Free. just like latin-s languages.
I will say rudely, it's wrong.
You should learn the Chinish, my mother language, she is context-relative.
BTW, I'm a Chinan, to European descendant, the words Chinish and
Chinan, from your ancestor.
AIK, there are some my brothers in java team, maybe they can teach
some basic, through I not sure they catch me about the post.
Let me make a explain why CF style is wrong, just oriented the lamda.
What's lamda use case?
One main, invocation parameters.
Only one, or multiple? both!
what's form? expression, or statement.
How may parameters for lamda self? *.
OK, conclusion, in java,  lamda will used as method parameter by
expression or statement way, and lamda has any number of parameters.
Lets see one parameter case:
//OO parameter cases:
collection.filter(x<3);
collection.filter(x<3 && y>5);
collection.filter(checkX(x));
collection.filter(checkX(x, y));

//more complicated:
int ctxJ;
coolection.filter(ctxJ>0? x<3: y>5);

collection.filter(x){
    if(ctxJ>0) return x<ctxJ++;
    if(ctxJ>100) return x>ctxJ && y>5;
   doCheckingForX(x);
   return y>5;
};

//Last parameter cases:
collection.filter("condition", ..., x<3);
collection.filter("condition", ..., checkX(x));
collection.filter("condition", ..., x<3 && y>5);
collection.filter("condition", ..., checkX(x, y));

//Multiple parameter lamdas
collection.filter(x<3, y<5, z>2);
collection.filter(checkX(x), checkY(y));
collection.filter(x, y){ checkX(x); return x>2;}{ checkY(y); return y<3;};
collection.filter(x, (x,y)){
lamda.implements(x)}{lamda.implements(x,y)}; //BTW, x, or (x,y) cannot
infer? it's to put off pants to fart!
//it's form
collection.filter(expression, expression)
collection.filter({statement;+}{statememt;+}); //BTW, dose any still
need a comma between blocks?
collection.filter({statement;+}+);


Object other;
collection.filter(expression, other, expression)
collection.filter({statement;+}{statememt;+}, other); //BTW, dose any
still need a comma between blocks?
collection.filter({statement;+}+, other, ....);

Look, it's easy? OK, I stop, just like tiger head and snake tail, just be it.
As to assign case, not true case, dont make a wrong direction. it
exampled at follow snippets.
Hint, if some difficult, rethink your compiler arch.
Lexer should not do more thing, it's should be just a simple scanner.
most work must within context. that some like early binding and later
binding. I think you know its problem.
If by this way, all is APOC. Trust me, I did develop a c-structure
super set by this way, very success.

there have some example by my way, origin from M$ c# msdn page
snippet1:
delegate int del(int i);
static void main(String[] args){
 del(x)=x*x;
 int j=del(5);
}
s2:
using System.Linq.Expressions;
namespace ConsoleApplication1{
   class Program{
       static void Main(string[] args){
           Expression<del> myET(x)= x * x;
       }
   }
}

s3:
delegate void TestDelegate(string s);
…
TestDelegate myDel(n){ string s = n + " " + "World"; Console.WriteLine(s); };
myDel("Hello");

s4:
Func<int, bool> myFunc(x) = x == 5;
bool result = myFunc(4); // returns false of course

s5:
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
int oddNumbers = numbers.Count(n % 2 == 1);
int oddNumbers = numbers.Count(n){n % 2 == 1};

s6:
var firstSmallNumbers = numbers.TakeWhile(n >= index);
var firstSmallNumbers = numbers.TakeWhile(n, index) {n >= index;}

s7:
customers.Where(c){c.City == "London"};
customers.Where(c.City == "London");

s8:
delegate bool D();
delegate bool D2(int i);

class Test{
   D del;
   D2 del2;
   public void TestMethod(int input){
       int j = 0;
       // Initialize the delegates with lambda expressions.
       // Note access to 2 outer variables.
       // del will be invoked within this method.
       del{ j = 10;  return j > input; };
       del(){ j = 10;  return j > input; };

       // del2 will be invoked after TestMethod goes out of scope.
       del2(x){return x == j; };

       // Demonstrate value of j:
       // Output: j = 0
       // The delegate has not been invoked yet.
       Console.WriteLine("j = {0}", j);        // Invoke the delegate.
       bool boolResult = del();

       // Output: j = 10 b = True
       Console.WriteLine("j = {0}. b = {1}", j, boolResult);
   }

   static void Main(){
       Test test = new Test();
       test.TestMethod(5);

       // Prove that del2 still has a copy of
       // local variable j from TestMethod.
       bool result = test.del2(10);

       // Output: True
       Console.WriteLine(result);

       Console.ReadKey();
   }
}


More information about the lambda-dev mailing list