Pushing D's mixin to the limits: Project Euler Problem 61 from Ruby to D by David Oftedal

Philippe Sigaud via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Thu Jun 12 12:27:22 PDT 2014


Drat, I need a livejournal account to post comments? Well, I can at
least create a reddit account, I guess...

"In the Ruby version, I was able to add the methods directly to the
Integer class, using what's known as monkey patching, allowing me to
make calls like3.pentagonal. In D, the methods are global instead, so
the call would be pentagonal(3)."

Hmm, 3.pentagonal is valid D code. If that makes it more palatable to
Rubyists, that's good news.

There is something I don't get:

"The doublemixins with the method calls also took a while to figure
out, after the convenience of eval"

That is:

mixin("mixin(defineMain());");

I don't understand why he's doing that. AFAICT, simply using

mixin(defineMain());

would work perfectly, no? (defineMain and his other functions return strings).


More information about the Digitalmars-d-announce mailing list