April 05, 2013
Jos van Uden:

> That shouldn't happen.

Do you know why that shouldn't happen? :-)

Bye,
bearophile
April 06, 2013
Jos van Uden:

>> http://rosettacode.org/wiki/Set_puzzle#Alternative_Version
>
> Ledrug tagged it. The output says: striped open open. That shouldn't happen.

I don't know what's wrong, and why, so I've killed that alternative version...

Bye,
bearophile
April 18, 2013
Maybe there is a way to translate this Haskell version to D with bigints:

http://rosettacode.org/wiki/Find_largest_left_truncatable_prime_in_a_given_base#Haskell

Unrelated: now I have a kind of efficient longest common subsequence algorithm with O(n) memory usage. Maybe there is some interest for it in Phobos.

Bye,
bearophile
June 13, 2013
Some of the last ones that are undone still:

http://rosettacode.org/wiki/Birthday_problem
http://rosettacode.org/wiki/Suffix_tree
http://rosettacode.org/wiki/Deming%27s_Funnel

Bye,
bearophile
June 14, 2013
There is also one D entry in need to be fixed (with Phobos):

http://rosettacode.org/wiki/Distributed_programming#D

Bye,
bearophile
June 14, 2013
On Friday, 14 June 2013 at 22:17:16 UTC, bearophile wrote:
> http://rosettacode.org/wiki/Distributed_programming#D

It kinda sounds like the description calls for something like what web.d does:

server:

import arsd.web;
class Foo : ApiProvider {
    export string hello(string name) { return "hello, " ~ name; }
    export int add(int a, int b) { return a + b; }
}
mixin FancyMain!Foo;

client:

import arsd.curl;
import std.stdio;
void main() {
    writeln(curl("http://example.com/server/hello?name=me"));
}

or javascript client:

Foo.hello("me").get(alert); // will pop up "hello, me"

or php client:

$api = new Foo("http://example.com/server/");
echo $api->add(10, 20)->getSync(); // prints 30

(the code for this is generated automatically by web.d. I also wrote a bash [!] script to call arbitrary web.d functions remotely but have not actually done the same for D itself yet! The reason is for all my use cases, I can just call the D function without going through the http middle man because all the D is part of the same executable program. Interestingly, the D one would probably use a code generator like javascript rather than opDispatch like the bash and php examples do because the code generator could give more type safety.)



This is a generic protocol, can handle many things at once, and uses pretty natural data structures. (The returned values can be almost anything, but the arguments must be all types that can be converted from strings or arrays of strings.)


This actual example here uses several thousand lines of library code but if you think it would fit the description, I'm sure I can do a basic demo in far fewer lines using nothing but phobos.
June 14, 2013
Adam D. Ruppe:

> This actual example here uses several thousand lines of library code but if you think it would fit the description, I'm sure I can do a basic demo in far fewer lines using nothing but phobos.

I think Rosettacode accepts code that uses libraries that are free. Take a look at the many Python entries for this task. So if you think this task can be implemented quickly using web.d, then use it :-) In some tasks I have appreciated solving the problems from the ground up, but in this task I think it's better to be lazy.

Bye,
bearophile
June 15, 2013
On Friday, 14 June 2013 at 22:44:40 UTC, bearophile wrote:
> So if you think this task can be implemented quickly using
> web.d, then use it :-)

I just think it is really cool that D can do that kind of thing, so a brief implementation might be good to show people how it is done.

I'll see about slapping something together over the weekend and posting it here.
June 15, 2013
Adam D. Ruppe:

> I'll see about slapping something together over the weekend and posting it here.

If you use a library, please also give the link to the library, so I can create a nearly empty page on Rosettacode about it. It's kind of needed.

Bye,
bearophile
June 16, 2013
I made a network server/client that needs no library except Phobos. Came in a little under 500 lines but is quite generic:

http://arsdnet.net/dcode/server.d

The top of the file shows the usage program, then comes the code that could go in a library.

Basically you define an interface with a bunch of functions. The server writes a class that implements that interface and then mixes in the helper code that does the network talking. The network protocol is very basic, it just serializes the arguments and return values with function and sequence numbers to know what to call. The serializer only handles basic types, arrays, and some structs, it isn't much code.

On the client side, that class is automatically generated. It doesn't completely implement the interface though, because the functions are all async callbacks instead of return values.

Run it without arguments to be the server. Any arguments will cause it to be a client and connect to local host to run the example.