Skip to main content
100%

Fibonacci with pattern matching in Julia

✓ Published0🌍 Public
CCliffordAnderson
Last edited Feb 27, 2017
Created on Feb 16, 2017

This example demonstrates a pattern-matching–based implementation of the Fibonacci sequence in Julia, showing how the `Match.jl` library's `@match` macro can express recursive function cases inline. The code defines a `fib` function that dispatches on the integer argument, with explicit base cases for 0 and 1 and a recursive fallback case for larger numbers. The example relies on Julia's `typeof` check to constrain inputs to non-negative `Int64` values, then uses `Match.jl`'s pattern syntax (e.g., `0 => 0`, `_ => fib(num-1) + fib(num-2)`) to handle each branch. The rendering is purely computational, with no external data sources or graphical output.

AI-generated description

Similar vizzes