Front Page All Articles Recent Changes Random Article

Contents

Concatenative language

  • ACL
  • Ait
  • Aocla
  • Breeze
  • Callisto
  • Cat
  • Cognate
  • colorForth
  • Concata
  • CoSy
  • Deque
  • DSSP
  • dt
  • Elymas
  • Enchilada
  • ETAC
  • F
  • Factor
  • Fiveth
  • Forth
  • Fourth
  • Freelang
  • Gershwin
  • hex
  • iNet
  • Joy
  • Joy of Postfix App
  • kcats
  • Kitten
  • lang5
  • Listack
  • LSE64
  • Lviv
  • Meow5
  • min
  • Mirth
  • mjoy
  • Mlatu
  • Ode
  • OForth
  • Om
  • Onyx
  • Plorth
  • Popr
  • Porth
  • PostScript
  • Prowl
  • Quest32
  • Quackery
  • r3
  • Raven
  • Retro
  • RPL
  • SPL
  • Staapl
  • Stabel
  • Tal
  • Titan
  • Trith
  • Uiua
  • Worst
  • xs
  • XY
  • 5th
  • 8th

Concatenative topics

  • Compilers
  • Interpreters
  • Type systems
  • Object systems
  • Quotations
  • Variables
  • Garbage collection
  • Example programs

Concatenative meta

  • People
  • Communities

Other languages

  • APL
  • C++
  • Erlang
  • FP trivia
  • Haskell
  • Io
  • Java
  • JavaScript
  • Lisp
  • ML
  • Oberon
  • RPL
  • Self
  • Slate
  • Smalltalk

Meta

  • Search
  • Farkup wiki format
  • Etiquette
  • Sandbox

FizzBuzz

Print the first 30 numbers using the following rules:

  • If n is divisible by 3, print "fizz"
  • If n is divisible by 5, print "buzz"
  • If n is divisible by both, print "fizzbuzz"
  • Else, print the number

Factor

: fizzify ( sbuf m n string -- )
    [ divisor? ] dip '[ _ append! ] when drop ;

: fizzbuzz* ( n -- )
    0 <sbuf> swap { 
        [ 3 "fizz" fizzify ]
        [ 5 "buzz" fizzify ]
        [ '[ _ >dec ] when-empty print ]
    } 2cleave ;

: fizzbuzz ( n -- )
    [1..b] [ fizzbuzz* ] each ;

Kitten

Retrieved from: https://github.com/evincarofautumn/kitten/blob/master/examples/fizz-buzz.ktn

define divisible (Int32, Int32 -> Bool +Fail):
  (%) 0 (=)

define fizzbuzz (Int32 -> List<Char>):
  -> n;
  do (with (+Fail)):
    n 5 divisible
    n 3 divisible

  if:
    if: "FizzBuzz"
    else: "Fizz"
  else:
    if: "Buzz"
    else: n show

define fizzbuzzes (Int32, Int32 -> +IO):
  -> c, m;
  c fizzbuzz say
  if (c < m): (c + 1) m fizzbuzzes

1 30 fizzbuzzes

Haystack

Retrieved from: https://github.com/rtulip/haystack/blob/main/examples/fizzbuzz.hay

fn fizzbuzz(u64: n) {
    n 15 % 0 == if {
        "FizzBuzz" println
    } else n 5 % 0 == if {
        "Buzz" println
    } else n 3 % 0 == if {
        "Fizz" println
    } else {
        n println
    }
}

fn main() {
    0 while dup 30 < do {
        as [i]
        "i: " print i print " -> " print
        i fizzbuzz
        i 1 + 
    } drop
}

This revision created on Sun, 10 Mar 2024 17:28:51 by CapitalEx (Fix fib count)

Latest Revisions Edit

All content is © 2008-2024 by its respective authors. By adding content to this wiki, you agree to release it under the BSD license.