[erlang-questions] compile buffer, cant execute func in emacs shell
Circular Function
circularfunc@REDACTED
Tue Jul 1 14:40:50 CEST 2008
Eshell V5.6.2 (abort with ^G)
1> fibo(12).
** exception error: undefined function shell_default:fibo/1
2> fibonacci:fibo(12).
** exception error: undefined function fibonacci:fibo/1
3>
this works in the shell so there is nothing wrong with the function. if i compile a buffer in emacs with erlangmode it starts the repl/shell but i cant seem to access the functions in the file.
-module(fibonacci).
-export([fib/1,fibo/1, fibo2/1, fibo3/1]).
fib_i(A, _B, 0) -> A;
fib_i(A, B, N) when N > 0 -> fib_i(B, A + B, N - 1).
fib(N) -> fib_i(0, 1, N).
fibo(0) -> 0 ;
fibo(1) -> 1 ;
fibo(N) when N > 0 -> fibo(N-1) + fibo(N-2) .
fibo2_tr( 0, Result, _Next) -> Result ; %% last recursion output
fibo2_tr( Iter, Result, Next) when Iter > 0 -> fibo2_tr( Iter -1, Next, Result + Next) .
fibo2( N) -> fibo2_tr( N, 0, 1) .
fibo3(N) ->
{Fib, _} = fibo3(N, {1, 1}, {0, 1}),
Fib.
fibo3(0, _, Pair) -> Pair;
fibo3(N, {Fib1, Fib2}, Pair) when N rem 2 == 0 ->
SquareFib1 = Fib1*Fib1,
fibo3(N div 2, {2*Fib1*Fib2 - SquareFib1, SquareFib1 + Fib2*Fib2}, Pair);
fibo3(N, {FibA1, FibA2}=Pair, {FibB1, FibB2}) ->
fibo3(N-1, Pair, {FibA1*FibB2 + FibB1*(FibA2 - FibA1), FibA1*FibB1 + FibA2*FibB2}).
___________________________________________________
Sök efter kärleken!
Hitta din tvillingsjäl på Yahoo! Dejting: http://ad.doubleclick.net/clk;185753627;24584539;x?http://se.meetic.yahoo.net/index.php?mtcmk=148783
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080701/ca4aa4f9/attachment.htm>
More information about the erlang-questions
mailing list