Quotidian

An occasionally updated blog, mostly related to programming. (Views are my own, not my employer's.)

Tuesday, January 4, 2022

Factorial in Forth

I've been enjoying playing with Forth. Here's what I came up with to implement factorial:
: fact dup 2 < if drop 1 else dup 1 - recurse * then ;

3 fact . 6  ok
6 fact . 720  ok
This looks pretty similar to the example code here: http://progopedia.com/example/factorial/253/.
Posted by util at 9:51 PM No comments:
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Newer Posts Older Posts Home
Subscribe to: Posts (Atom)

Blog Archive

  • ►  2024 (2)
    • ►  January (2)
  • ►  2023 (7)
    • ►  December (1)
    • ►  October (1)
    • ►  July (1)
    • ►  June (1)
    • ►  May (2)
    • ►  February (1)
  • ▼  2022 (3)
    • ►  August (2)
    • ▼  January (1)
      • Factorial in Forth
  • ►  2021 (12)
    • ►  June (1)
    • ►  May (3)
    • ►  April (7)
    • ►  March (1)
  • ►  2020 (2)
    • ►  December (1)
    • ►  September (1)
  • ►  2013 (1)
    • ►  December (1)
  • ►  2009 (1)
    • ►  March (1)
  • ►  2008 (67)
    • ►  June (15)
    • ►  May (15)
    • ►  April (9)
    • ►  March (12)
    • ►  February (6)
    • ►  January (10)
  • ►  2007 (2)
    • ►  December (1)
    • ►  November (1)

About Me

util
View my complete profile
Powered by Blogger.