module reloading

classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

module reloading

Alex Alvarez-4
Sorry if this was already asked and I missed it...  While using v20.3.2, after I load a module...

11> l(math).
{module,math}

...if I try to reload it again with the same command...

12> l(math).

=ERROR REPORT==== 13-Apr-2018::13:09:15 ===
Can't load module 'math' that resides in sticky dir
{error,sticky_directory}

...I get this error message. It's not particular to any module.  From the error, there seems to be a problem with a stcky bit somewhere.  Although I don't remember having this problem before, who knows, maybe it's just my install.  Has anyone run into this issue recently?

Thanks,
Alex

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: module reloading

bengt e
Greetings,

This is one explanation of *sticky directory*:
http://erlang.org/pipermail/erlang-questions/2002-October/005908.html


bengt

On 13 Apr 2018, at 19:13, Alex Alvarez <[hidden email]> wrote:

Sorry if this was already asked and I missed it...  While using v20.3.2, after I load a module...

11> l(math).
{module,math}

...if I try to reload it again with the same command...

12> l(math).

=ERROR REPORT==== 13-Apr-2018::13:09:15 ===
Can't load module 'math' that resides in sticky dir
{error,sticky_directory}

...I get this error message. It's not particular to any module.  From the error, there seems to be a problem with a stcky bit somewhere.  Although I don't remember having this problem before, who knows, maybe it's just my install.  Has anyone run into this issue recently?

Thanks,
Alex
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: module reloading

Joe Armstrong-2
In reply to this post by Alex Alvarez-4
The module called 'math' is a pre-defined system module, and
redefining it might have
unpleasant and unpredictable consequences - so you really should not
do this unless you
know exactly what you are doing. Best is to just change the name.

If you know what you're doing you can call unstick_dir on the
directory where math.beam was loaded from
and then you will be able to change the code - again this is not a
good idea if you don't
really understand the consequences of doing this.

System modules are 'sticky' by default to stop you from accidentally
shooting yourself in the foot.

If you get this warning just change the module name.

Cheers

/Joe

On Fri, Apr 13, 2018 at 7:13 PM, Alex Alvarez <[hidden email]> wrote:

> Sorry if this was already asked and I missed it...  While using v20.3.2,
> after I load a module...
>
> 11> l(math).
> {module,math}
>
> ...if I try to reload it again with the same command...
>
> 12> l(math).
>
> =ERROR REPORT==== 13-Apr-2018::13:09:15 ===
> Can't load module 'math' that resides in sticky dir
> {error,sticky_directory}
>
> ...I get this error message. It's not particular to any module.  From the
> error, there seems to be a problem with a stcky bit somewhere.  Although I
> don't remember having this problem before, who knows, maybe it's just my
> install.  Has anyone run into this issue recently?
>
> Thanks,
> Alex
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: module reloading

Alex Alvarez-4
In reply to this post by bengt e
Thanks for your response and the referenced link!  What called my attention about this is that according to the c:help() function c:l() is for both loading and reloading.  Now, I see that from the documentation this is only the case if the given module (e.g., math) is marked/identified as old.  Hence, this reloading is only for module upgrades, as need be.  AFAIK now, then the only way to manually reload any module is to first use code:delete/1 and then c:l/1 again or code:load_file/1.  What do you know!  Then again, if you know of a one step way, please let me know.

Cheers,
Alex

On 4/15/2018 at 7:34 AM, "bengt" <[hidden email]> wrote:code:load_file
Greetings,

This is one explanation of *sticky directory*:
<a class="" target="_blank" href="http://erlang.org/pipermail/erlang-questions/2002-October/005908.html" onclick="window.open('http://erlang.org/pipermail/erlang-questions/2002-October/005908.html');return false;">http://erlang.org/pipermail/erlang-questions/2002-October/005908.html


bengt

On 13 Apr 2018, at 19:13, Alex Alvarez <[hidden email]> wrote:

Sorry if this was already asked and I missed it...  While using v20.3.2, after I load a module...

11> l(math).
{module,math}

...if I try to reload it again with the same command...

12> l(math).

=ERROR REPORT==== 13-Apr-2018::13:09:15 ===
Can't load module 'math' that resides in sticky dir
{error,sticky_directory}

...I get this error message. It's not particular to any module.  From the error, there seems to be a problem with a stcky bit somewhere.  Although I don't remember having this problem before, who knows, maybe it's just my install.  Has anyone run into this issue recently?

Thanks,
Alex
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: module reloading

Alex Alvarez-4
In reply to this post by Joe Armstrong-2
Thanks for your reply!  I can certainly understand that and appreciate the system would be letting me know if I was trying to do that.  But the issue is that I was not trying to load any code of mine with the same module name, I just tried reloading the same (e.g., math) module.

Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V9.3  (abort with ^G)
1> l(math).
{module,math}
2> l(math).
{error,sticky_directory}
3>
=ERROR REPORT==== 15-Apr-2018::22:09:00 ===
Can't load module 'math' that resides in sticky dir


As mentioned in my last email, the issue seems to be with the fact that the module was not marked old...

3> code:purge(math).
false

Now, I just thought that c:l() would load and reload any module regardless, but that doesn't seem to be the case.

