Standard library / go/constant

go/constant.Compare()

Compare compatible constants using a comparison token; Unknown yields false. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func Compare(x_ Value, op token.Token, y_ Value) bool

Parameters & Attributes

NameTypeDescription
x_ValueLeft constant operand.
optoken.TokenOperator token appropriate for this operation.
y_ValueRight constant operand.

Return Value

bool

Compare compatible constants using a comparison token; Unknown yields false.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/constant"  "go/token")
func main() { fmt.Println(constant.Compare(constant.MakeInt64(42), token.GTR, constant.MakeInt64(5))) }
Go Reference