Goby - Yet another programming language written in Go
This version contains many new APIs, bug fixes and internal refactorings.
Array.new(args)
- https://github.com/goby-lang/goby/pull/832
Object#rand
- https://github.com/goby-lang/goby/pull/819
Object#sql?
- https://github.com/goby-lang/goby/pull/843
Class#define_method
- https://github.com/goby-lang/goby/pull/842
Object#define_singleton_method
- https://github.com/goby-lang/goby/pull/842
Float
APIs - https://github.com/goby-lang/goby/pull/664 (thanks to @SD10)
#abs
#cel
#floor
#round
#positive?
#negative?
#zero?
before
and after
callback to Spec
library - https://github.com/goby-lang/goby/pull/835
#inspect
instead of #to_s
when generating error messages - https://github.com/goby-lang/goby/pull/836
=~
is now deprecated. Please use String#match?
instead. - https://github.com/goby-lang/goby/pull/802
This version contains 1 new API and fixes a few issues. The rest of the changes were for internal polishing.
Object#dup
- https://github.com/goby-lang/goby/pull/791
object_id
returning arbitrary number issue - https://github.com/goby-lang/goby/pull/796
Object#tap
- @st0012Object#inspect
- @mweitzelObject#kind_of?
- @284kmArray#sort
- @st0012Array#index_with
- @hachi8833Integer#time
now returns an Enumerator - @st0012The overall performance is now 2x faster and object allocations and memory usage are reduced to half.
benchmarking e22beaebdea18ea8670d98d56f4e4f39eed444e8
benchmarking 587f1c8dadd5adec3c16642ae3133504682f4d5c
go get: warning: modules disabled by GO111MODULE=auto in GOPATH/src;
ignoring go.mod;
see 'go help modules'
x86_64-darwin18
benchmark old ns/op new ns/op delta
BenchmarkBasicMath/add-4 5650 3357 -40.58%
BenchmarkBasicMath/subtract-4 5592 2740 -51.00%
BenchmarkBasicMath/multiply-4 5687 2786 -51.01%
BenchmarkBasicMath/divide-4 5661 2757 -51.30%
benchmark old allocs new allocs delta
BenchmarkBasicMath/add-4 75 33 -56.00%
BenchmarkBasicMath/subtract-4 75 33 -56.00%
BenchmarkBasicMath/multiply-4 75 33 -56.00%
BenchmarkBasicMath/divide-4 75 33 -56.00%
benchmark old bytes new bytes delta
BenchmarkBasicMath/add-4 3152 1568 -50.25%
BenchmarkBasicMath/subtract-4 3152 1568 -50.25%
BenchmarkBasicMath/multiply-4 3152 1568 -50.25%
BenchmarkBasicMath/divide-4 3152 1568 -50.25%
Big thanks to @eliothedeman for the significant improvement 🎉
There are a lot of refactoring/code reorganization/bug fixes in this version as well. They’re mainly done by @hachi8833, @ear7h and @saveriomiroddi
Compare to the first commit (d5f5fc
) that introduces the benchmark
benchmarking d5f5fc591bdbd3cd8f35cfe4e753f977478eecf8
benchmarking e22beaebdea18ea8670d98d56f4e4f39eed444e8
x86_64-darwin17
benchmark old ns/op new ns/op delta
BenchmarkBasicMath/add-4 7178 5299 -26.18%
BenchmarkBasicMath/subtract-4 7185 5336 -25.73%
BenchmarkBasicMath/multiply-4 7185 5298 -26.26%
BenchmarkBasicMath/divide-4 7158 5292 -26.07%
benchmark old allocs new allocs delta
BenchmarkBasicMath/add-4 78 75 -3.85%
BenchmarkBasicMath/subtract-4 78 75 -3.85%
BenchmarkBasicMath/multiply-4 78 75 -3.85%
BenchmarkBasicMath/divide-4 78 75 -3.85%
benchmark old bytes new bytes delta
BenchmarkBasicMath/add-4 3792 3152 -16.88%
BenchmarkBasicMath/subtract-4 3792 3152 -16.88%
BenchmarkBasicMath/multiply-4 3792 3152 -16.88%
BenchmarkBasicMath/divide-4 3792 3152 -16.88%
Module
- #681Result
- #675Object#respond_to?
- #651Integer#to_d
- #649Class#method_missing
- #672Class#inherits_method_missing
- #676Class#Constants
- #686Object#print
- #694Now you can use built-in test framework: spec
to write specs for Goby program! For example:
require "spec"
Spec.describe Spec do
describe "comparison" do
describe "#to eq" do
it "compares if two values are equal" do
expect(1).to eq(1)
end
end
describe "#not_to eq" do
it "compares if two values are not equal" do
expect(1).not_to eq(2)
end
end
end
describe "indentation" do
it "indents four spaces" do
end
describe "nest another level" do
it "indents six spaces" do
end
end
end
end
And to run the spec, use goby test FILE_OR_DIRECTORY_PATH
.
Then it will run the spec and print the output like:
Spec
comparison
#to eq
it "compares if two values are equal"
#not_to eq
it "compares if two values are not equal"
indentation
it "indents four spaces"
nest another level
it "indents six spaces"
Thanks to @ear7h, this is a feature that does not exist in Ruby but now in Goby! Take the following code as an example:
sum = 0
(2..-9).step(3) do |i|
sum = sum + i
end
puts(sum)
In Ruby it returns 0
cause it does not support descending range.
But in Goby it will return -10
😁
The major fix is to make splat parameter returns an empty array instead of nil
when no argument is passed.
def foo(*x)
x
end
# before fix
foo #=> nil
# after fix
foo #=> []
String
's range indexings = "Hello!"
puts(s[1..3]) #=> ell
For example, to test
def add(x, y)
x + y
end
We can now write it like:
firstStmt := program.FirstStmt().IsDefStmt(t)
firstStmt.ShouldHasName("add")
firstStmt.ShouldHasNormalParam("x")
firstStmt.ShouldHasNormalParam("y")
firstExpression := firstStmt.MethodBody().NthStmt(1).IsExpression(t)
infixExp := firstExpression.IsInfixExpression(t)
infixExp.ShouldHasOperator("+")
infixExp.TestableLeftExpression().IsIdentifier(t).ShouldHasName("x")
infixExp.TestableRightExpression().IsIdentifier(t).ShouldHasName("y")
See #604
t.Helper()
to test helper functionsget_block
: let you retrieve a block as an objectbreak
: break current loop or block executionArray#lazy
Array#to_enum
Object#raise
Range#lazy
Range#map
Range#to_enum
LazyEnumerator
ArrayEnumerator
RangeEnumerator
then
keywordFloat
GoMap
Decimal
MatchData
Regex
Concurrent::Array
Concurrent::Hash
Concurrent::RWLock
_
for unused variable1.0
Foo()
++
+=
or -=
syntactic sugars~=
operatorFile
is now builtin class instead of standard library now