http://erlang.org/doc/man/c.html#l-1
http://erlang.org/doc/man/code.html#purge-1

Thanks,
Alex


On 4/13/2018 at 4:26 PM, "Joe Armstrong" <[hidden email]> wrote:
The module called 'math' is a pre-defined system module, and
redefining it might have
unpleasant and unpredictable consequences - so you really should not
do this unless you
know exactly what you are doing. Best is to just change the name.

If you know what you're doing you can call unstick_dir on the
directory where math.beam was loaded from
and then you will be able to change the code - again this is not a
good idea if you don't
really understand the consequences of doing this.

System modules are 'sticky' by default to stop you from accidentally
shooting yourself in the foot.

If you get this warning just change the module name.

Cheers

/Joe

On Fri, Apr 13, 2018 at 7:13 PM, Alex Alvarez <[hidden email]> wrote:

> Sorry if this was already asked and I missed it... While using v20.3.2,
> after I load a module...
>
> 11> l(math).
> {module,math}
>
> ...if I try to reload it again with the same command...
>
> 12> l(math).
>
> =ERROR REPORT==== 13-Apr-2018::13:09:15 ===
> Can't load module 'math' that resides in sticky dir
> {error,sticky_directory}
>
> ...I get this error message. It's not particular to any module. From the
> error, there seems to be a problem with a stcky bit somewhere. Although I
> don't remember having this problem before, who knows, maybe it's just my
> install. Has anyone run into this issue recently?
>
> Thanks,
> Alex
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: module reloading

Joe Armstrong-2
I see :-)

But why I ask do you do "l(math)" ?

This loads or reloads a module - but modules are autoloaded on demand
the first time the module
is called, so really there is almost [1] no need to do ever do this.

Cheers

/Joe

[1] there is actually but the use cases are rather obscure




On Mon, Apr 16, 2018 at 4:24 AM, Alex Alvarez <[hidden email]> wrote:

> Thanks for your reply!  I can certainly understand that and appreciate the
> system would be letting me know if I was trying to do that.  But the issue
> is that I was not trying to load any code of mine with the same module name,
> I just tried reloading the same (e.g., math) module.
>
> Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:2:2] [ds:2:2:10]
> [async-threads:10] [hipe] [kernel-poll:false]
>
> Eshell V9.3  (abort with ^G)
> 1> l(math).
> {module,math}
> 2> l(math).
> {error,sticky_directory}
> 3>
> =ERROR REPORT==== 15-Apr-2018::22:09:00 ===
> Can't load module 'math' that resides in sticky dir
>
> As mentioned in my last email, the issue seems to be with the fact that the
> module was not marked old...
>
> 3> code:purge(math).
> false
>
> Now, I just thought that c:l() would load and reload any module regardless,
> but that doesn't seem to be the case.
>
> http://erlang.org/doc/man/c.html#l-1
> http://erlang.org/doc/man/code.html#purge-1
>
> Thanks,
> Alex
>
>
>
> On 4/13/2018 at 4:26 PM, "Joe Armstrong" <[hidden email]> wrote:
>
> The module called 'math' is a pre-defined system module, and
> redefining it might have
> unpleasant and unpredictable consequences - so you really should not
> do this unless you
> know exactly what you are doing. Best is to just change the name.
>
> If you know what you're doing you can call unstick_dir on the
> directory where math.beam was loaded from
> and then you will be able to change the code - again this is not a
> good idea if you don't
> really understand the consequences of doing this.
>
> System modules are 'sticky' by default to stop you from accidentally
> shooting yourself in the foot.
>
> If you get this warning just change the module name.
>
> Cheers
>
> /Joe
>
> On Fri, Apr 13, 2018 at 7:13 PM, Alex Alvarez <[hidden email]> wrote:
>> Sorry if this was already asked and I missed it... While using v20.3.2,
>> after I load a module...
>>
>> 11> l(math).
>> {module,math}
>>
>> ...if I try to reload it again with the same command...
>>
>> 12> l(math).
>>
>> =ERROR REPORT==== 13-Apr-2018::13:09:15 ===
>> Can't load module 'math' that resides in sticky dir
>> {error,sticky_directory}
>>
>> ...I get this error message. It's not particular to any module. From the
>> error, there seems to be a problem with a stcky bit somewhere. Although I
>> don't remember having this problem before, who knows, maybe it's just my
>> install. Has anyone run into this issue recently?
>>
>> Thanks,
>> Alex
>>
>> _______________________________________________
>> erlang-questions mailing list
>> [hidden email]
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: module reloading

Alex Alvarez-4
Thanks Joe!  LOL!!!  Might sound silly, but it's very useful to be able to load/reload modules manually.  At the very least, it'd be great to at least get something like {error, module_loaded}, instead of the current "error report" message

Ok, so, why don't I just enter a <module name>:<function name> and allow the module to autoload.  That's great for source code, but not that great in the command line.  The problem is that I, as I suppose most folks, don't know the function names (or even a function name) in every module, which is why I tend to manually load them when I'm in Erlang's REPL.  As we know, once a module is loaded, you can type the module name, press the <TAB> key and get a list of the function names + arity.  This is very powerful. If you don't know the exact name of a function, but do know the name of a few modules where it might be, you can try loading them, pressing <TAB> and see if you can find it before having to consult the documentation.

