Skip to content

HE vs ML discrepancy: ML factorial function hangs (doesn't terminate) on non-numeric input #244

Open
@zariuq

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugIssues that represent errors in the code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions