On Tue, Sep 4, 2018, at 01:33, Sayan Shankhari wrote: > Probably I am making some nonsense post here and disturbing you but as a > beginner, I want to know how in Go I can implement the following. If I can > not, please suggest me suitable solution:
Not at all; welcome! If you're just getting started with Go, I recommend that you take the tour (https://tour.golang.org). This probably covers most of what you want. > 1. Create a package "myNum" This is a good resource for getting started with creating Go packages: https://golang.org/doc/code.html It's a tiny bit out of date, there are some experimental features in Go 1.11 that make using GOPATH obsolete, but it will still work for now. > 2. containing data type like: > type Num struct { > n, d int // numerator, denominator > } > 3. and a function to print like > func printMyNum(x Num) { > fmt.Println("the fractional number is: %d/%d", x.n, x.d) > } Looks like you've already done this, good job :) In Go, the case of the first letter of an identifier determines if it's exported or not. In your code "Num" will be exported (it can be used from another package), but its fields are not (so you won't be able to set "n" or "d" from another package). Similarly, "printMyNum" will not be exported, so you won't be able to call it from another package. Here is a more detailed explanation: https://stackoverflow.com/questions/38616687/which-way-to-name-a-function-in-go-camelcase-or-semi-camelcase/38617771#38617771 And here is a nice post about how to name things: https://blog.golang.org/package-names I hope that's helpful. Welcome to Go! —Sam -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.