Thanks,
Alex


On 4/16/2018 at 9:55 AM, "Joe Armstrong" <[hidden email]> wrote:
I see :-)

But why I ask do you do "l(math)" ?

This loads or reloads a module - but modules are autoloaded on demand
the first time the module
is called, so really there is almost [1] no need to do ever do this.

Cheers

/Joe

[1] there is actually but the use cases are rather obscure




On Mon, Apr 16, 2018 at 4:24 AM, Alex Alvarez <[hidden email]> wrote:

> Thanks for your reply! I can certainly understand that and appreciate the
> system would be letting me know if I was trying to do that. But the issue
> is that I was not trying to load any code of mine with the same module name,
> I just tried reloading the same (e.g., math) module.
>
> Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:2:2] [ds:2:2:10]
> [async-threads:10] [hipe] [kernel-poll:false]
>
> Eshell V9.3 (abort with ^G)
> 1> l(math).
> {module,math}
> 2> l(math).
> {error,sticky_directory}
> 3>
> =ERROR REPORT==== 15-Apr-2018::22:09:00 ===
> Can't load module 'math' that resides in sticky dir
>
> As mentioned in my last email, the issue seems to be with the fact that the
> module was not marked old...
>
> 3> code:purge(math).
> false
>
> Now, I just thought that c:l() would load and reload any module regardless,
> but that doesn't seem to be the case.
>
> http://erlang.org/doc/man/c.html#l-1
> http://erlang.org/doc/man/code.html#purge-1
>
> Thanks,
> Alex
>
>
>
> On 4/13/2018 at 4:26 PM, "Joe Armstrong" <[hidden email]> wrote:
>
> The module called 'math' is a pre-defined system module, and
> redefining it might have
> unpleasant and unpredictable consequences - so you really should not
> do this unless you
> know exactly what you are doing. Best is to just change the name.
>
> If you know what you're doing you can call unstick_dir on the
> directory where math.beam was loaded from
> and then you will be able to change the code - again this is not a
> good idea if you don't
> really understand the consequences of doing this.
>
> System modules are 'sticky' by default to stop you from accidentally
> shooting yourself in the foot.
>
> If you get this warning just change the module name.
>
> Cheers
>
> /Joe
>
> On Fri, Apr 13, 2018 at 7:13 PM, Alex Alvarez <[hidden email]> wrote:
>> Sorry if this was already asked and I missed it... While using v20.3.2,
>> after I load a module...
>>
>> 11> l(math).
>> {module,math}
>>
>> ...if I try to reload it again with the same command...
>>
>> 12> l(math).
>>
>> =ERROR REPORT==== 13-Apr-2018::13:09:15 ===
>> Can't load module 'math' that resides in sticky dir
>> {error,sticky_directory}
>>
>> ...I get this error message. It's not particular to any module. From the
>> error, there seems to be a problem with a stcky bit somewhere. Although I
>> don't remember having this problem before, who knows, maybe it's just my
>> install. Has anyone run into this issue recently?
>>
>> Thanks,
>> Alex
>>
>> _______________________________________________
>> erlang-questions mailing list
>> [hidden email]
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: module reloading

Brujo Benavides-3
Well... You might not realize but you do know _a_ function: your_module:module_info/0 always exists, for every module ;)

Also... Just trying to evaluate _any_ function, loads the module. That's why instead of loading modules manually, when in the shell, I tend to write the module name and :, press tab, if nothing pops up, I type x(). and press enter. Either the module loads and I have autocomplete next time I press tab, or I can't load the module.

I bet one day I'll find a module that defines x/0 and I will be in trouble...

On Tue, 17 Apr 2018 at 19:18 Alex Alvarez <[hidden email]> wrote:
Thanks Joe!  LOL!!!  Might sound silly, but it's very useful to be able to load/reload modules manually.  At the very least, it'd be great to at least get something like {error, module_loaded}, instead of the current "error report" message

Ok, so, why don't I just enter a <module name>:<function name> and allow the module to autoload.  That's great for source code, but not that great in the command line.  The problem is that I, as I suppose most folks, don't know the function names (or even a function name) in every module, which is why I tend to manually load them when I'm in Erlang's REPL.  As we know, once a module is loaded, you can type the module name, press the <TAB> key and get a list of the function names + arity.  This is very powerful. If you don't know the exact name of a function, but do know the name of a few modules where it might be, you can try loading them, pressing <TAB> and see if you can find it before having to consult the documentation.

Thanks,
Alex



On 4/16/2018 at 9:55 AM, "Joe Armstrong" <[hidden email]> wrote:
I see :-)

But why I ask do you do "l(math)" ?

This loads or reloads a module - but modules are autoloaded on demand
the first time the module
is called, so really there is almost [1] no need to do ever do this.

Cheers

/Joe

[1] there is actually but the use cases are rather obscure




On Mon, Apr 16, 2018 at 4:24 AM, Alex Alvarez <[hidden email]> wrote:

