d 言語でアクター モデルを使用して階乗関数を実装しようとしています。私の目的は、アクターを作成して各パーツを単独で計算し、新しいアクターを生成して次のアクターを作成することです。私は D の初心者なので、言語の使い方を学んでいます。私の目的は、階乗の実装をさらに拡張することです。これは単なるテストです。
これが私の問題です。再帰を使用して階乗を実装しようとしています。ファクト関数は、基本条件に達していない限り、行の次の番号の新しいファクト スレッドを作成します。
私のコード:
void fact(Tid tid)
{
int fact = 1;
receive
(
(int i)
{
if(i == 0)
{
writeln("End of recursion");
}
else
{
fact *= i;
send(thisTid, i-1);
}
}
);
send(tid, fact);
}
void main()
{
auto tid = spawn(&fact, thisTid);
int x = 3;
send(tid, x);
auto fact = receiveOnly!(int);
writeln(fact);
}
それが可能かどうかさえわかりませんが、いずれにせようまくいきません。spwn in fact 関数を追加しようとすると、次のエラーが返されます。
src/main.d(62): Error: template std.concurrency.spawn does not match any function template declaration
/usr/include/x86_64-linux-gnu/dmd/phobos/std/concurrency.d(399): Error: template std.concurrency.spawn(T...) cannot deduce template function from argument types !()(int*,Tid)
src/main.d(63): Error: template std.concurrency.send does not match any function template declaration
/usr/include/x86_64-linux-gnu/dmd/phobos/std/concurrency.d(463): Error: template std.concurrency.send(T...) cannot deduce template function from argument types !()(_error_,int)
それで、私がやろうとしていることをすることは可能ですか?どのように?そうでない場合、そのようなことを可能にする計画はありますか?
助けてください。