Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Now
require
is not an alias ofsource
aymore.source
, like in bash, imports a script and gives it fullaccess to the global environment.
require
instead imports the script, but does not allow itto read or set variables at the global level. If a required
scripts needs to "pass" variables to the caller, it can simply
return
them and they will be available to th caller.Example -- say this is our module,
ip-finder.abs
:Then we can simply use it like this:
I have also made an important change while we wait for modules and the ABS package manager to be implemented (cc @mingwho): I've made
require(...)
use paths that are relative to the current script, just like in NodeJS etc.To illustrate the problem:
Say that A imports B, and B imports C. If you use
source
, B will have to usesource("./dir/C")
as source paths are always relative to the initial execution context.With
require
B instead canrequire("C")
since the import path is always relative to the current script. When @mingwho works on the installer, we'll have to tweak how we locate the required script making sure we can include installed modules.With these changes, I've also gotten rid of the
globalEnv
variable which is a global we use to access the main ABS execution environment. I replaced it making sure that the env is being passed around as needed.