> Thanks for your reply! I can certainly understand that and appreciate the
> system would be letting me know if I was trying to do that. But the issue
> is that I was not trying to load any code of mine with the same module name,
> I just tried reloading the same (e.g., math) module.
>
> Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:2:2] [ds:2:2:10]
> [async-threads:10] [hipe] [kernel-poll:false]
>
> Eshell V9.3 (abort with ^G)
> 1> l(math).
> {module,math}
> 2> l(math).
> {error,sticky_directory}
> 3>
> =ERROR REPORT==== 15-Apr-2018::22:09:00 ===
> Can't load module 'math' that resides in sticky dir
>
> As mentioned in my last email, the issue seems to be with the fact that the
> module was not marked old...
>
> 3> code:purge(math).
> false
>
> Now, I just thought that c:l() would load and reload any module regardless,
> but that doesn't seem to be the case.
>
> http://erlang.org/doc/man/c.html#l-1
> http://erlang.org/doc/man/code.html#purge-1
>
> Thanks,
> Alex
>
>
>
> On 4/13/2018 at 4:26 PM, "Joe Armstrong" <[hidden email]> wrote:
>
> The module called 'math' is a pre-defined system module, and
> redefining it might have
> unpleasant and unpredictable consequences - so you really should not
> do this unless you
> know exactly what you are doing. Best is to just change the name.
>
> If you know what you're doing you can call unstick_dir on the
> directory where math.beam was loaded from
> and then you will be able to change the code - again this is not a
> good idea if you don't
> really understand the consequences of doing this.
>
> System modules are 'sticky' by default to stop you from accidentally
> shooting yourself in the foot.
>
> If you get this warning just change the module name.
>
> Cheers
>
> /Joe
>
> On Fri, Apr 13, 2018 at 7:13 PM, Alex Alvarez <[hidden email]> wrote:
>> Sorry if this was already asked and I missed it... While using v20.3.2,
>> after I load a module...
>>
>> 11> l(math).
>> {module,math}
>>
>> ...if I try to reload it again with the same command...
>>
>> 12> l(math).
>>
>> =ERROR REPORT==== 13-Apr-2018::13:09:15 ===
>> Can't load module 'math' that resides in sticky dir
>> {error,sticky_directory}
>>
>> ...I get this error message. It's not particular to any module. From the
>> error, there seems to be a problem with a stcky bit somewhere. Although I
>> don't remember having this problem before, who knows, maybe it's just my
>> install. Has anyone run into this issue recently?
>>
>> Thanks,
>> Alex
>>
>> _______________________________________________
>> erlang-questions mailing list
>> [hidden email]
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
--
elbrujohalcon @ iPhone

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: module reloading

Alex Alvarez-4
Thanks for your response!  I did find interesting the <module name>:<type any word>() trick.  Didn't know about it!

Thanks,
Alex

On 4/17/2018 at 9:27 PM, "Fernando Benavides" <[hidden email]> wrote:
Well... You might not realize but you do know _a_ function: your_module:module_info/0 always exists, for every module ;)

Also... Just trying to evaluate _any_ function, loads the module. That's why instead of loading modules manually, when in the shell, I tend to write the module name and :, press tab, if nothing pops up, I type x(). and press enter. Either the module loads and I have autocomplete next time I press tab, or I can't load the module.

I bet one day I'll find a module that defines x/0 and I will be in trouble...

On Tue, 17 Apr 2018 at 19:18 Alex Alvarez <[hidden email]> wrote:
Thanks Joe!  LOL!!!  Might sound silly, but it's very useful to be able to load/reload modules manually.  At the very least, it'd be great to at least get something like {error, module_loaded}, instead of the current "error report" message

Ok, so, why don't I just enter a <module name>:<function name> and allow the module to autoload.  That's great for source code, but not that great in the command line.  The problem is that I, as I suppose most folks, don't know the function names (or even a function name) in every module, which is why I tend to manually load them when I'm in Erlang's REPL.  As we know, once a module is loaded, you can type the module name, press the <TAB> key and get a list of the function names + arity.  This is very powerful. If you don't know the exact name of a function, but do know the name of a few modules where it might be, you can try loading them, pressing <TAB> and see if you can find it before having to consult the documentation.

Thanks,
Alex



On 4/16/2018 at 9:55 AM, "Joe Armstrong" <[hidden email]> wrote:
I see :-)

But why I ask do you do "l(math)" ?

This loads or reloads a module - but modules are autoloaded on demand
the first time the module
is called, so really there is almost [1] no need to do ever do this.

Cheers

/Joe

[1] there is actually but the use cases are rather obscure




On Mon, Apr 16, 2018 at 4:24 AM, Alex Alvarez <[hidden email]> wrote:

