ok

command module
v0.17.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2020 License: MIT Imports: 11 Imported by: 0

README

GitHub release Build Status codecov

ok is a strongly-duck-typed language. It has the rigidness of a strongly typed language with more runtime flexibility and simplified . See Why Go? for language highlights, or if you just want to browse some examples head over to Learn By Example.

func main() {
    print("hello world")
}

It is heavily inspired by Go, especially around how interfaces are implicit. However, ok takes this one step further by merging the concepts of a struct and interface into a func declaration. This idea is not new, but it means that all cases where a instance is expected actually is an implicit interface.

func Person(Name string) Person {
    func Greeting() string {
        return "Hello, " + ^Name
    }
}

func Impersonator() Impersonator {
    Name = "Secret Agent"

    func Greeting() string {
        return "Hello, Joe Bloggs"
    }
}

func SayHello(p Person) {
    print(p.Greeting())
}

func main() {
    SayHello(Person("Joe Bloggs"))

    // Impersonator satisfies the interface of a Person, so we can use that
    // implicitly instead:
    SayHello(Impersonator())
}

Having all inputs being implicit interfaces makes testing really easy and flexible. Also, ok treats testing as a first-class citizen with syntax:

// add.ok
func add(a, b number) number {
    return a + b
}
// add.okt
test "adding some numbers" {
    assert(add(3, 5) == 8)
    assert(add(3, 5) == 10)
}
$ ok test
add: add.okt:2:4: adding some numbers: assert(8 == 10) failed
add: 1 failed 0 passed 2 asserts (0ms)

For more language features and examples, check out Learn By Example.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
ast
Package ast provides structures for representing parsed source code.
Package ast provides structures for representing parsed source code.
cmd
asm
doc
run
Package compiler translates the ast structures that represent the parsed course code into instructions that can be executed by the VM.
Package compiler translates the ast structures that represent the parsed course code into instructions that can be executed by the VM.
Package lexer converts source code into tokens.
Package lexer converts source code into tokens.
Package number contains the implementation of the number data type.
Package number contains the implementation of the number data type.
Package parser translates the linear stream of tokens into ast structures based on the syntax of the ok language.
Package parser translates the linear stream of tokens into ast structures based on the syntax of the ok language.
Package instruction contains all the instructions created by the compiler and executed by the VM.
Package instruction contains all the instructions created by the compiler and executed by the VM.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL