Plan 9 from Bell Labs’s /usr/web/sources/contrib/fgb/root/sys/src/cmd/4th/examples/demo/recurse.4th

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


\ Example code recursion
\ Copyright 1997 HanSoft & Partners

: factorial1
  dup 2 >
  if
    dup 1-
    recurse *
  then
;

: factorial2
  dup 2 >
  if
    dup 1-
    factorial2 *
  then
;

: factorial3
  dup

  begin
    dup 2 >
  while
    1- swap over * swap
  repeat

  drop
;

10 factorial1 . cr
10 factorial2 . cr
10 factorial3 . cr


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].