> Thanks for your reply! I can certainly understand that and appreciate the
> system would be letting me know if I was trying to do that. But the issue
> is that I was not trying to load any code of mine with the same module name,
> I just tried reloading the same (e.g., math) module.
>
> Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:2:2] [ds:2:2:10]
> [async-threads:10] [hipe] [kernel-poll:false]
>
> Eshell V9.3 (abort with ^G)
> 1> l(math).
> {module,math}
> 2> l(math).
> {error,sticky_directory}
> 3>
> =ERROR REPORT==== 15-Apr-2018::22:09:00 ===
> Can't load module 'math' that resides in sticky dir
>
> As mentioned in my last email, the issue seems to be with the fact that the
> module was not marked old...
>
> 3> code:purge(math).
> false
>
> Now, I just thought that c:l() would load and reload any module regardless,
> but that doesn't seem to be the case.
>
> <a target="_blank" href="http://erlang.org/doc/man/c.html#l-1" onclick="window.open('http://erlang.org/doc/man/c.html#l-1');return false;">http://erlang.org/doc/man/c.html#l-1
> <a target="_blank" href="http://erlang.org/doc/man/code.html#purge-1" onclick="window.open('http://erlang.org/doc/man/code.html#purge-1');return false;">http://erlang.org/doc/man/code.html#purge-1
>
> Thanks,
> Alex
>
>
>
> On 4/13/2018 at 4:26 PM, "Joe Armstrong" <[hidden email]> wrote:
>
> The module called 'math' is a pre-defined system module, and
> redefining it might have
> unpleasant and unpredictable consequences - so you really should not
> do this unless you
> know exactly what you are doing. Best is to just change the name.
>
> If you know what you're doing you can call unstick_dir on the
> directory where math.beam was loaded from
> and then you will be able to change the code - again this is not a
> good idea if you don't
> really understand the consequences of doing this.
>
> System modules are 'sticky' by default to stop you from accidentally
> shooting yourself in the foot.
>
> If you get this warning just change the module name.
>
> Cheers
>
> /Joe
>
> On Fri, Apr 13, 2018 at 7:13 PM, Alex Alvarez <[hidden email]> wrote:
>> Sorry if this was already asked and I missed it... While using v20.3.2,
>> after I load a module...
>>
>> 11> l(math).
>> {module,math}
>>
>> ...if I try to reload it again with the same command...
>>
>> 12> l(math).
>>
>> =ERROR REPORT==== 13-Apr-2018::13:09:15 ===
>> Can't load module 'math' that resides in sticky dir
>> {error,sticky_directory}
>>
>> ...I get this error message. It's not particular to any module. From the
>> error, there seems to be a problem with a stcky bit somewhere. Although I
>> don't remember having this problem before, who knows, maybe it's just my
>> install. Has anyone run into this issue recently?
>>
>> Thanks,
>> Alex
>>
>> _______________________________________________
>> erlang-questions mailing list
>> [hidden email]
>> <a target="_blank" href="http://erlang.org/mailman/listinfo/erlang-questions" onclick="window.open('http://erlang.org/mailman/listinfo/erlang-questions');return false;">http://erlang.org/mailman/listinfo/erlang-questions
>>
_______________________________________________
erlang-questions mailing list
[hidden email]
<a target="_blank" href="http://erlang.org/mailman/listinfo/erlang-questions" onclick="window.open('http://erlang.org/mailman/listinfo/erlang-questions');return false;">http://erlang.org/mailman/listinfo/erlang-questions
--
elbrujohalcon @ iPhone

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: module reloading

Per Hedeland
In reply to this post by Brujo Benavides-3
On 2018-04-18 03:27, Fernando Benavides wrote:
>
> Also... Just trying to evaluate _any_ function, loads the module. That's why instead of loading modules manually, when in the shell, I tend to write the module name and :, press tab, if nothing pops
> up, I type x(). and press enter.

I tend to do the same, even down to the "arbitrary function name", but
it *is* rather quirky, and there is a hint for an obvious and probably
straightforward-to-implement (I haven't looked at the relevant code)
enhancement in your description: why not have the sequence <name>:<TAB>
do a code:ensure_loaded(<name>) before it (tries to) look up the
function list?

> I bet one day I'll find a module that defines x/0 and I will be in trouble...

That too.:-)

--Per Hedeland
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: module reloading

Per Hedeland
On 2018-04-18 08:05, Per Hedeland wrote:

> On 2018-04-18 03:27, Fernando Benavides wrote:
>>
>> Also... Just trying to evaluate _any_ function, loads the module. That's why instead of loading modules manually, when in the shell, I tend to write the module name and :, press tab, if nothing pops
>> up, I type x(). and press enter.
>
> I tend to do the same, even down to the "arbitrary function name", but
> it *is* rather quirky, and there is a hint for an obvious and probably
> straightforward-to-implement (I haven't looked at the relevant code)
> enhancement in your description: why not have the sequence <name>:<TAB>
> do a code:ensure_loaded(<name>) before it (tries to) look up the
> function list?

OK, so I looked at the code, and the change (see below) is so trivial
that there is probably a good reason it doesn't already do that - I
don't know what that reason might be though...

--Per

diff --git a/lib/stdlib/src/edlin_expand.erl b/lib/stdlib/src/edlin_expand.erl
index bdcefda..4b3e0cc 100644
--- a/lib/stdlib/src/edlin_expand.erl
+++ b/lib/stdlib/src/edlin_expand.erl
@@ -49,8 +49,8 @@ expand_module_name(Prefix) ->
  expand_function_name(ModStr, FuncPrefix) ->
      case to_atom(ModStr) of
  {ok, Mod} ->
-    case erlang:module_loaded(Mod) of
- true ->
+    case code:ensure_loaded(Mod) of
+ {module, Mod} ->
     L = Mod:module_info(),
     case lists:keyfind(exports, 1, L) of
  {_, Exports} ->
@@ -58,7 +58,7 @@ expand_function_name(ModStr, FuncPrefix) ->
  _ ->
     {no, [], []}
     end;
- false ->
+ {error, _What} ->
     {no, [], []}
     end;
  error ->
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Fwd: module reloading

Attila Rajmund Nohl
2018-04-18 8:28 GMT+02:00 Per Hedeland <[hidden email]>:
[...]

OK, so I looked at the code, and the change (see below) is so trivial
that there is probably a good reason it doesn't already do that - I
don't know what that reason might be though...

​If someone accidentally mistypes a module name (to an other, existing module name), it might be unwise to load that different module​. Especially that the different module might have some code that executes at load time...




_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: module reloading

Joe Armstrong-2
In reply to this post by Alex Alvarez-4
On Wed, Apr 18, 2018 at 12:18 AM, Alex Alvarez <[hidden email]> wrote:

> Thanks Joe!  LOL!!!  Might sound silly, but it's very useful to be able to
> load/reload modules manually.  At the very least, it'd be great to at least
> get something like {error, module_loaded}, instead of the current "error
> report" message
>
> Ok, so, why don't I just enter a <module name>:<function name> and allow the
> module to autoload.  That's great for source code, but not that great in the
> command line.  The problem is that I, as I suppose most folks, don't know
> the function names (or even a function name) in every module, which is why I
> tend to manually load them when I'm in Erlang's REPL.

I have the same problem - so I say

   > m('modname').

Which autoloads the module if it's not loaded and prints a list of the
functions in the module. After this <TAB> expansion works.

This has non of the problems you've see with load :-)

/Joe



>  As we know, once a
> module is loaded, you can type the module name, press the <TAB> key and get
> a list of the function names + arity.  This is very powerful. If you don't
> know the exact name of a function, but do know the name of a few modules
> where it might be, you can try loading them, pressing <TAB> and see if you
> can find it before having to consult the documentation.
>
> Thanks,
> Alex
>
>
>
> On 4/16/2018 at 9:55 AM, "Joe Armstrong" <[hidden email]> wrote:
>
> I see :-)
>
> But why I ask do you do "l(math)" ?
>
> This loads or reloads a module - but modules are autoloaded on demand
> the first time the module
> is called, so really there is almost [1] no need to do ever do this.
>
> Cheers
>
> /Joe
>
> [1] there is actually but the use cases are rather obscure
>
>
>
>
> On Mon, Apr 16, 2018 at 4:24 AM, Alex Alvarez <[hidden email]> wrote:
>> Thanks for your reply! I can certainly understand that and appreciate the
>> system would be letting me know if I was trying to do that. But the issue
>> is that I was not trying to load any code of mine with the same module
>> name,
>> I just tried reloading the same (e.g., math) module.
>>
>> Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:2:2] [ds:2:2:10]
>> [async-threads:10] [hipe] [kernel-poll:false]
>>
>> Eshell V9.3 (abort with ^G)
>> 1> l(math).
>> {module,math}
>> 2> l(math).
>> {error,sticky_directory}
>> 3>
>> =ERROR REPORT==== 15-Apr-2018::22:09:00 ===
>> Can't load module 'math' that resides in sticky dir
>>
>> As mentioned in my last email, the issue seems to be with the fact that
>> the
>> module was not marked old...
>>
>> 3> code:purge(math).
>> false
>>
>> Now, I just thought that c:l() would load and reload any module
>> regardless,
>> but that doesn't seem to be the case.
>>
>> http://erlang.org/doc/man/c.html#l-1
>> http://erlang.org/doc/man/code.html#purge-1
>>
>> Thanks,
>> Alex
>>
>>
>>
>> On 4/13/2018 at 4:26 PM, "Joe Armstrong" <[hidden email]> wrote:
>>
>> The module called 'math' is a pre-defined system module, and
>> redefining it might have
>> unpleasant and unpredictable consequences - so you really should not
>> do this unless you
>> know exactly what you are doing. Best is to just change the name.
>>
>> If you know what you're doing you can call unstick_dir on the
>> directory where math.beam was loaded from
>> and then you will be able to change the code - again this is not a
>> good idea if you don't
>> really understand the consequences of doing this.
>>
>> System modules are 'sticky' by default to stop you from accidentally
>> shooting yourself in the foot.
>>
>> If you get this warning just change the module name.
>>
>> Cheers
>>
>> /Joe
>>
>> On Fri, Apr 13, 2018 at 7:13 PM, Alex Alvarez <[hidden email]> wrote:
>>> Sorry if this was already asked and I missed it... While using v20.3.2,
>>> after I load a module...
>>>
>>> 11> l(math).
>>> {module,math}
>>>
>>> ...if I try to reload it again with the same command...
>>>
>>> 12> l(math).
>>>
>>> =ERROR REPORT==== 13-Apr-2018::13:09:15 ===
>>> Can't load module 'math' that resides in sticky dir
>>> {error,sticky_directory}
>>>
>>> ...I get this error message. It's not particular to any module. From the
>>> error, there seems to be a problem with a stcky bit somewhere. Although I
>>> don't remember having this problem before, who knows, maybe it's just my
>>> install. Has anyone run into this issue recently?
>>>
>>> Thanks,
>>> Alex
>>>
>>> _______________________________________________
>>> erlang-questions mailing list
>>> [hidden email]
>>> http://erlang.org/mailman/listinfo/erlang-questions
>>>
>
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: module reloading

