digitalmars.D - Re: A const idiom + a different 'delete'
- Pillsy <pillsbury gmail.com> Aug 12 2010
Shin Fujishiro Wrote:bearophile <bearophileHUGS lycos.com> wrote:This is an alternative way to write it that I've never used
void main() { const(int[int]) aa = { int[int] result; foreach (i; 0 .. 10) result[i] = i * i; return result; }(); }
It looks like LISP's (let ...) expression and personally I like it. The idiom is really useful for building immutable things, including compile-time constants.
It also makes for a fine replacement for the comma operator, because you can use it anywhere you can use an expression. I'd love a bit of syntactic sugar for the idiom, that would do the same thing the Lisp LET does, transforming let (x = a, y = b) { foo(x); bar(y); return quux(x, y); } into (x, y){ foo(x); bar(y); return quux(x, y); }(a, b) automatically. Cheers, Pillsy
Aug 12 2010