# Miscellaneous

This page documents the part of the language that were not "big" enough to warrant an entire page.

## Line Comments

### Syntax

```
// Comment here
```

### Working Example

{% tabs %}
{% tab title="Gauntlet" %}
```fsharp
package main

import "fmt" as fmt

fun main(): Unit {
  fmt.println("Hello world!") // This is a comment
}
```
{% endtab %}

{% tab title="Transpiled" %}
```go
package main

import fmt "fmt"

func main() {
	fmt.Println("Hello world!")

}

```
{% endtab %}

{% tab title="Output" %}
```
Hello world!
```
{% endtab %}
{% endtabs %}



{% hint style="info" %}
At this time, block comments are not supported
{% endhint %}

## Array Literal

You can use an array literal to construct an array.

### Syntax

```fsharp
[<array length>]<Array Type>{<expr>, <expr>, ...}
```

**-OR-**

```
[...]<Array Type>{<key expr> : <value expr>, ...}
```

### Working Example

{% tabs %}
{% tab title="Gauntlet" %}
```fsharp
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)
}
```
{% endtab %}

{% tab title="Transpiled" %}
```go
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

}

```
{% endtab %}

{% tab title="Output" %}
```
Good languages:
[Gauntlet Go F#]
Bad languages:
[Java PHP C#]
```
{% endtab %}
{% endtabs %}



## Slice Literal

You can use a slice literal to construct a slice.

### Syntax

```fsharp
[]<Slice type>{<expr1>, <expr2> ...}
```

### Working Example

{% tabs %}
{% tab title="Gauntlet" %}
```fsharp
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)
}
```
{% endtab %}

{% tab title="Transpiled" %}
```go
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

}

```
{% endtab %}

{% tab title="Output" %}
```
The first 5 numbers are:
[1 2 3 4 5]
```
{% endtab %}
{% endtabs %}

## Map Literal

Map literals can be used to construct maps

### Syntax

```
[<Key Type>]<Value Type>{<key expr> : <value expr>, ...]
```

### Working Example

{% tabs %}
{% tab title="Gauntlet" %}
```fsharp
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"])


}
```
{% endtab %}

{% tab title="Transpiled" %}
```go
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

}

```
{% endtab %}

{% tab title="Output" %}
```
Bob's grade was: 
80
```
{% endtab %}
{% endtabs %}

## Indexing

The indexing operator can be used on arrays, slices, strings, maps, and pointers to arrays

### Syntax

```fsharp
<expr>[expr>]
```

### Working Example

{% tabs %}
{% tab title="Gauntlet" %}
```fsharp
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+"])

}
```
{% endtab %}

{% tab title="Transpiled" %}
```go
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

}

```
{% endtab %}

{% tab title="Output" %}
```
The first thing I want to buy when I get to the store is:
Orange
The password to my Disney+ account is:
Disney10
```
{% endtab %}
{% endtabs %}

## Slicing

Slicing can only be done on strings, slices, and arrays

### Syntax:

```fsharp
<expr>[<start expr> : <end expr>]
```

### Working Example

{% tabs %}
{% tab title="Gauntlet" %}
```fsharp
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)
}
```
{% endtab %}

{% tab title="Transpiled" %}
```go
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

}

```
{% endtab %}

{% tab title="Output" %}
```
I am a human being
```
{% endtab %}
{% endtabs %}

## Tuples

### Syntax

```
(<expr>, <expr>, <expr>, etc)
```

### Working Example

{% tabs %}
{% tab title="Guantlet" %}
```fsharp
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)
}
```
{% endtab %}

{% tab title="Transpiled" %}
```go
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

}

```
{% endtab %}

{% tab title="Output" %}
```
a is:
1
b is:
2
c is:
3
d is:
4
```
{% endtab %}
{% endtabs %}

## Type Assertion

### Syntax

```fsharp
<identifier> typeassert <Type>
```

### Working Example

{% tabs %}
{% tab title="Gauntlet" %}
```fsharp
package main

import "fmt" as fmt

fun main(): Unit {
  let a: Any = 1
  let b = a typeassert Int
  fmt.println(b)
}
```
{% endtab %}

{% tab title="Transpiled" %}
```go
package main

import fmt "fmt"

func main() {
	var a any = 1
	b := a.(int)
	fmt.Println(b)
	// Eliminates any 'unused variable' errors
	_, _ = a, b

}

```
{% endtab %}

{% tab title="Output" %}
```
1
```
{% endtab %}
{% endtabs %}

## Type Conversion

### Syntax

```fsharp
(<Type>)(<expr>)
```

### Working Example

{% tabs %}
{% tab title="Gauntlet" %}
```fsharp
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)
}
```
{% endtab %}

{% tab title="Transpiled" %}
```go
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

}

```
{% endtab %}

{% tab title="Output" %}
```
I have this much money:
10
```
{% endtab %}
{% endtabs %}

## Goroutines

### Syntax

```fsharp
go {
    <scope content>
}
```

### Working Example

{% tabs %}
{% tab title="Gauntlet" %}
```fsharp
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")
}
```
{% endtab %}

{% tab title="Transpiled" %}
```go
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")

}

```
{% endtab %}

{% tab title="Output" %}
```
Hello from Gauntlet!
Main function has ended
```
{% endtab %}
{% endtabs %}

## Defer

### Syntax

```fsharp
defer {
    <scope content>
}
```

### Working Example

{% tabs %}
{% tab title="Gauntlet" %}
```fsharp
package main

import "fmt" as fmt

fun main(): Unit {
  defer {
    fmt.println("World!")
  }
  fmt.println("Hello")
}
```
{% endtab %}

{% tab title="Transpiled" %}
```go
package main

import fmt "fmt"

func main() {
	defer (func() {
		fmt.Println("World!")
	})()
	fmt.Println("Hello")

}

```
{% endtab %}

{% tab title="Output" %}
```
Hello
World!
```
{% endtab %}
{% endtabs %}

## Pointers & Dereferencing

### Pointer Syntax

```fsharp
&<expr>
```

### Dereferencing Syntax

```fsharp
*<expr>
```

### Working Example

{% tabs %}
{% tab title="Gauntlet" %}
```fsharp
package main

import "fmt" as fmt

fun main(): Unit {
  let x = 10
  let ptr = &x 
  *ptr = 20
  fmt.println(x)
}
```
{% endtab %}

{% tab title="Transpiled" %}
```go
package main

import fmt "fmt"

func main() {
	x := 10
	ptr := &x
	*ptr = 20
	fmt.Println(x)
	// Eliminates any 'unused variable' errors
	_, _ = ptr, x

}

```
{% endtab %}

{% tab title="Output" %}
```
20
```
{% endtab %}
{% endtabs %}

## Sending and Receiving with Channels

### Sending Syntax

```fsharp
<channel name> <- <expr>
```

### Receiving Syntax

```fsharp
<-<channel name>
```

### Working Example

{% tabs %}
{% tab title="Gauntlet" %}
```fsharp
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)
}
```
{% endtab %}

{% tab title="Transpiled" %}
```go
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

}

```
{% endtab %}

{% tab title="Output" %}
```
Hello from goroutine!
```
{% endtab %}
{% endtabs %}

## Negated Expression

### Syntax

```
!<expr>
```

### Working Example

{% tabs %}
{% tab title="Gauntlet" %}
```fsharp
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)
}
```
{% endtab %}

{% tab title="Transpiled" %}
```go
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

}

```
{% endtab %}

{% tab title="Output" %}
```
myValue:
false
myValue but negated:
true
```
{% endtab %}
{% endtabs %}
