16 lines
378 B
Factor
16 lines
378 B
Factor
! Copyright (C) 2019-2020 KUSUMOTO Norio.
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
USING: factlog kernel assocs math ;
|
|
IN: factlog.examples.factorial
|
|
|
|
LOGIC-PREDS: factorial ;
|
|
LOGIC-VARS: N F N2 F2 ;
|
|
|
|
{ factorial N F } {
|
|
{ (>) N 0 }
|
|
[ [ N of 1 - ] N2 is ]
|
|
{ factorial N2 F2 }
|
|
[ [ [ F2 of ] [ N of ] bi * ] F is ] !!
|
|
} rule
|
|
{ factorial 0 1 } fact
|