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

x/tour: explain function syntax better #4284

Closed
btracey opened this issue Oct 25, 2012 · 13 comments
Closed

x/tour: explain function syntax better #4284

btracey opened this issue Oct 25, 2012 · 13 comments

Comments

@btracey
Copy link
Contributor

btracey commented Oct 25, 2012

For those of us who are trying to pick up Go, but aren't CS majors, could we change the
description of 

http://tour.golang.org/#39

to be more explicit? I'm not sure how to parse the adder function declaration

func adder() func(int) int

It appears that adder is a function which takes no arguments, but returns a function
which takes an int as an argument and returns an int? Assuming that's correct, could you
also state how that works if it's nested? For example, what if the function adder
returns is also a closure? Is the definition

func adder() func1(int) func2(int) int

?
@robpike
Copy link
Contributor

robpike commented Oct 30, 2012

Comment 1:

Labels changed: added priority-later, removed priority-triage.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Dec 10, 2012

Comment 2:

Labels changed: added size-m.

@rsc
Copy link
Contributor

rsc commented Jan 29, 2013

Comment 3:

Labels changed: removed go1.1.

@rsc
Copy link
Contributor

rsc commented Nov 27, 2013

Comment 4:

Labels changed: added go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 5:

Labels changed: added release-none, removed go1.3maybe.

@adg
Copy link
Contributor

adg commented Dec 4, 2013

Comment 6:

Labels changed: added repo-tour.

@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@rsc rsc changed the title go.tour: explain function syntax better x/tour: explain function syntax better Apr 14, 2015
@rsc rsc modified the milestones: Unreleased, Unplanned Apr 14, 2015
@rsc rsc removed the repo-tour label Apr 14, 2015
@kytrinyx
Copy link
Contributor

kytrinyx commented Oct 8, 2015

This is now /moretypes/21.

The slide is focusing on the closure, and the function signature seems somewhat incidental. I suspect that adding explanations regarding the function signature might distract from the main point.

@adg What about adding a separate slide about function values?

@adg
Copy link
Contributor

adg commented Oct 8, 2015

The previous slide is about function values, but it doesn't say much. We could certainly expand on that.

@kytrinyx
Copy link
Contributor

Agreed. I'll take this one.

@kytrinyx
Copy link
Contributor

Would it be too much to expand the code example for the function values slide? E.g. something like this:

package main

import (
    "fmt"
    "math"
)

func compute(x, y float64, fn func(float64, float64) float64) float64 {
    return fn(x, y)
}

func main() {
    hypot := func(x, y float64) float64 {
        return math.Sqrt(x*x + y*y)
    }
    fmt.Println(hypot(5, 12))

    fmt.Println(compute(3, 4, hypot))
    fmt.Println(compute(3, 4, math.Pow))
}

@gopherbot
Copy link

CL https://golang.org/cl/15752 mentions this issue.

@adg
Copy link
Contributor

adg commented Oct 12, 2015

@kytrinyx how about just having compute take a single argument—the function—and then it does fmt.Println(fn(3, 4)). Then the example gets smaller too.

@kytrinyx
Copy link
Contributor

Oh, nice. Yepp, I like that.

adg pushed a commit to golang/tour that referenced this issue Oct 13, 2015
Typo introduced when addressing golang/go#4284

Change-Id: Iba8e9e8ef4c8fa528c10c42cf4cff244086712aa
Reviewed-on: https://go-review.googlesource.com/15801
Reviewed-by: Andrew Gerrand <adg@golang.org>
@golang golang locked and limited conversation to collaborators Oct 12, 2016
gopherbot pushed a commit to golang/website that referenced this issue May 26, 2021
The description was a little bit sparse.

The next slide talks about closures, but since the idea of
function values wasn't clear to all readers, some people got
confused when the next slide defined a function that had
a function as a return value.

Fixes golang/go#4284

Change-Id: Id71f71cafb7c411dbad8306980f7eb1d75aa59e5
Reviewed-on: https://go-review.googlesource.com/15752
Reviewed-by: Andrew Gerrand <adg@golang.org>
X-Tour-Commit: 500288ff415f380583e271decde1cde70e3348ef
passionSeven added a commit to passionSeven/website that referenced this issue Oct 18, 2022
The description was a little bit sparse.

The next slide talks about closures, but since the idea of
function values wasn't clear to all readers, some people got
confused when the next slide defined a function that had
a function as a return value.

Fixes golang/go#4284

Change-Id: Id71f71cafb7c411dbad8306980f7eb1d75aa59e5
Reviewed-on: https://go-review.googlesource.com/15752
Reviewed-by: Andrew Gerrand <adg@golang.org>
X-Tour-Commit: 500288ff415f380583e271decde1cde70e3348ef
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

6 participants