Skip to content
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
merged 19 commits into from
Sep 20, 2019
Merged

Tracking PR for 1.8.x #271

merged 19 commits into from
Sep 20, 2019

Conversation

odino
Copy link
Collaborator

@odino odino commented Aug 20, 2019

/cc @abs-lang/contributors

@odino odino added this to the 1.8.x milestone Aug 20, 2019
odino and others added 18 commits August 25, 2019 21:18
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
@odino
Copy link
Collaborator Author

odino commented Sep 18, 2019

@abs-lang/contributors this is going to get released tomorrow.

@odino odino merged commit c4636fe into master Sep 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants