문제

I have to test a function in erlang shell. I don't want to write a module and test i.e. erl> c(module_name).

is there any way to test my sample erlang function directly? like :

    a() -> 1.

Throwing error :

(my_project@laxmikant)7> a()->1.
* 1: syntax error before: '->'

Thanks in advance!

도움이 되었습니까?

해결책

What I understand, you want to define function directly in shell and play with it. Then wrap functionality you want to test with fun/anonymous function, example:

13> ShellFunction = fun(X) -> io:format("Some logic in my function"), 2*2 end.
#Fun<erl_eval.6.80484245>
14> ShellFunction(4).
Some logic in my function4

It is only good for small pieces of code you want to test in shell.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top