Erlang Mailing Lists

Author Message

<  Erlang  ~  user_default:c

happi
Posted: Fri Jul 21, 2006 1:17 pm Reply with quote
Joined: 07 Nov 2005 Posts: 6 Location: Sweden
If you have a system that is normaly built with makefiles, and which uses the otp structure of src and ebin directories you might have had problem compiling from the erlang shell.
I use the following useful hack in my user_default:

Code:


c(M) ->
    case shell_default:c(M) of
   error ->
       try src(M) of
      S -> shell_default:c(S,[{outdir,filename:dirname(beam(M))}])
       catch error: _ -> error
       end;
   O -> O
    end.

c(M, Opts) ->
    case shell_default:c(M, Opts) of
   error ->
       try src(M) of
      S -> shell_default:c(S,Opts++[{outdir,filename:dirname(beam(M))}])
       catch error: E -> E
       end;
   O -> O
    end.
   
src(Module) ->
    proplists:get_value(source,
         proplists:get_value(compile, 
                   Module:module_info())).
beam(Module) ->
    code:which(Module).

View user's profile Send private message Visit poster's website
Ludvig
Posted: Fri Jul 21, 2006 1:31 pm Reply with quote
User Joined: 20 Jul 2006 Posts: 38 Location: London
Cool, I will try it out.
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number
Ludvig
Posted: Fri Jul 21, 2006 3:57 pm Reply with quote
User Joined: 20 Jul 2006 Posts: 38 Location: London
I have now added your code to my .erlang file:
But when I'm starting erl I get this message

=ERROR REPORT==== 21-Jul-2006::16:56:24 ===
file:path_eval([".","/home/ludvig"],".erlang"): error on line 3: 3: syntax error before: '->'


Do you know what could be the problem. Is .erlang the right file?
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number
happi
Posted: Mon Jul 24, 2006 6:28 am Reply with quote
Joined: 07 Nov 2005 Posts: 6 Location: Sweden
Ludvig wrote:

Do you know what could be the problem. Is .erlang the right file?


No, it should go into user_default.erl
View user's profile Send private message Visit poster's website
Ludvig
Posted: Mon Jul 24, 2006 8:39 am Reply with quote
User Joined: 20 Jul 2006 Posts: 38 Location: London
Where should I put this file?

Should I compile it and put it somewhere and then do add_path in my .erlang file?

--- EDIT ---
I have now tried this:
.erlang
Code:
code:load_abs("/home/ludvig/user_default").


user_default.erl
Code:
-module(user_default).
-compile(export_all).

c(M) ->
    case shell_default:c(M) of
   error ->
       try src(M) of
      S -> shell_default:c(S,[{outdir,filename:dirname(beam(M))}])
       catch error: _ -> error
       end;
   O -> O
    end.

c(M, Opts) ->
    case shell_default:c(M, Opts) of
   error ->
       try src(M) of
      S -> shell_default:c(S,Opts++[{outdir,filename:dirname(beam(M))}])
       catch error: E -> E
       end;
   O -> O
    end.

src(Module) ->
    proplists:get_value(source,
         proplists:get_value(compile,
                   Module:module_info())).
beam(Module) ->
    code:which(Module).


And I have a structure with:
test
test/src
test/ebin

But when I compile a file it will just be put in the folder that I'm currently at. So it dosen't seem to work for me. Any idea?
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number
happi
Posted: Tue Jul 25, 2006 7:34 pm Reply with quote
Joined: 07 Nov 2005 Posts: 6 Location: Sweden
Ludvig wrote:

[...] when I compile a file it will just be put in the folder that I'm currently at. So it dosen't seem to work for me. Any idea?

It only works for re-compiling the file, i.e. you need to have it compiled with make once first (it looks at the path of the old beam file to find out where to put the new one.
View user's profile Send private message Visit poster's website
Ludvig
Posted: Wed Jul 26, 2006 7:33 am Reply with quote
User Joined: 20 Jul 2006 Posts: 38 Location: London
Hmm, okay. I will try it out again. But will this user_default override the existing c function or do I have to do something special to use it? like user_default:c(blaa)?
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum