Can be accessed one function from a file to the another one?
// file one.go
-----------------------
package foo
func One() {...}
-----------------------
// file two.go
-----------------------
package foo
func Two() {
/* Access to One()? */
}
-----------------------
If I've 2 source files to build a same package.
Can be accessed one function from a file to the another one?
Go compiles all the source files in a package at once, so one
file
can refer to constants, variables, types, and functions in
another file without special arrangement or declarations.
A quick look in the spec doesn't reveal such an explicit statement,I've:
// shell.go
------------------------
package shutil
func Foo(...) {
fmt.Println(Bin["qwe"])
}
------------------------
// _path.go
------------------------
package shutil
var Bin: map[string] string {
"qwe": "zxc",
}
------------------------
shell.go:27: undefined: Bin
On 30 mar, 06:13, Steven <steven...@gmail.com> wrote:
> On Mon, Mar 29, 2010 at 3:35 AM, chris dollin <ehog.he...@googlemail.com>wrote:
>
>
>
>
>
> > On 29 March 2010 08:18, Joan Miller <pelok...@gmail.com> wrote:
>
> >> If I've 2 source files to build a same package.
>
> >> Can be accessed one function from a file to the another one?
>
> > "how to write go code" says:
>
> > Go compiles all the source files in a package at once, so one
>
> > file can refer to constants, variables, types, and functions in
>
> > another file without special arrangement or declarations.
> > A quick look in the spec doesn't reveal such an explicit statement,
> > but I could have missed it.
>
> > --
> > Chris "allusive" Dollin
>
> "A package in turn is constructed from one or more source files that
> together declare constants, types, variables and functions belonging to the
> package and *which are accessible in all files of the same package.*"http://golang.org/doc/go_spec.html#Packages
So, it doesn't works to me.
I've:
// shell.go
------------------------
package shutil
func Foo(...) {
fmt.Println(Bin["qwe"])
}
------------------------
// _path.go
------------------------
package shutil
var Bin: map[string] string {
"qwe": "zxc",
}
------------------------
shell.go:27: undefined: Bin
On 30 mar, 08:23, chris dollin <ehog.he...@googlemail.com> wrote:
(replaced colon with equals)
And yes, you need to compile both files at the same time. You would
have gotten a syntax error if you'd compiled the second file.
Maybe you should read the language spec, and other documents? It looks
like you're carrying over assumptions from another language...