Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

functions can not live in a function, and lambda can not recursive invoke #59392

Closed
AiziChen opened this issue Apr 3, 2023 · 0 comments
Closed

Comments

@AiziChen
Copy link

AiziChen commented Apr 3, 2023

When I define a function named sqrt in Golang:

package main

import (
	"fmt"
	"math"
)

func main() {
	func sqrt(x float64) string {
		if x < 0 {
			return sqrt(-x) + "i"
		} else {
			return fmt.Sprint(math.Sqrt(x))
		}
	}
	sqrt(20);
}

then compile it, go compiler: mymath.go:9:7: syntax error: unexpected sqrt, expected (

When I change this function to a lambda:

package main

import (
	"fmt"
	"math"
)

func main() {
	var sqrt = func(x float64) string {
		if x < 0 {
			return sqrt(-x) + "i"
		} else {
			return fmt.Sprint(math.Sqrt(x))
		}
	}
	sqrt(20)
}

then compile it, go compiler: mymath.go:11:11: undefined: sqrt'

@AiziChen AiziChen closed this as completed Apr 3, 2023
@golang golang locked and limited conversation to collaborators Apr 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants