Skip to content

@odino odino released this May 12, 2021

A fresh new minor release of ABS: always be shipping! 🚢

Added a negative membership operator !in

Earlier, you could test membership with x in list, but in order to negate that expression you had to !(x in list) which is quite verbose.
We now added in #412 the !in operator to make things simpler: x !in list, it behaves just like python's not in.

Module cache

Every time you required a module, you'd always get a fresh instance of it, which would cause some funny behaviors:

$ require('@runtime').name = "xxx"
$ require('@runtime').name
abs

We now (#428) cache modules as soon as they are required, so the next time you require them you will receive the same instance you've required before:

$ require('@runtime').name = "xxx"
$ require('@runtime').name
xxx

This only applies to require and not source, as source is intended to be used in order to always evaluate a block of fresh code in the current environment.

Specify your own shell

In #429 we added the ability to execute commands with any shell, not just bash -c.

You can now specify a different shell to execute system commands with through ABS_COMMAND_EXECUTOR:

`echo \$0` # bash
env("ABS_COMMAND_EXECUTOR", "sh -c")
`echo \$0` # sh
Assets 11

@odino odino released this Mar 30, 2021

A fresh new patch release of ABS: always be shipping! 🚢

Fixed parsing of numbers and their sign

By solving #409, we bring a little more stability and less funkiness in ABS' parser.

The way ABS used to parse prefixes (eg. -5) was kind of wonky:
we would dump in a token the whole prefix + number (-5) vs
parsing them separately and build the AST according to where
the minus token is found. This change makes it so -5 is actually
(-)(5).

Problems with the previous approach:

  • inconsistent behavior between x = 5; -x and -5
  • -5 would be treated differently than - 5
  • code such as 1 -1 would be parsed as (1); (-1), producing 2
    statements. The return value would be -1 rather than 0

In general, I looked around and the common behavior is to read
tokens separately and, while parsing, figure out, based on their
position, what precedence they should have. This is what this PR
fundamentally does.

For example:

  • when - is a prefix (-2), it should have the highest precedence over
    any other operator. For example, -2.clamp(0, 1) should interpret as
    (-2).clamp(0, 1)
  • when - is not a prefix, it can fallback to its usual precedence (eg.
    less than * or /)

Thie behavior is also consistent with other, languages, take ruby as an
example:

irb(main):011:0> -1.clamp(0, 10)
=> 0

One way in which ABS now deviates with other implementations
is that, since we do not bother reading whitespaces etc in our lexer
-1.clamp(0, 10) and - 1.clamp(0, 10) are exactly the same (while
in ruby, for example, the latter is intepreted as (-)(1.clamp(0, 10))). I think for now this is a reasonable compromise, but I'm open
to change this behavior in subsequent versions of ABS.

This PR also fixes a couple additional issues:

  • +2 is now a valid number, earlier we only considered - as the only
    valid prefix for numbers
  • there could be instances where an infinite loop would be triggered
    because of ABS parsing x +y as x; +y; where the return value is just
    +y. A for loop written like this would have triggered the bug: decr = f(x) {x -1}; for x = 0; x > -10; x = decr(x). It would only happen on for loops where our looper is decrementing
Assets 11

@odino odino released this Feb 17, 2021

A fresh new patch release of ABS: always be shipping! 🚢

Upgrade to Go 1.16

Go 1.16 was released yesterday and ABS gets updated quickly 🙂

There are no major changes in the platform, but sometimes it's all about housekeeping! 🧹 ☁️

Assets 11

@odino odino released this Sep 28, 2020

A fresh new minor release of ABS: always be shipping! 🚢

array.shuffle()

We've introduced a new array.shuffle() function:

⧐  [1,2,3,4,5].shuffle()
[4, 5, 3, 2, 1]

array.reverse() operates on a copy of an array

We're in the process of making sure that functions that mutate arrays always operate on a copy of the array. This is somewhat of a breaking change but it also introduces an "expected" behavior (we align with Ruby here). You can expect other updates, in ABS 1.5, to align other array / string functions to this behavior.

Prior to this change:

a = [1,2,3,4,5]
⧐  a.reverse()
[5, 4, 3, 2, 1]
⧐  a
[5, 4, 3, 2, 1]

After this change:

a = [1,2,3,4,5]
⧐  a.reverse()
[5, 4, 3, 2, 1]
⧐  a
[1, 2, 3, 4, 5]

If you have older code that relies on mutating arrays in-place, you could migrate from x.reverse() to x = x.reverse().

Assets 11

@odino odino released this Aug 25, 2020

A fresh bugfix for ABS!

#402 fixes a nasty bug with silent returns (return statements without a value, which default to NULL).

The PR fixes them and adds some more sophisticated tests. A return without a value, when interpreted before this PR, would terminate the script without executing the rest of the code.

This snippet:

if false {
	return
}
return 3

would return NULL instead of 3.

Assets 11

@odino odino released this Aug 14, 2020

A fresh new minor release of ABS: always be shipping! 🚢

ABS allows you to check whether you should upgrade 😄

When you run the REPL with abs, it will periodically print whether there's a new release you should upgrade to (#392):

$ abs
Hello user, welcome to the ABS (2.2.2) programming language!
*** Update available: 2.3.0 (your version is 2.2.2) ***
Type 'quit' when you're done, 'help' if you get lost!
⧐  

A new command has also been added if you want to explicitly check for a new version:

$ abs --check-update 
Update available: 2.3.0 (your version is 2.2.2)

Upgrade to Go 1.15

ABS is now built with Go 1.15 (#397). As a result, we dropped support for darwin/386 (#396).

The REPL used to suppress output when ending with a comment

A fairly annoying behavior (#388) we fixed by discarding comments right at the lexer's level (#394).

A big thank you to @gromgit who's the main contributor behind this release -- see ya! 👋

Assets 11

@odino odino released this Jul 28, 2020

This release fixes a bug with parsing negative numbers (#385): before, -10 would be parsed as (minus, number) whereas
right now it's going to be parsed as (number) only.

This fixes a bug with precedences, where -1.str() would be parsed as (-, (1, str)), leading to first calling the str method on the positive number, then applying the minus.

Before:

⧐  -1.234.str()
ERROR: unknown operator: -STRING
	[1:1]	-1.234.str()

After:

⧐  -1.234.str()
-1.234

If a space is found between the minus and the number, the old parsing mechanism still applies.

It's inspired by Ruby, where:

$ - 1.to_s()
-@: undefined method `-@' for "1":String

$-1.to_s()
-1

$ -10.3.floor()
-11

$ - 10.3.floor()
-10

In addition, the documentation for strings has been improved (#384).

Thanks to @gromgit both for finding the bug as well as improving the documentation ❤️

Assets 12

@odino odino released this Jul 7, 2020

This is a bugfix release that fixes a bug in the @util.memoize decorator. Earlier, the decorator used a shared in-memory map for all functions, meaning that 2 different functions with the same arguments would collide and memoize each other's results (#379).

Assets 12

@odino odino released this Jul 6, 2020

A fresh new minor release of ABS: always be shipping! 🚢

Interactive REPL through the @cli module

The @cli.repl() mode allows to run interactive REPLs based on the commands registered within the CLI:

cli = require('@cli')

res = {"count": 0}

@cli.cmd("count", "prints a counter", {})
f counter(arguments, flags) {
    echo(res.count)
}

@cli.cmd("incr", "Increment our counter", {})
f incr(arguments, flags) {
    res.count += 1
    return "ok"
}

@cli.cmd("incr_by", "Increment our counter", {})
f incr_by(arguments, flags) {
    echo("Increment by how much?")
    n = stdin().number()
    res.count += n
    return "ok"
}

cli.repl()

You can see it in action:

$ ./cli
help
Available commands:

  * count - prints a counter
  * help - print this help message
  * incr - Increment our counter
  * incr_by - Increment our counter
count
0
incr
ok
incr
ok
count
2
incr_by
Increment by how much?
-10
ok
count
-8

Memoizing through @util.memoize

A new @util native module was introduced to allow memoization of functions:

memo = require('@util').memoize

@memo(60)
f long_task(x, y) {
    sleep(1000)
    return "done"
}

echo(long_task(1, 1)) # waits 1s
echo(long_task(1, 1)) # immediate
echo(long_task(1, 1)) # immediate
sleep(61000) # sleep for a min...
echo(long_task(1, 1)) # waits 1s
echo(long_task(1, 2)) # waits 1s

New function: unix_ms

unix_ms() returns the current Unix epoch, in milliseconds.

unix_ms() # 1594049453157

See ya! 👋

Assets 12

@odino odino released this May 13, 2020

A fresh new minor release of ABS: always be shipping! 🚢

Optional function parameters

You can now make a parameter optional by specifying its
default value:

f greet(name, greeting = "hello") {
    echo("$greeting $name!")
}
greet("user") # hello user!
greet("user", "hola") # hola user!

A default value can be any expression (doesn't have to be a literal):

f test(x = 1){x}; test() # 1
f test(x = "test".split("")){x}; test() # ["t", "e", "s", "t"]
f test(x = {}){x}; test() # {}
y = 100; f test(x = y){x}; test() # 100
x = 100; f test(x = x){x}; test() # 100
x = 100; f test(x = x){x}; test(1) # 1

Note that mandatory arguments always need to be declared
before optional ones:

f(x = null, y){}
# parser errors:
# 	found mandatory parameter after optional one
# 	[1:13]	f(x = null, y){}

Descending number ranges

Number ranges (x..y) now support generating ranges in descending order:

3..1 # [3, 2, 1]

See ya! 👋

Assets 12