Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Credits: The Gauntlet programming language and this accompanying documentation were written solely by TricolorHen061.
Gauntlet is in it's alpha phase. Please expect (and !) bugs.
Non-parser error messages are do not contain line numbers. This will be implemented in a future update.
There is little typechecking. Better typechecking will be implemented in the future.
All Gauntlet type names are the CamelCase version of it's corresponding Go type name. For instance:
String type in Gauntlet -> string type in Golang
Float64 type in Gauntlet -> float64 type in Golang
The only two exceptions to the above rule are:
Unit, which is equivalent to ()
Null, which is equivalent to nil
You can import and use any library from the Golang ecosystem without writing a binding. Though at this point in time, Gauntlet does not perform type-checking on them.
When referring to a function from a module, use camelCase to refer to it. Use PascalCase for everything else.
Anything wrapped in <> signifies a required placeholder
Anything wrapped in [] signifies an optional placeholder
The type of casing that should be used is reflected in placeholder names. For instance, if something LooksLikeThis , it means PascalCase should be used.
Join the Discord server
Take a look at the GitHub repository
Check out the Visual Studio Code extension
Generics
Syntax: [TypeConstraint ParamName, ...]
Example: [T : String, U: Any]
Int type in Guantlet -> int type in Golang
GenericsInstantiation
Syntax: [Type1, Type2, ...]
Example: [String, Int]
Parameters
Syntax: ParamName : ParamType, ...
Example: num1 : Int, num2 : Int
varPattern
Syntax: varName1, varName2, etc
Example: firstName, lastName
To transpile Gauntlet code to Go code, simply provide the target .gaunt file. If no errors are found, Gauntlet will put your transpiled code in a .go file (in the same folder as your Gauntlet one) with the corresponding name. In the example below, the file name is MyTestFile.gaunt, which means MyTestFile.go will contain the resulting code.
You can run your transpiled code immediately after it's created by utilizing the run command.
By default, your transpiled code will be formatted with go fmt. If, for some reason, you don't want this, you can stop it from happening with the --no-format flag.
-OR-
./gauntlet MyTestFile.gaunt.\gauntlet.exe MyTestFile.gaunt./gauntlet MyTestFile.gaunt run .\gauntlet MyTestFile.gaunt run ./gauntlet MyTestFile.gaunt run --no-format.\gauntlet MyTestFile.gaunt run --no-format./gauntlet MyTestFile.gaunt --no-format.\gauntlet MyTestFile.gaunt --no-formatFor the sake of organization, it's recommended that you make a Gauntlet folder (e.g. Gauntlet test) to put the gauntlet executable in, along with your .gaunt files.
Go must be installed on your computer for Gauntlet to work
Linux, Windows, and MacOS are supported
Be sure to download the most recent version
Rename the file you just downloaded to gauntlet for easy access
You can use your file manager to do this
Mark the file as executable (only required on Linux and MacOS)
chmod +x gauntlet
Move to PATH for universal access (optional)
There are plenty of articles online for how you can do this for your respective OS
Gauntlet is a programming language made to tackle Golang’s most frustrating design choices. It transpiles exclusively to Go, fully supports all of its features, and integrates seamlessly with its entire ecosystem — without the need for bindings.
Annoying "unused variable" error
Verbose error handling (if err ≠ nil everywhere in your code)
Annoying way to import and export (e.g. capitalizing letters to export)
Lack of ternary operator
Transpiles to maintainable, easy-to-read Golang
Interoperates with entire Go ecosystem. No bindings required.
Consistent and familiar syntax
Near-instant conversion to Go
Gauntlet is in the alpha phase - meaning it has just been released without thorough testing. As such, it will inevitably contain bugs. If you run into one, please open an issue on the .
Because I snapped Go's issues out of existence
Complicated for-loops
Weird assignment operator (whose idea was it to use :=)
No way to fluently pipe functions
Easy install with a singular self-contained executable
Beautiful syntax highlighting on Visual Studio Code
Shares exact conventions/idioms with Golang. Virtually no learning curve.


