Currently module does not overwrite existing values (for security reasons).
It works like:
>> m: module [name: test][ export my-func: does[print "hello"]]
>> m/my-func
hello
>> my-func ;<- will error because module was not imported yet
** Script error: my-func has no value
>> import m
>> my-func ;<- now `my-func` is in user's but also `lib` contexts
hello
>> lib/my-func
hello
;-- one must unset it in both contexts
;-- and also remove module from list of existing modules
>> remove/part find system/modules 'test 3 unset 'my-func unset in lib 'my-func
>> import module [name: test][ export my-func: does[print "hello again"]]
>> my-func
hello again
One can simplify it a little bit using private
flag and version
:
>> import module [name: test version: 1.0.0 options: [private]][export my-func: does[print "hello"]]
>> lib/my-func ;<- will error, because module is private
** Script error: cannot access my-func in path lib/my-func
>> my-func ;<- but it is still in user's context
hello
>> unset 'my-func
>> import module [name: test version: 1.0.1 options: [private]][export my-func: does[print "hello again"]]
>> my-func
hello again
It's also possible to write a function for module unloading (although it may not work in all cases)
unload-module: function[module [word!]][
m: system/modules/:module
unless m [ exit ]
e: select spec-of m 'exports
forall e [
print ["Unsetting:" e/1]
try [unset in system/contexts/user e/1]
try [unset in system/contexts/lib e/1]
]
remove/part find system/modules module 3
m
]
; than:
>> import module [name: test][export my-func: does[print "hello"]]
>> my-func
hello
>> unload-module 'test
Unsetting: my-func
>> import module [name: test][export my-func: does[print "hello again"]]
>> my-func
hello again