Question

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!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top