{"issue":{"state":"open","pull_request":{"diff_url":null,"html_url":null,"patch_url":null},"milestone":null,"user":{"avatar_url":"https://secure.gravatar.com/avatar/d1588981e0248aaa0174906c99df180e?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"d1588981e0248aaa0174906c99df180e","url":"https://api.github.com/users/petdance","login":"petdance","id":41100},"assignee":{"avatar_url":"https://secure.gravatar.com/avatar/d1588981e0248aaa0174906c99df180e?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"d1588981e0248aaa0174906c99df180e","url":"https://api.github.com/users/petdance","login":"petdance","id":41100},"updated_at":"2011-11-01T04:25:28Z","labels":[],"closed_at":null,"comments":0,"url":"https://api.github.com/repos/petdance/scratch/issues/256","body":"[squaak]% cat examples/factorial.sq \r\n# Copyright (C) 2008, Parrot Foundation.\r\n# $Id: factorial.sq 36833 2009-02-17 20:09:26Z allison $\r\n\r\nprint(\"Please enter number: \")\r\nx = read()\r\n\r\nsub factorial(n)\r\n    ## test for < 2 because all numbers are represented by\r\n    ## floating-point numbers, and equality checks on those\r\n    ## do not work (yet?)\r\n    if n < 2 then\r\n        return 1\r\n    else\r\n        return n * factorial(n - 1)\r\n    end\r\nend\r\n\r\nprint(\"factorial of \", x, \" is: \", factorial(x))\r\n\r\n\r\n[squaak]% ./installable_squaak examples/factorial.sq \r\nPlease enter number: \r\n10\r\nfactorial of 10\r\n is: 1\r\n[squaak]% ./installable_squaak examples/factorial.sq\r\nPlease enter number: \r\n10\r\nfactorial of 10\r\n is: 1\r\n[squaak]% pwd\r\n/home/parthm/src/parrot-2.1.1/examples/languages/squaak\r\n[squaak]% which parrot\r\n/home/parthm/src/parrot-2.1.1/parrot\r\n[squaak]%\r\n\r\nIt seems (n < 2) is always returning true. Below are the results with prints added.\r\n\r\n[squaak]% cat fac2.sq \r\n# Copyright (C) 2008, Parrot Foundation.\r\n# $Id: factorial.sq 36833 2009-02-17 20:09:26Z allison $\r\n\r\nprint(\"Please enter number: \")\r\nx = read()\r\n\r\nprint(\"you entered:\", x)\r\n\r\nsub factorial(n)\r\n    ## test for < 2 because all numbers are represented by\r\n    ## floating-point numbers, and equality checks on those\r\n    ## do not work (yet?)\r\n\r\n    print(\"got: \", n)\r\n    print(\"is n < 2:\", n < 2)\r\n\r\n    if n < 2 then\r\n        print(\"return 1\")\r\n        return 1\r\n    else\r\n        print(\"return n * fac(n-1)\")\r\n        return n * factorial(n - 1)\r\n    end\r\nend\r\n\r\nprint(\"factorial of \", x, \" is: \", factorial(x))\r\n\r\n\r\n[squaak]% ./installable_squaak fac2.sq\r\nPlease enter number: \r\n10\r\nyou entered:10\r\n\r\ngot: 10\r\n\r\nis n < 2:1\r\nreturn 1\r\nfactorial of 10\r\n is: 1\r\n[squaak]%\r\n\r\n","html_url":"https://github.com/petdance/scratch/issues/256","title":"factorial example in languages/squaak gives incorrect result","number":256,"id":2105102,"created_at":"2011-11-01T04:25:28Z"},"action":"opened"}