[erlang-questions] Fwd: run program from commandprompt? define function?

David Budworth <>
Sat May 31 20:30:04 CEST 2008


Forgot to reply-all, here it is again:

c(tut) will look in the current directory.  So if you moved it to bin, you
should run erl from there or do:cd("bin").

from the shell
as for defining functions from the shell, I don't believe you can define
normal module:function/arity style functions like in your tut.erl (that
function being tut:double/1)

but you can define fun's from the shell and call them, example:
1> Double = fun(X) -> 2 * X end.
#Fun<erl_eval.6.13229925>
2> Double(5).
10
3>

the difference here is you have to make anonymous functions and bind them to
variables.  so they won't look quite the same as from a source file where
you use lowercase atom names.

make sense?

2008/5/31 Circular Function <>:

> -module(tut).
> -export([double/1]).
>
> double(X) ->
>     2 * X.
>
> saved that in tut.erl, placed it in the bin/ and tried to run it but it
> asks for a specific program to run.
>
> Erlang (BEAM) emulator version 5.6.2 [async-threads:0]
>
> Eshell V5.6.2  (abort with ^G)
> 1> c(tut).
> ./tut.erl:none: no such file or directory
> error
> 2>
>
> so which install do i need?
>
>
> how do i define a function?
>
> can i do that directlyin the shell?
>
> like in python:
> def sq(x): return x*x
>
> how would i dot hat in erlang?
>
> ------------------------------
> Sök efter kärleken!
> Hitta din tvillingsjäl på Yahoo! Dejting: http://se.meetic.yahoo.net<http://ad.doubleclick.net/clk;185753627;24584539;x?http://se..meetic.yahoo.net/index.php?mtcmk=148783>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080531/b3c05000/attachment.html>


More information about the erlang-questions mailing list