Open jkleiser opened 8 years ago
Hi Jon,
Strange. Could it be something to do with overloading infix ops if you have an 'add' function? Happy to look at the fibo.pony file - maybe there's a bug here that needs squashing somewhere...
Cheers,
Darach.
Here's my fibo.pony:
use "time"
// https://cdn.rawgit.com/darach/my_little_pony/master/my-little-pony.html#/7/4
primitive Functional
fun fib(0): U64 => 0
fun fib(1): U64 => 1
fun fib(n: U64): U64 => fib(n - 1) + fib(n - 2) // couldn't find 'add' in 'None'
actor Main
let _env: Env
new create(env: Env) =>
_env = env
try
let n = _env.args(1).u8()
_env.out.write("Fibonacci(" + n.string() + ") = ")
Time.perf_begin()
let start = Time.micros()
let fib = fibonacci(n)
let stop = Time.micros()
Time.perf_end()
_env.out.print(fib.string())
_env.out.print("Time used: " + (stop - start).string() + " micros")
else
_env.err.print("An error occurred in Main.create")
_env.exitcode(-1)
end
fun fibonacci(n: U8): U64 =>
if n <= 2 then
1
else
fibonacci(n - 1) + fibonacci(n - 2)
end
Hi Jon,
This is from the 'promises' section of the talk which is about planned features! The good news is, you can track progress here for the functional programming style function overloading which is what you are trying to use:
https://github.com/CausalityLtd/ponyc/issues/351
Some of the planned features such as C-like structures are already available on master.
Cheers,
Darach.
Yes, good news. Thanks!
Hi, and thanks a lot for a great presentation!
I'm still very much a Pony beginner. I got curious re. your "primitive Functional" at my-little-pony.html#/7/4, and just pasted your 4 lines into an existing fibo.pony file I had. When trying to compile, I got things like this:
Is there some way to supply the missing 'add', or was this just some "fantasy" example?