-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking PR for 1.8.x #271
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Now `require` is not an alias of `source` aymore. `source`, like in bash, imports a script and gives it full access to the global environment. `require` instead imports the script, but does not allow it to 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`: ``` return f() { return `curl icanhazip.com` } ``` Then we can simply use it like this: ``` ip_finder = require("ip-finder.abs") echo("My IP is %s", ip_finder()) ```
This PR adds support for negative indexes in arrays / strings. ``` bash [1,2,3][-1] #3 ``` There is one change that might alter existing ABS scripts, and that's non-existing indexes, for strings, returning an empty string rather than `null`. I believe it's an ok thing to break as both will evaluate to `false` when casted to boolean, and to check whether an index exists one can simply: * check the length of the string (`s.len()`) * check the boolean value of the index (`!!s[idx]`) both these examples do not break with these changes. I instead admit that it would be weird to see code such as: ``` bash if s[idx] == null { ... } ``` rather than ``` if !s[idx] { ... } ``` So I guess this is a change that can go through, as it really shouldn't impact much of the userbase.
We have been operating a fork due to #265
Now you can embed variables inside strings by prefixing them with `$`. Literal `$` simply need a `\`. This aligns the string interpolation syntax with commands, and makes it easier to switch between running a command (`` `$some $command` ``) and echoing it (`echo("$some $command")`).
Arrays can now easily be formatted as TSV / CSV content: ``` array.tsv() array.tsv(",") ``` Here are some samples: ``` ⧐ [["LeBron", "James"], ["James", "Harden"]].tsv() LeBron James James Harden ⧐ [{"name": "Lebron", "last": "James", "jersey": 23}, {"name": "James", "last": "Harden"}].tsv("\t", ["name", "last", "jersey", "additional_key"]) name last jersey additional_key Lebron James 23 null James Harden null null ``` There is some complexity in this function due to the fact that we have to support custom headers, as well as the fact that we can both format arrays of objects as well as hashes.
* if the package file is not present, calls to `require` shouldn't fail * a package `user/package` might contain different abs files (eg. `user/package/file.abs`). When we resolve calls to `require("package/file.abs")` we should only take `package`, and not the whole `package/file.abs` * saving aliases was only working for the first package installed, now the installer will save all modules that are being installed locally * when including a module, if a file is not specified (`require("module")`), we will try to load the `index.abs` file by default
… with a .abs file
@abs-lang/contributors this is going to get released tomorrow. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
/cc @abs-lang/contributors