Useless Realizations

Saturday, April 18, 2009

I was writing a compiler, for my own "fun", and had the realization that C# v3.5 can be very succinct. I had built out my lexer and was roughing out a target lisp-like syntax when I realized it was just like the C# I was writing.

private static Token GetToken(char p, IEnumerable validTokens)
{
return validTokens.FirstOrDefault(item => item.Value.Contains(p));
}

(define GetToken [p validTokens]
(first validTokens (define [item] (contains (value item) p)))
)

I have not decided if this is proof I have lost my imagination or C#'s progress as a language.