Drkcore

29 01 2009 perl prolog Tweet

AI::Prolog

perlの実装でAI::Prologというのがあるが、インストールするとaiprologというコマンドがついてくる。

階乗を計算してみる。

fact(0, 1).
fact(X, Sum) :-
    X > 0, X1 is X - 1, fact(X1, Sum1), Sum is X * Sum1.

aiprologを起動

$ aiprolog fact.swi

Welcome to AI::Prolog v 0.740
Copyright (c) 2005-2006, Curtis "Ovid" Poe.
AI::Prolog comes with ABSOLUTELY NO WARRANTY.  This library is free software;
you can redistribute it and/or modify it under the same terms as Perl itself.

Type 'help.' for for a list of built-ins or 'help("$builtin").' for help on a specific built-in.

?-fact(10,X).

fact(10, 3628800)

Yes

prologをいじってると宣言的ってのが「あーこういうことなのね」ってのがわかって楽しい。On LispでCommon Lispで実装するPrologとか読んである(継続とパターンマッチング)と内部でこういうことしてんのかなとか推測できるし。

ProductName On Lisp
ポール グレアム
オーム社 / 3990円 ( 2007-03 )


あとでHOPの9章の宣言的プログラミングのとこも読み返そう。Prologを知ってると面白く読めるのかも。

ProductName Higher-Order Perl: Transforming Programs with Programs
Mark Jason Dominus
Morgan Kaufmann / 5692円 ( 2005-03-28 )


About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021