package main
import "fmt" as fmt
fun main(): Unit {
let a, b, c: Int = (1, 2, 3)
let myName = "Bobby"
fmt.println(myName)
zero myZeroVar: Int
fmt.println("The number below should be 0, since it's Int's 'zero' value:")
fmt.println(myZeroVar)
}package main
import fmt "fmt"
func main() {
var a, b, c int = 1, 2, 3
myName := "Bobby"
fmt.Println(myName)
var myZeroVar int
fmt.Println("The number below should be 0, since it's Int's 'zero' value:")
fmt.Println(myZeroVar)
// Eliminates any 'unused variable' errors
_, _, _, _, _ = a, b, c, myName, myZeroVar
}
package main
import "fmt" as fmt
const PI = 3.14
const MY_NAME = "Bob"
fun main(): Unit {
fmt.println("My name is " + MY_NAME + ". And pi is approximately:")
fmt.println(PI)
}package main
import fmt "fmt"
const pI = 3.14
const mY_NAME = "Bob"
func main() {
fmt.Println("My name is " + mY_NAME + ". And pi is approximately:")
fmt.Println(pI)
}
let <varPattern> [: TypeName] = <expression>zero <varPattern>: <TypeName>Bobby
The number below should be 0, since it's Int's 'zero' value:
0My name is Bob. And pi is approximately:
3.14Welcome to the official documentation for the Gauntlet Programming Language.
Gauntlet was made so you can overcome Golang's frustrating design choices. Have a look:
package main
// Seamless interop with the entire golang ecosystem
import "fmt" as fmt
import "os" as os
import "strings" as strings
import "strconv" as strconv
// Explicit export keyword
Like what you see? Hit the "Introduction To Gauntlet" button below.
[exported] fun <functionName>[Generics]([Parameters]): <ReturnType> {
<function body>
}For syntax of Generics and Parameters - Common placeholders throughout documentation
package main
import fmt "fmt"
import os "os"
import strings "strings"
import strconv "strconv"
func GetTrimmedFileLines(fileName string) ([]string, error) {
fileContent, err := os.ReadFile(fileName)
if err != nil {
return nil, err
}
fileContentStrVersion := string(fileContent)
trimmedLines := strings.Split(strings.TrimSpace(fileContentStrVersion), "\n")
// Eliminates any 'unused variable' errors
_, _, _, _ = err, fileContent, fileContentStrVersion, trimmedLines
return trimmedLines, nil
}
func main() {
a := 1
lines, err := GetTrimmedFileLines("example.txt")
if err != nil {
panic(err)
}
properWord := (func() string {
if len(lines) > 1 {
return "lines"
}
return "line"
})()
stringLength := strconv.Itoa(len(lines))
fmt.Println("There are " + stringLength + " " + properWord + ".")
fmt.Println("Here they are:")
for i, line := range lines {
fmt.Println("Line " + strconv.Itoa(i+1) + " is:")
fmt.Println(line)
// Eliminates any 'unused variable' errors
_, _ = i, line
}
// Eliminates any 'unused variable' errors
_, _, _, _, _ = a, err, lines, properWord, stringLength
}
Whats
the
meaning
of
lifeThere are 5 lines.
Here they are:
Line 1 is:
Whats
Line 2 is:
the
Line 3 is:
meaning
Line 4 is:
of
Line 5 is:
lifeswitch typeof <expr> {
case <Type> : {
<case body>
}
case <Type> : {
<case body>
}
// The default case is optional
default : {
<default case body>
}
}select {
case <expr> : {
<case body>
}
// or, you can declare variable(s)
case let <varPattern> = <expr> : {
<case body>
}
// default is optional
default: {
<case body>
}
}package main
import fmt "fmt"
func main() {
ch1 := make(chan string, 1)
ch2 := make(chan string, 1)
ch1 <- "Hello from ch1"
var msg string
var ok bool
select {
case msg, ok := <-ch1:
{
if ok {
fmt.Println("Case 1:", msg)
} else {
fmt.Println("ch1 closed")
}
// Eliminates any 'unused variable' errors
_, _ = msg, ok
}
case <-ch2:
{
fmt.Println("Case 2: received from ch2")
}
default:
{
fmt.Println("Default case: nothing ready")
}
}
// Eliminates any 'unused variable' errors
_, _, _, _ = ch1, ch2, msg, ok
}
if <expr> {
<if statement body>
}
elif <expr> {
<else if statement body>
}
else {
<else statement body>
}package main
import fmt "fmt"
func main() {
isInRelationship := false
isProgrammer := true
if isProgrammer && !isInRelationship {
fmt.Println("Makes sense")
} else if !isProgrammer && isInRelationship {
fmt.Println("Makes sense")
} else if !isProgrammer && !isInRelationship {
fmt.Println("It's ok, it won't be hard for you to find a relationship")
} else {
fmt.Println("Stop lying")
}
// Eliminates any 'unused variable' errors
_, _ = isInRelationship, isProgrammer
}
Evaluating the result of (1 + 2) - 1 ...
It's two
And also...
1 is an Int!package main
import "fmt" as fmt
fun Unit main() {
fmt.println("Counting to 10...")
for let a = 1; a <= 10; a++ {
fmt.println(a)
}
fmt.println("Done!")
}package main
import fmt "fmt"
func main() {
fmt.Println("Counting to 10...")
for a := 1; a <= 10; a++ {
fmt.Println(a)
// Eliminates any 'unused variable' errors
_ = a
}
fmt.Println("Done!")
}
package main
import "fmt" as fmt
import "golang.org/x/exp/constraints" as constraints
fun isOver[T: constraints.Integer](a: T, b: T): Bool {
return a > b
}
fun createGreeting(firstName: String, lastName: String): String {
return "Hello " + firstName + " " + lastName + "!"
}
fun main(): Unit {
let age = 28
let firstName = "John"
let lastName = "Doe"
let greeting = createGreeting(firstName, lastName)
let isAdult = isOver(age, 18)
fmt.println("Greeting:")
fmt.println(greeting)
fmt.println("Adult Status:")
fmt.println(isAdult)
}package main
import "fmt" as fmt
fun Unit main() {
let result = (1 + 2) - 1
fmt.println("Evaluating the result of (1 + 2) - 1 ...")
switch result {
case 1: {
fmt.println("It's one")
}
case 2: {
fmt.println("It's two")
}
case 3: {
fmt.println("It's three")
}
default: {
fmt.println("It's not one, two, or three.")
}
}
fmt.println("And also...")
let Any a = 1
switch typeof a {
case String: {
fmt.println("1 is a String!")
}
case Int: {
fmt.println("1 is an Int!")
}
}
}package main
import fmt "fmt"
func main() {
result := (1 + 2) - 1
fmt.Println("Evaluating the result of (1 + 2) - 1 ...")
switch result {
case 1:
{
fmt.Println("It's one")
}
case 2:
{
fmt.Println("It's two")
}
case 3:
{
fmt.Println("It's three")
}
default:
{
fmt.Println("It's not one, two, or three.")
}
}
fmt.Println("And also...")
var a any = 1
switch a.(type) {
case string:
{
fmt.Println("1 is a String!")
}
case int:
{
fmt.Println("1 is an Int!")
}
}
// Eliminates any 'unused variable' errors
_, _ = a, result
}
for let <varPattern> = <expr>; <terminal expr>; <expr run after every iteration> {
<loop body>
} Counting to 10...
1
2
3
4
5
6
7
8
9
10
Done!for let <varPattern> in <iterable> {
<loop body>
}package main
import "fmt" as fmt
fun Unit main() {
fmt.println("Iterating through every letter in the word 'Hello'")
for let _, c in "Hello" {
fmt.println((String)(c))
}
fmt.println("Done!")
}package main
import fmt "fmt"
func main() {
fmt.Println("Iterating through every letter in the word 'Hello'")
for _, c := range "Hello" {
fmt.Println(string(c))
// Eliminates any 'unused variable' errors
_ = c
}
fmt.Println("Done!")
}
Iterating through every letter in the word 'Hello'
H
e
l
l
o
Done!for <terminal expr> {
<loop body>
}package main
import "fmt" as fmt
fun Unit main() {
fmt.println("The program will terminate if you say the magic word...")
let magicWord = "please"
zero String input
while input != magicWord {
fmt.println("What's the magic word?")
fmt.scan(&input)
}
fmt.println("You said it!")
}package main
import fmt "fmt"
func main() {
fmt.Println("The program will terminate if you say the magic word...")
magicWord := "please"
var input string
for {
if !(input != magicWord) {
break
}
fmt.Println("What's the magic word?")
fmt.Scan(&input)
}
fmt.Println("You said it!")
// Eliminates any 'unused variable' errors
_, _ = magicWord, input
}
The program will terminate if you say the magic word...
What's the magic word?
Gauntlet
What's the magic word?
Go
What's the magic word?
Life
What's the magic word?
please
You said it!Case 1: Hello from ch1package main
import fmt "fmt"
import constraints "golang.org/x/exp/constraints"
func isOver[T constraints.Integer](a T, b T) bool {
return a > b
}
func createGreeting(firstName string, lastName string) string {
return "Hello " + firstName + " " + lastName + "!"
}
func main() {
age := 28
firstName := "John"
lastName := "Doe"
greeting := createGreeting(firstName, lastName)
isAdult := isOver(age, 18)
fmt.Println("Greeting:")
fmt.Println(greeting)
fmt.Println("Adult Status:")
fmt.Println(isAdult)
// Eliminates any 'unused variable' errors
_, _, _, _, _ = age, firstName, greeting, isAdult, lastName
}
Greeting:
Hello John Doe!
Adult Status:
trueMakes senseGauntlet mirrors Go's package-based compilation model. As such, every file must start with package <name>.
Gauntlet's import syntax is:
It is required that you give an alias to every module you import.
Once you have imported it, you can use it like you normally would in Golang.
If you imported fmt as such:
Then you must access it using whatever is on the right side of the "as" keyword (fmt):
The main function is the entry point of every Gauntlet program; it is not required in every file. It must have a return type of Unit.
def <methodName>(<receiverParamName>: ReceiverType, Parameters): <ReturnType> {
<method body>
}For syntax of Parameters - Common placeholders throughout documentation
Methods can be implemented only on wrapper types and structs.
For syntax of Generics - Common placeholders throughout documentation
@<ReturnType> <test expr> ? <success value> : <failure value>[export] struct <StructName>[Generics] {
[export] <FieldName>: <FieldType> [`FieldTag`] // Syntax of fields
<EmbeddedInterfaces> // Syntax of embedded interfaces
<EmbeddedStructs> // Syntax of embedded structs
}<StructName>[GenericsInstantiation]{Field1 = Value1, etc}package main
import "fmt" as fmt
import "strconv" as strconv
struct Person {
FirstName: String
LastName: String
Money: Int
Happy: Bool
}
def getSummary(person: Person): String {
let fullName = person.FirstName + " " + person.LastName
return fullName + " has $" + strconv.Itoa(person.Money) + ". It is " + strconv.FormatBool(person.Happy) + " that he is happy."
}
fun main(): Unit {
let person = Person{FirstName = "John", LastName = "Doe", Money = 10000, Happy = true}
fmt.println(person.getSummary())
}package main
import "fmt" as fmt
import "golang.org/x/exp/constraints" as constraints
struct BankAccount[T : constraints.Integer] {
Retirement: T
Checking: T
Total: T
}
struct Human[T: constraints.Integer] {
export FullName: String
export Age: Int
BankAccount[T]
}
fun main(): Unit {
let age = 28
let firstName = "John"
let lastName = "Doe"
let fullName = firstName + " " + lastName
let john = Human[Int]{FullName = fullName, Age = age, BankAccount = BankAccount[Int]{Retirement = 100000, Checking = 1000, Total = 100000 + 1000}}
fmt.println("John's full name is:")
fmt.println(john.FullName)
fmt.println("In total, he has this much money:")
fmt.println(john.BankAccount.Total)
}package main
import "fmt" as fmt
alias Name = String
fun getGreeting(name: Name): String {
return "Hello, " + name + "!"
}
fun main(): Unit {
let myGreeting = getGreeting("Bob")
fmt.println(myGreeting)
}package main
import fmt "fmt"
type name = string
func getGreeting(name name) string {
return "Hello, " + name + "!"
}
func main() {
myGreeting := getGreeting("Bob")
fmt.Println(myGreeting)
// Eliminates any 'unused variable' errors
_ = myGreeting
}
Because it is true that I am a programmer, I am depressedimport "<modulename>" as <aliasname>import "fmt" as fmtfmt.println("Hello World!")package main
import "fmt" as fmt
fun main(): Unit {
fmt.println("Hello World!")
}package main
import fmt "fmt"
func main() {
fmt.Println("Hello World!")
}Hello World!package main
import fmt "fmt"
import strconv "strconv"
type person struct {
happy bool
money int
lastName string
firstName string
}
func (person person) getSummary() string {
fullName := person.firstName + " " + person.lastName
// Eliminates any 'unused variable' errors
_ = fullName
return fullName + " has $" + strconv.Itoa(person.money) + ". It is " + strconv.FormatBool(person.happy) + " that he is happy."
}
func main() {
person := person{firstName: "John", lastName: "Doe", money: 10000, happy: true}
fmt.Println(person.getSummary())
// Eliminates any 'unused variable' errors
_ = person
}
John Doe has $10000. It is true that he is happy.package main
import fmt "fmt"
import constraints "golang.org/x/exp/constraints"
type bankAccount[T constraints.Integer] struct {
total T
checking T
retirement T
}
type human[T constraints.Integer] struct {
Age int
FullName string
bankAccount[T]
}
func main() {
age := 28
firstName := "John"
lastName := "Doe"
fullName := firstName + " " + lastName
john := human[int]{FullName: fullName, Age: age, bankAccount: bankAccount[int]{retirement: 100000, checking: 1000, total: 100000 + 1000}}
fmt.Println("John's full name is:")
fmt.Println(john.FullName)
fmt.Println("In total, he has this much money:")
fmt.Println(john.bankAccount.total)
// Eliminates any 'unused variable' errors
_, _, _, _, _ = age, firstName, fullName, john, lastName
}
John's full name is:
John Doe
In total, he has this much money:
101000Hello, Bob!alias <AliasName> = <Type>package main
import "fmt" as fmt
import "strings" as strings
interface AcceptableAgeType {
| Int16 | Int32 |
}
struct Person
package main
import "fmt" as fmt
fun main(): Unit {
let myLambda = lambda (caps: Bool): String {
if caps {
return "HELLO"
package main
import fmt "fmt"
func main() {
myLambda := func(caps bool) string {
if caps {
return "HELLO"
New scopes cannot be used on the left side of the arrow. Only expressions can.
package main
import "fmt" as fmt
fun main(): Unit {
let language = "Gauntlet"
let reaction = when language @ String {
is "Gauntlet" -> "smiled"
package main
import fmt "fmt"
func main() {
language := "Gauntlet"
reaction := (func() string {
switch language {
case
expr |> someFunctionCall(<args with at least one underscore>)The pipe (|>) takes the expression on the left and "pipes" it into the function right, wherever there are underscores.
For every underscore you use, a new instance of the left-hand expression will be made. For instance, myExpr |> someFunction(_, _) turns into someFunction(myExpr, myExpr). This many result in unwanted side-effects.
This page documents the part of the language that were not "big" enough to warrant an entire page.
You can use an array literal to construct an array.
-OR-
You can use a slice literal to construct a slice.
Map literals can be used to construct maps
The indexing operator can be used on arrays, slices, strings, maps, and pointers to arrays
Slicing can only be done on strings, slices, and arrays
A force-statement evaluates the expr between force and with. It must evaluate to (..., error).
If error != nil:
The program will panic with the expr to the right of with
If error == nil:
expression between try and with will be destructured into successVar and failureVar
The below code will error, which is intended since force will call panic
<case expr> refers to any of the following:
An enum literal (e.g. Circle() in the below example)
Currently, you cannot pattern match on any field that is another enum literal. Support is currently being implemented for this.
A string (e.g. "hello")
An int (e.g. 30)
A decimal (e.g. 5.0)
A boolean (e.g. true)
A char (e.g. 'a')
[Support Coming Soon] Wildcard
[Support Coming Soon] Array literal (e.g. [2]string{"hello", "world"})
[Support Coming Soon] Slice literal (e.g. []string{"hello", "world"})
--OR--
The try-statement will evaluate the expression in-between try and with. Said expression must have a type of (..., error).
If error != nil: the expression to the right of with will be returned.
If error == nil:
If you're using the first syntax: Control flow will continue as normal
If you're using the second syntax: expression between try and with will be destructured into successVar and failureVar
package main
import fmt "fmt"
import strings "strings"
type acceptableAgeType interface {
int16 | int32
}
type person struct {
Age int16
LastName string
FirstName string
}
type greeter interface {
greet(punctuation string) string
person
}
type loudGreeter interface {
shout() string
greeter
}
func (name person) greet(punctuation string) {
fmt.Println("Greetings " + name.FirstName + " " + name.LastName + punctuation)
}
func (name person) shout() {
uppercaseFirstName := strings.ToUpper(name.FirstName)
uppercaseLastName := strings.ToUpper(name.LastName)
fmt.Println("GREETINGS " + uppercaseFirstName + " " + uppercaseLastName + "!!!!!!!")
// Eliminates any 'unused variable' errors
_, _ = uppercaseFirstName, uppercaseLastName
}
func addOneToAge[T acceptableAgeType](inputAge T) T {
return inputAge + 1
}
func greetBothWays(name person) {
fmt.Println("Normal greeting:")
name.greet(".")
fmt.Println("Shouting greeting:")
name.shout()
}
func main() {
person := person{FirstName: "John", LastName: "Doe", Age: 35}
greetBothWays(person)
fmt.Println("Next year, you'll be:")
fmt.Println(addOneToAge(person.Age))
// Eliminates any 'unused variable' errors
_ = person
}
Normal greeting:
Greetings John Doe.
Shouting greeting:
GREETINGS JOHN DOE!!!!!!!
Next year, you'll be:
36interface <InterfaceName>[Generics] {
[export] <methodName>(Arguments): <MethodReturnType> // Syntax of methods
<EmbeddedInterface> // Syntax of embedded interfaces
<EmbeddedStructs> // Syntax of embedded structs
<| Type1 | Type2 | etc> // Syntax of type sets
// NOTE: Type sets MUST start with `|`
}HELLOlambda <ReturnType> (Parameters) {
<lambda body>
}When I found out I was required to program in Gauntlet, I smiled!when <expr> @ <Return Type Of Below exprs> {
is <expr> -> <expr>
is <expr> -> <expr>
is <expr> -> <expr>
default -> <expr>
}enum <TaggedUnionName> {
case <case name>(<FieldName> : <FieldType>, ...) // case syntax
}package main
import fmt "fmt"
import strconv "strconv"
type Case343818345 struct {
diameter int
color string
}
type Case421059818 struct {
width int
height int
color string
}
type Case499594069 struct {
base int
width int
height int
color string
}
func main() {
fmt.Println("I only like red triangles. Let's see...")
myShape := map[int]any{499594069: Case499594069{base: 10, width: 5, height: 20, color: "red"}}
if _, exists := myShape[499594069]; exists {
if height, b := myShape[499594069].(Case499594069).height, myShape[499594069].(Case499594069).base; (func() bool {
return (myShape[499594069].(Case499594069).base == (b)) && (myShape[499594069].(Case499594069).height == (height)) && (myShape[499594069].(Case499594069).color == ("red"))
})() {
fmt.Println("It's a red triangle with a height of " + strconv.Itoa(height) + " and base length of " + strconv.Itoa(b) + "!")
}
}
if _, exists := myShape[421059818]; exists {
if width := myShape[421059818].(Case421059818).width; (func() bool {
return (myShape[421059818].(Case421059818).width == (width)) && (myShape[421059818].(Case421059818).color == ("red"))
})() {
fmt.Println("It's a red square with a width of " + strconv.Itoa(width))
}
}
if _, exists := myShape[343818345]; exists {
if diameter := myShape[343818345].(Case343818345).diameter; (func() bool {
return (myShape[343818345].(Case343818345).diameter == (diameter)) && (myShape[343818345].(Case343818345).color == ("red"))
})() {
fmt.Println("It's a red circle with a diameter of " + strconv.Itoa(diameter))
}
}
// Eliminates any 'unused variable' errors
_ = myShape
}
// Comment herelet <successVar>, <failureVar> = force <expr> with <expr>match <expr> {
case <case expr>: {
<code block>
}
}try <expr> with <expr if error != nil>let <successVar, failureVar> = try <expr> with <expr>package main
import "fmt" as fmt
fun add(num: Int, addend: Int): Int {
return num + addend
}
fun subtract(num: Int, subtrahend: Int): Int {
return num - subtrahend
}
fun multiply(num: Int, multiplier: Int): Int {
return num * multiplier
}
fun divide(num: Int, divisor: Int): Int {
return num / divisor
}
fun Unit main() {
10
|> add(_, 10)
|> add(_, 30)
|> divide(_, 2)
|> subtract(_, 5)
|> divide(_, 2)
|> multiply(_, 10)
|> fmt.println(_)
}Hello world!package main
import "fmt" as fmt
fun main(): Unit {
fmt.println("Hello world!") // This is a comment
}package main
import fmt "fmt"
func main() {
fmt.Println("Hello world!")
}
package main
import "fmt" as fmt
import "errors" as errors
fun divide(num1: Int, num2: Int): (Int, Error) {
if num2 == 0 {
return (0, errors.new("Cannot divide by 0"))
}
return (num1 / num2, null)
}
fun divideBy2(num: Int): (Int, Error) {
return divide(num, 2)
}
fun divideBy0(num: Int): (Int, Error) {
return divide(num, 0)
}
fun getResults(num: Int): (Int, Error) {
let dBy2Res, dBy2Err = force divideBy2(5) with "Error when dividing 5 by 2"
let dBy0Res, dBy0Err = force divideBy0(10) with "Error when dividing 10 by 0"
return (dBy2Res + dBy0Res, null)
}
fun main(): Unit {
fmt.println("Let's see if there's an error:")
let res, err = getResults(10)
fmt.println(err != null)
}package main
import "fmt" as fmt
import "errors" as errors
fun divide(num1: Int, num2: Int): (Int, Error) {
if num2 == 0 {
return (0, errors.new("Cannot divide by 0"))
}
return (num1 / num2, null)
}
fun divideBy2(num: Int): (Int, Error) {
return divide(num, 2)
}
fun divideBy0(num: Int): (Int, Error) {
return divide(num, 0)
}
fun getResults(num: Int): (Int, Error) {
let dBy2Res, dBy2Err = try divideBy2(5) with (dBy2Res, dBy2Err)
let dBy0Res, dBy0Err = try divideBy0(10) with (dBy0Res, dBy0Err)
return (dBy2Res + dBy0Res, null)
}
fun main(): Unit {
fmt.println("Let's see if there's an error:")
let res, err = getResults(10)
fmt.println(err != null)
}I only like red shapes. Let's see if this shape is red...
It's a red triangle with a height of 20 and base length of 10package main
import fmt "fmt"
func add(num int, addend int) int {
return num + addend
}
func subtract(num int, subtrahend int) int {
return num - subtrahend
}
func multiply(num int, multiplier int) int {
return num * multiplier
}
func divide(num int, divisor int) int {
return num / divisor
}
func main() {
fmt.Println(multiply(divide(subtract(divide(add(add(10, 10), 30), 2), 5), 2), 10))
}
100[<array length>]<Array Type>{<expr>, <expr>, ...}[...]<Array Type>{<key expr> : <value expr>, ...}package main
import "fmt" as fmt
fun main(): Unit {
let goodLanguages = [...]String{"Gauntlet", "Go", "F#"}
let badLanguages = [3]String{"Java", "PHP", "C#"}
fmt.println("Good languages:")
fmt.println(goodLanguages)
fmt.println("Bad languages:")
fmt.println(badLanguages)
}package main
import fmt "fmt"
func main() {
goodLanguages :=
[...]string{"Gauntlet", "Go", "F#"}
badLanguages :=
[3]string{"Java", "PHP", "C#"}
fmt.Println("Good languages:")
fmt.Println(goodLanguages)
fmt.Println("Bad languages:")
fmt.Println(badLanguages)
// Eliminates any 'unused variable' errors
_, _ = badLanguages, goodLanguages
}
Good languages:
[Gauntlet Go F#]
Bad languages:
[Java PHP C#][]<Slice type>{<expr1>, <expr2> ...}package main
import "fmt" as fmt
fun main(): Unit {
let first5Numbers = []Int{1, 2, 3, 4, 5}
fmt.println("The first 5 numbers are:")
fmt.println(first5Numbers)
}package main
import fmt "fmt"
func main() {
first5Numbers := []int{1, 2, 3, 4, 5}
fmt.Println("The first 5 numbers are:")
fmt.Println(first5Numbers)
// Eliminates any 'unused variable' errors
_ = first5Numbers
}
The first 5 numbers are:
[1 2 3 4 5][<Key Type>]<Value Type>{<key expr> : <value expr>, ...]package main
import "fmt" as fmt
fun main(): Unit {
let grades = map[String]Int{
"Bob" : 80
"Joe" : 75
"Josh" : 90
}
fmt.println("Bob's grade was: ")
fmt.println(grades["Bob"])
}package main
import fmt "fmt"
func main() {
grades := map[string]int{"Bob": 80, "Joe": 75, "Josh": 90}
fmt.Println("Bob's grade was: ")
fmt.Println(grades["Bob"])
// Eliminates any 'unused variable' errors
_ = grades
}
Bob's grade was:
80<expr>[expr>]package main
import "fmt" as fmt
fun main(): Unit {
let shoppingList = [...]String{"Bananna", "Orange", "Apples"}
fmt.println("The first thing I want to buy when I get to the store is:")
fmt.println(shoppingList[1])
let streamingPasswords = map[String]String{
"Netflix" : "net123",
"Hulu" : "hulu5"
"Disney+" : "Disney10"
}
fmt.println("The password to my Disney+ account is:")
fmt.println(streamingPasswords["Disney+"])
}package main
import fmt "fmt"
func main() {
shoppingList :=
[...]string{"Bananna", "Orange", "Apples"}
fmt.Println("The first thing I want to buy when I get to the store is:")
fmt.Println(shoppingList[1])
streamingPasswords := map[string]string{"Netflix": "net123", "Hulu": "hulu5", "Disney+": "Disney10"}
fmt.Println("The password to my Disney+ account is:")
fmt.Println(streamingPasswords["Disney+"])
// Eliminates any 'unused variable' errors
_, _ = shoppingList, streamingPasswords
}
The first thing I want to buy when I get to the store is:
Orange
The password to my Disney+ account is:
Disney10<expr>[<start expr> : <end expr>]package main
import "fmt" as fmt
fun main(): Unit {
let statement = "I am a human being who is loved and cared for"
let truePart = statement[0:18]
fmt.println(truePart)
}package main
import fmt "fmt"
func main() {
statement := "I am a human being who is loved and cared for"
truePart := statement[0:18]
fmt.Println(truePart)
// Eliminates any 'unused variable' errors
_, _ = statement, truePart
}
I am a human being(<expr>, <expr>, <expr>, etc)package main
import "fmt" as fmt
fun main(): Unit {
let a, b, c, d = (1, 2, 3, 4)
fmt.println("a is:")
fmt.println(a)
fmt.println("b is:")
fmt.println(b)
fmt.println("c is:")
fmt.println(c)
fmt.println("d is:")
fmt.println(d)
}package main
import fmt "fmt"
func main() {
a, b, c, d := 1, 2, 3, 4
fmt.Println("a is:")
fmt.Println(a)
fmt.Println("b is:")
fmt.Println(b)
fmt.Println("c is:")
fmt.Println(c)
fmt.Println("d is:")
fmt.Println(d)
// Eliminates any 'unused variable' errors
_, _, _, _ = a, b, c, d
}
a is:
1
b is:
2
c is:
3
d is:
4<identifier> typeassert <Type>package main
import "fmt" as fmt
fun main(): Unit {
let a: Any = 1
let b = a typeassert Int
fmt.println(b)
}package main
import fmt "fmt"
func main() {
var a any = 1
b := a.(int)
fmt.Println(b)
// Eliminates any 'unused variable' errors
_, _ = a, b
}
1(<Type>)(<expr>)package main
import "fmt" as fmt
wrapper Int Dollar
fun main(): Unit {
let dollars = Dollar(10)
let intVersion = (Int)(dollars)
fmt.println("I have this much money:")
fmt.println(intVersion)
}package main
import fmt "fmt"
type dollar int
func main() {
dollars := dollar(10)
intVersion := int(dollars)
fmt.Println("I have this much money:")
fmt.Println(intVersion)
// Eliminates any 'unused variable' errors
_, _ = dollars, intVersion
}
I have this much money:
10go {
<scope content>
}package main
import "fmt" as fmt
import "time" as time
fun main(): Unit {
go {
fmt.println("Hello from Gauntlet!")
}
time.sleep(1 * time.second)
fmt.println("Main function has ended")
}package main
import fmt "fmt"
import time "time"
func main() {
go (func() {
fmt.Println("Hello from Gauntlet!")
})()
time.Sleep(1 * time.Second)
fmt.Println("Main function has ended")
}
Hello from Gauntlet!
Main function has endeddefer {
<scope content>
}package main
import "fmt" as fmt
fun main(): Unit {
defer {
fmt.println("World!")
}
fmt.println("Hello")
}package main
import fmt "fmt"
func main() {
defer (func() {
fmt.Println("World!")
})()
fmt.Println("Hello")
}
Hello
World!&<expr>*<expr>package main
import "fmt" as fmt
fun main(): Unit {
let x = 10
let ptr = &x
*ptr = 20
fmt.println(x)
}package main
import fmt "fmt"
func main() {
x := 10
ptr := &x
*ptr = 20
fmt.Println(x)
// Eliminates any 'unused variable' errors
_, _ = ptr, x
}
20<channel name> <- <expr><-<channel name>package main
import "fmt" as fmt
fun main(): Unit {
let ch = make(chan String)
go {
ch <- "Hello from goroutine!"
}
let msg = <-ch
fmt.println(msg)
}package main
import fmt "fmt"
func main() {
ch := make(chan string)
go (func() {
ch <- "Hello from goroutine!"
})()
msg := <-ch
fmt.Println(msg)
// Eliminates any 'unused variable' errors
_, _ = ch, msg
}
Hello from goroutine!!<expr>package main
import "fmt" as fmt
fun main(): Unit {
let myValue = false
let myNegatedValue = !myValue
fmt.println("myValue:")
fmt.println(myValue)
fmt.println("myValue but negated:")
fmt.println(myNegatedValue)
}package main
import fmt "fmt"
func main() {
myValue := false
myNegatedValue := !myValue
fmt.Println("myValue:")
fmt.Println(myValue)
fmt.Println("myValue but negated:")
fmt.Println(myNegatedValue)
// Eliminates any 'unused variable' errors
_, _ = myNegatedValue, myValue
}
myValue:
false
myValue but negated:
truepackage main
import fmt "fmt"
import errors "errors"
func divide(num1 int, num2 int) (int, error) {
if num2 == 0 {
return 0, errors.New("Cannot divide by 0")
}
return num1 / num2, nil
}
func divideBy2(num int) (int, error) {
return divide(num, 2)
}
func divideBy0(num int) (int, error) {
return divide(num, 0)
}
func getResults(num int) (int, error) {
dBy2Res, dBy2Err := divideBy2(5)
if dBy2Err != nil {
panic("Error when dividing 5 by 2")
}
dBy0Res, dBy0Err := divideBy0(10)
if dBy0Err != nil {
panic("Error when dividing 10 by 0")
}
// Eliminates any 'unused variable' errors
_, _, _, _ = dBy0Err, dBy0Res, dBy2Err, dBy2Res
return dBy2Res + dBy0Res, nil
}
func main() {
fmt.Println("Let's see if there's an error:")
res, err := getResults(10)
fmt.Println(err != nil)
// Eliminates any 'unused variable' errors
_, _ = err, res
}
Let's see if there's an error:
panic: Error when dividing 10 by 0
goroutine 1 [running]:
main.getResults(0x4bc5f8?)
/home/user/projects/gauntlet-lang/GoTesting/sample.go:37 +0x25
main.main()
/home/user/projects/gauntlet-lang/GoTesting/sample.go:48 +0x5a
exit status 2package main
import "fmt" as fmt
import "strconv" as strconv
enum Shapes {
Circle(diameter: Int, color: String)
Square(width: Int, height: Int, color: String)
Triangle(base: Int, width: Int, height: Int, color: String)
}
fun main(): Unit {
fmt.println("I only like red triangles. Let's see...")
let myShape = Triangle(base: 10, width : 5, height : 20, color : "red")
match myShape {
case Triangle(base: let b, height: let height, color : "red") : {
fmt.println("It's a red triangle with a height of " + strconv.itoa(height) + " and base length of " + strconv.itoa(b) + "!")
}
case Square(width : let width, color : "red") : {
fmt.println("It's a red square with a width of " + strconv.itoa(width))
}
case Circle(diameter: let diameter, color : "red") : {
fmt.println("It's a red circle with a diameter of " + strconv.itoa(diameter))
}
}
}package main
import fmt "fmt"
import strconv "strconv"
type Case343818345 struct {
diameter int
color string
}
type Case421059818 struct {
width int
height int
color string
}
type Case499594069 struct {
base int
width int
height int
color string
}
func main() {
fmt.Println("I only like red triangles. Let's see...")
myShape := map[int]any{499594069: Case499594069{base: 10, width: 5, height: 20, color: "red"}}
if _, exists := myShape[499594069]; exists {
if height, b := myShape[499594069].(Case499594069).height, myShape[499594069].(Case499594069).base; (func() bool {
return (myShape[499594069].(Case499594069).base == (b)) && (myShape[499594069].(Case499594069).height == (height)) && (myShape[499594069].(Case499594069).color == ("red"))
})() {
fmt.Println("It's a red triangle with a height of " + strconv.Itoa(height) + " and base length of " + strconv.Itoa(b) + "!")
}
}
if _, exists := myShape[421059818]; exists {
if width := myShape[421059818].(Case421059818).width; (func() bool {
return (myShape[421059818].(Case421059818).width == (width)) && (myShape[421059818].(Case421059818).color == ("red"))
})() {
fmt.Println("It's a red square with a width of " + strconv.Itoa(width))
}
}
if _, exists := myShape[343818345]; exists {
if diameter := myShape[343818345].(Case343818345).diameter; (func() bool {
return (myShape[343818345].(Case343818345).diameter == (diameter)) && (myShape[343818345].(Case343818345).color == ("red"))
})() {
fmt.Println("It's a red circle with a diameter of " + strconv.Itoa(diameter))
}
}
// Eliminates any 'unused variable' errors
_ = myShape
}
I only like red triangles. Let's see...
It's a red triangle with a height of 20 and base length of 10!package main
import fmt "fmt"
import errors "errors"
func divide(num1 int, num2 int) (int, error) {
if num2 == 0 {
return 0, errors.New("Cannot divide by 0")
}
return num1 / num2, nil
}
func divideBy2(num int) (int, error) {
return divide(num, 2)
}
func divideBy0(num int) (int, error) {
return divide(num, 0)
}
func getResults(num int) (int, error) {
dBy2Res, dBy2Err := divideBy2(5)
if dBy2Err != nil {
return dBy2Res, dBy2Err
}
dBy0Res, dBy0Err := divideBy0(10)
if dBy0Err != nil {
return dBy0Res, dBy0Err
}
// Eliminates any 'unused variable' errors
_, _, _, _ = dBy0Err, dBy0Res, dBy2Err, dBy2Res
return dBy2Res + dBy0Res, nil
}
func main() {
fmt.Println("Let's see if there's an error:")
res, err := getResults(10)
fmt.Println(err != nil)
// Eliminates any 'unused variable' errors
_, _ = err, res
}
Let's see if there's an error:
trueHit the button below to read the documentation regarding tagged unions
🚥Tagged UnionsHit the button below to read the documentation regarding pattern matching
In the previous version of the language, the type would always come before the name. For example:
in this new version, this aspect been reversed: the type will now always come after the name, seperated by a colon:
The pipe operator has been changed from => to |>.
Experince issues, or want to get involved? Please join the Discord server and/or create an issue on the GitHub page. Links can be found .
package main
import "fmt" as fmt
wrapper Int Dollars
fun addDollars(currentAmount: Dollars, amountToAdd: Int): Dollars {
return Dollars(((Int)(currentAmount)) + amountToAdd)
}
fun printDollars(amount: Dollars): Unit {
fmt.println(amount)
}
fun main(): Unit {
let dollarsIHave = Dollars(100)
let newAmount = addDollars(dollarsIHave, 900)
printDollars(newAmount)
}package main
import fmt "fmt"
type dollars int
func addDollars(currentAmount dollars, amountToAdd int) dollars {
return dollars((int(currentAmount)) + amountToAdd)
}
func printDollars(amount dollars) {
fmt.Println(amount)
}
func main() {
dollarsIHave := dollars(100)
newAmount := addDollars(dollarsIHave, 900)
printDollars(newAmount)
// Eliminates any 'unused variable' errors
_, _ = dollarsIHave, newAmount
}
// Old Syntax - <type> <name>
fun getGreeting(String fullName)// New Syntax - <name>: <type>
fun getGreeting(fullName: String)1000