On my Macbook (Mac OS X 10.6) I installed the Go language.
Basically I just followed the instruction after I watched the video on the website:
http://golang.org/
Added the following environment variables to my .bashrc:
export GOROOT=$HOME/go
export GOARCH=386
export GOOS=darwin
Then sourced the .bashrc (just this time because I did't want to restart my shell):
$ . ~/.bashrc
Installed mercurial($ is my prompt):
$ sudo easy_install mercurial
I've already had python 2.5.4 installed.
Then I tried to checkout source code from the Go language reposository:
hg clone -r release https://go.googlecode.com/hg/ $GOROOT
But then I got some error which seemed to come from my locale setup. For now I added the following to my .bashrc (not sure if that's the best workaround but anyway...):
export LC_CTYPE=C
Sourced .bashrc again, then retried the hg command to checkout the code.
Now it worked!
I've already had the latest XCode installed on my Macbook, so I already have required tools to build Go environment. So I just typed did as follows to build the Go system:
$ cd $GOROOT/src
$ ./all.bash
Then after a few minutes I saw this after lines of build commands:
--- cd ../test
0 known bugs; 0 unexpected bugs
Which means Go's ready here!
So I write my first Go program hello.go:
package main
import "fmt"
func main() {
fmt.Printf("hello, 世界\n")
fmt.Printf("123456789 * 123456789 = %d\n", 123456789 * 123456789)
}
Attempted to compile:
$ 8g hello
Which tells me:
c0 a4
b3 a6
hello.go:6: illegal rune in string
hello.go:6: illegal rune in string
hello.go:7: syntax error near fmt
Hmmm, multibyte string seems to cause some errors. So for now I change them to simpler "world" for now...:
fmt.Printf("hello, world")
What about the syntax error thing at line 7? By taking a look at the tutorial, I could see that I probably need a semicolon at the end of the line if I put more than one statement in a function (might not be correct to say so... oh, now I found there's some description on semicolons in "Effective Go" page). Anyway if I put at the end of line 6, the syntax error at 7 is gone, but instead this error comes along:
hello.go:7: constant 15241578750190521 overflows int
Sure, it's more than int can handle... So I look for some piece of info on variable types... OK, so there's 64-bit int (described at Printing section of Effective Go at least, and feels like there must be somewhere else too). Now I modify my source code at line 7:
fmt.Printf("123456789 * 123456789 = %d\n", int64(123456789 * 123456789))
Then my source code compiles successfully!
$ 8g hello.go
$ 8l hello.8
So I run the linked binary (unless you specify with -o option your target will be named "8.out" with the 8l command):
$ ./8.out
hello, world
123456789 * 123456789 = 15241578750190521
Examined the result with the bc command (a calculator command usually installed on *nix based systems), and looks right.
So my first Go code worked (except for the multibyte string issue) and I can start playing with the language.
2009年11月14日土曜日
2009年11月8日日曜日
eclipsecoder exception
eclipsecoder plugin wasn't working with c++, so after searching for some info, I installed Mingw. Now it seems working but still an exception shows up.
2009年11月5日木曜日
Wi2 not as good as expected so far
So I tried Wi2 with a coupon code from Bic Camera. Although it says DOUTOR cafes are covered, there are actually few wi-fi enabled DOUTORs even in Tokyo. Very disappointing. Let's see if it gets any better... Besides, the Wi2 site says DOUTOR in Hakozaki has a wi-fi spot, but I haven't been able to confirm that. I just walked by and didn't bother walking in though. It might work inside.
Today's self-study: I reviewed how adjacency matrices can be represented, and some about Floyd algorithm for finding shortest paths.
Today's self-study: I reviewed how adjacency matrices can be represented, and some about Floyd algorithm for finding shortest paths.
2009年11月4日水曜日
Wi-Fi Spots in Tokyo, and Self-Study
Today I went to Bic Camera, which sells PCs, TV sets, etc. It's an electric appliance store. They have cameras too, as the name says so. Anyway I found this ad about wi-fi service at 380 yen per month. To me it's bettern than Yodobashi Camera's wi-fi plan (similar chain of stores). Bic Camera's plan covers JR stations and DOUTOR (cafe here like Starbucks) plus Yodobashi's area (so far as I understand). I'm going to give it a try and see if it's any better. You find a lot of DOUTORs in Tokyo, which is a good point (don't really care about how their latte tastes for now).
At Bic Camera I bought a portable heater from SANYO, which is rechargeable. Traditional, disposable ones are cheap and convenient, but if rechargeable ones work, I'm going to switch to them.
About my learning stuff...
Yesterday at a cafe, I read chapter 6 of "Programming Principles and Practice Using C++."
Up to chapter 5, I just skimmed through, as the contents seemed fairly basic. I might go back to exercises in those chapters later.
In chapter 6, creating a calculator program is given as a topic. Although it's still introductory chapter, several techniques like tokenizing and parsing are explained.
I brought my mac book (which I had repaired yesterday) and implemented a calculator program following the text, up to 6.3.1.
Today I got back to dynamic programming. I finished up studying binomial coefficients and its implementation, and started to work on Floyd's algorithm, to find shortest edges for any given pair of vertices in a graph.
At Bic Camera I bought a portable heater from SANYO, which is rechargeable. Traditional, disposable ones are cheap and convenient, but if rechargeable ones work, I'm going to switch to them.
About my learning stuff...
Yesterday at a cafe, I read chapter 6 of "Programming Principles and Practice Using C++."
Up to chapter 5, I just skimmed through, as the contents seemed fairly basic. I might go back to exercises in those chapters later.
In chapter 6, creating a calculator program is given as a topic. Although it's still introductory chapter, several techniques like tokenizing and parsing are explained.
I brought my mac book (which I had repaired yesterday) and implemented a calculator program following the text, up to 6.3.1.
Today I got back to dynamic programming. I finished up studying binomial coefficients and its implementation, and started to work on Floyd's algorithm, to find shortest edges for any given pair of vertices in a graph.
登録:
投稿 (Atom)