Permalink
Cannot retrieve contributors at this time
Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign up
Fetching contributors…
| -- neoscript example: Fibonacci | |
| using neos.string; | |
| using neos.stream; | |
| import fn to_string(x : i32) -> string; | |
| import fn to_integer(s : string) -> i32; | |
| import proc input(s : out string); | |
| import proc print(s : in string); | |
| -- functions are pure | |
| def fn add(x, y : i32) -> i32 | |
| { | |
| return x + y; | |
| } | |
| def fn fib(x : i32) -> i32 | |
| { | |
| if (x < 2) | |
| return 1; | |
| else | |
| return add(fib(x-1), fib(x-2)); | |
| } | |
| -- procedures are impure | |
| def proc main() | |
| s : string; | |
| { | |
| print("Enter a positive " | |
| "integer: "); | |
| input(s); | |
| print("Fibonacci(" + s + ") = " + to_string(fib(to_integer(s))) + "\n"); | |
| } |