As you might know from the main D NG, I have just started to solve a few little programming puzzles with D2/Phobos to test how well especially the algorithm/range stuff in Phobos works out in more-or-less real world use cases.

To solve a Caesar-cipher related challenge (from hacker.org, by the way), I wrote up the following simple program:

---
import std.algorithm;
import std.stdio;

enum INPUT = "cqrb lryqna rb fjh, fjh qjamna cqjw axc cqracnnw. qnan, hxd wnena twxf qxf oja cx bqroc! xq kh cqn fjh, cqn jwbfna rb mnjmvjwblqnbc.";

void main() {
   foreach ( offset; 0..25 ) {
      writeln( map!( ( dchar c ) {
         if ( c < 'a' ) return c;
         if ( 'z' < c ) return c;
         return cast( dchar )( ( ( ( c - 'a' ) + offset ) % 26 ) + 'a' );
      } )( INPUT ) );
   }
}
---

Seems reasonable, right? Using DMD 2.049, however, it segfaults in the delegate literal. Why this? Have I missed something obvious?

If you don't want to compile it yourself, I have posted the backtrace here: http://gist.github.com/630201

David

Reply via email to