factor/extra/logic/examples/factorial/factorial.factor

16 lines
378 B
Factor
Raw Normal View History

2020-03-01 04:19:07 -05:00
! 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