Joe Armstrong-2
In reply to this post by Per Hedeland
You're on the sticky slope to DWIM :-)

/Joe

On Wed, Apr 18, 2018 at 8:28 AM, Per Hedeland <[hidden email]> wrote:

> On 2018-04-18 08:05, Per Hedeland wrote:
>>
>> On 2018-04-18 03:27, Fernando Benavides wrote:
>>>
>>>
>>> Also... Just trying to evaluate _any_ function, loads the module. That's
>>> why instead of loading modules manually, when in the shell, I tend to write
>>> the module name and :, press tab, if nothing pops up, I type x(). and press
>>> enter.
>>
>>
>> I tend to do the same, even down to the "arbitrary function name", but
>> it *is* rather quirky, and there is a hint for an obvious and probably
>> straightforward-to-implement (I haven't looked at the relevant code)
>> enhancement in your description: why not have the sequence <name>:<TAB>
>> do a code:ensure_loaded(<name>) before it (tries to) look up the
>> function list?
>
>
> OK, so I looked at the code, and the change (see below) is so trivial
> that there is probably a good reason it doesn't already do that - I
> don't know what that reason might be though...
>
> --Per
>
> diff --git a/lib/stdlib/src/edlin_expand.erl
> b/lib/stdlib/src/edlin_expand.erl
> index bdcefda..4b3e0cc 100644
> --- a/lib/stdlib/src/edlin_expand.erl
> +++ b/lib/stdlib/src/edlin_expand.erl
> @@ -49,8 +49,8 @@ expand_module_name(Prefix) ->
>  expand_function_name(ModStr, FuncPrefix) ->
>      case to_atom(ModStr) of
>         {ok, Mod} ->
> -           case erlang:module_loaded(Mod) of
> -               true ->
> +           case code:ensure_loaded(Mod) of
> +               {module, Mod} ->
>                     L = Mod:module_info(),
>                     case lists:keyfind(exports, 1, L) of
>                         {_, Exports} ->
> @@ -58,7 +58,7 @@ expand_function_name(ModStr, FuncPrefix) ->
>                         _ ->
>                             {no, [], []}
>                     end;
> -               false ->
> +               {error, _What} ->
>                     {no, [], []}
>             end;
>         error ->
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: module reloading

Per Hedeland
In reply to this post by Per Hedeland
On 2018-04-18 13:19, Attila Rajmund Nohl wrote:

> 2018-04-18 8:28 GMT+02:00 Per Hedeland <[hidden email] <mailto:[hidden email]>>:
> [...]
>
>
>     OK, so I looked at the code, and the change (see below) is so trivial
>     that there is probably a good reason it doesn't already do that - I
>     don't know what that reason might be though...
>
>
> If someone accidentally mistypes a module name (to an other, existing module name), it might be unwise to load that different module . Especially that the different module might have some code that
> executes at load time...

Well, yes, but there's lots of damage you can do by accidental
mistyping... And if you want to be able to get function-name completion
*at all* for a not-yet-loaded module, you will *have* to type its name,
hopefully correctly. See also the workaround for the lack of
auto-loading on completion-request that Fernando described earlier - I
suspect we're not alone in using it, and it's actually worse than
accidentally just loading the wrong module, since it also attempts to
call a function in the module...

--Per
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: module reloading

Alex Alvarez-4
In reply to this post by Per Hedeland
That's awesome!  Thanks; I'll try the patch out!

Cheers,
Alex

On 4/18/2018 at 2:28 AM, "Per Hedeland" <[hidden email]> wrote:
On 2018-04-18 08:05, Per Hedeland wrote:

> On 2018-04-18 03:27, Fernando Benavides wrote:
>>
>> Also... Just trying to evaluate _any_ function, loads the module. That's why instead of loading modules manually, when in the shell, I tend to write the module name and :, press tab, if nothing pops
>> up, I type x(). and press enter.
>
> I tend to do the same, even down to the "arbitrary function name", but
> it *is* rather quirky, and there is a hint for an obvious and probably
> straightforward-to-implement (I haven't looked at the relevant code)
> enhancement in your description: why not have the sequence <name>:<TAB>
> do a code:ensure_loaded(<name>) before it (tries to) look up the
> function list?

OK, so I looked at the code, and the change (see below) is so trivial
that there is probably a good reason it doesn't already do that - I
don't know what that reason might be though...

--Per

diff --git a/lib/stdlib/src/edlin_expand.erl b/lib/stdlib/src/edlin_expand.erl
index bdcefda..4b3e0cc 100644
--- a/lib/stdlib/src/edlin_expand.erl
+++ b/lib/stdlib/src/edlin_expand.erl
@@ -49,8 +49,8 @@ expand_module_name(Prefix) ->
expand_function_name(ModStr, FuncPrefix) ->
case to_atom(ModStr) of
{ok, Mod} ->
- case erlang:module_loaded(Mod) of
- true ->
+ case code:ensure_loaded(Mod) of
+ {module, Mod} ->
L = Mod:module_info(),
case lists:keyfind(exports, 1, L) of
{_, Exports} ->
@@ -58,7 +58,7 @@ expand_function_name(ModStr, FuncPrefix) ->
_ ->
{no, [], []}
end;
- false ->
+ {error, _What} ->
{no, [], []}
end;
error ->
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: module reloading

Alex Alvarez-4
In reply to this post by Joe Armstrong-2
Thanks!  That definitely also works!

Cheers,
Alex

On 4/18/2018 at 7:25 AM, "Joe Armstrong" <[hidden email]> wrote:
On Wed, Apr 18, 2018 at 12:18 AM, Alex Alvarez <[hidden email]> wrote:

> Thanks Joe! LOL!!! Might sound silly, but it's very useful to be able to
> load/reload modules manually. At the very least, it'd be great to at least
> get something like {error, module_loaded}, instead of the current "error
> report" message
>
> Ok, so, why don't I just enter a <module name>:<function name> and allow the
> module to autoload. That's great for source code, but not that great in the
> command line. The problem is that I, as I suppose most folks, don't know
> the function names (or even a function name) in every module, which is why I
> tend to manually load them when I'm in Erlang's REPL.

I have the same problem - so I say

> m('modname').

Which autoloads the module if it's not loaded and prints a list of the
functions in the module. After this <TAB> expansion works.

This has non of the problems you've see with load :-)

/Joe



> As we know, once a
> module is loaded, you can type the module name, press the <TAB> key and get
> a list of the function names + arity. This is very powerful. If you don't
> know the exact name of a function, but do know the name of a few modules
> where it might be, you can try loading them, pressing <TAB> and see if you
> can find it before having to consult the documentation.
>
> Thanks,
> Alex
>
>
>
> On 4/16/2018 at 9:55 AM, "Joe Armstrong" <[hidden email]> wrote:
>
> I see :-)
>
> But why I ask do you do "l(math)" ?
>
> This loads or reloads a module - but modules are autoloaded on demand
> the first time the module
> is called, so really there is almost [1] no need to do ever do this.
>
> Cheers
>
> /Joe
>
> [1] there is actually but the use cases are rather obscure
>
>
>
>
> On Mon, Apr 16, 2018 at 4:24 AM, Alex Alvarez <[hidden email]> wrote:
>> Thanks for your reply! I can certainly understand that and appreciate the
>> system would be letting me know if I was trying to do that. But the issue
>> is that I was not trying to load any code of mine with the same module
>> name,
>> I just tried reloading the same (e.g., math) module.
>>
>> Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:2:2] [ds:2:2:10]
>> [async-threads:10] [hipe] [kernel-poll:false]
>>
>> Eshell V9.3 (abort with ^G)
>> 1> l(math).
>> {module,math}
>> 2> l(math).
>> {error,sticky_directory}
>> 3>
>> =ERROR REPORT==== 15-Apr-2018::22:09:00 ===
>> Can't load module 'math' that resides in sticky dir
>>
>> As mentioned in my last email, the issue seems to be with the fact that
>> the
>> module was not marked old...
>>
>> 3> code:purge(math).
>> false
>>
>> Now, I just thought that c:l() would load and reload any module
>> regardless,
>> but that doesn't seem to be the case.
>>
>> http://erlang.org/doc/man/c.html#l-1
>> http://erlang.org/doc/man/code.html#purge-1
>>
>> Thanks,
>> Alex
>>
>>
>>
>> On 4/13/2018 at 4:26 PM, "Joe Armstrong" <[hidden email]> wrote:
>>
>> The module called 'math' is a pre-defined system module, and
>> redefining it might have
>> unpleasant and unpredictable consequences - so you really should not
>> do this unless you
>> know exactly what you are doing. Best is to just change the name.
>>
>> If you know what you're doing you can call unstick_dir on the
>> directory where math.beam was loaded from
>> and then you will be able to change the code - again this is not a
>> good idea if you don't
>> really understand the consequences of doing this.
>>
>> System modules are 'sticky' by default to stop you from accidentally
>> shooting yourself in the foot.
>>
>> If you get this warning just change the module name.
>>
>> Cheers
>>
>> /Joe
>>
>> On Fri, Apr 13, 2018 at 7:13 PM, Alex Alvarez <[hidden email]> wrote:
>>> Sorry if this was already asked and I missed it... While using v20.3.2,
>>> after I load a module...
>>>
>>> 11> l(math).
>>> {module,math}
>>>
>>> ...if I try to reload it again with the same command...
>>>
>>> 12> l(math).
>>>
>>> =ERROR REPORT==== 13-Apr-2018::13:09:15 ===
>>> Can't load module 'math' that resides in sticky dir
>>> {error,sticky_directory}
>>>
>>> ...I get this error message. It's not particular to any module. From the
>>> error, there seems to be a problem with a stcky bit somewhere. Although I
>>> don't remember having this problem before, who knows, maybe it's just my
>>> install. Has anyone run into this issue recently?
>>>
>>> Thanks,
>>> Alex
>>>
>>> _______________________________________________
>>> erlang-questions mailing list
>>> [hidden email]
>>> http://erlang.org/mailman/listinfo/erlang-questions
>>>
>
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions