Open
Description
- I modified the tutorial factorial example to not infinitely recurse on negative input.
- This works for numbers, but ML freezes when given "monkey".
(= (factorial $x)
(case $x
((0 1)
($_
(if (> $x 0)
(* $x (factorial (- $x 1)))
(Undefined)
)))
)
)
- With the following calls:
! (factorial 5)
! (factorial -1)
! (factorial monkey)
HE:
[120]
[(Undefined)]
[(if (> monkey 0) (* monkey (factorial (- monkey 1))) (Undefined))]
ML:
[120]
[(Undefined)]
...
Activity