Thursday, November 12, 2009

There we Go.

Last week I visited Google for the first time. I even passed by Rob Pikes office...

Today I'm using the language he and his team just created. Lots of inspirations from C, python, limbo and friends, and I actually had fun playing around with it.

1 package main
2
3 import "fmt"
4
5 func PrintAll(x interface{}) {
6 var str string;
7 switch value := x.(type) {
8 case bool:
9 if value {
10 str = "True"
11 } else {
12 str = "False"
13 }
14 case string:
15 str = value
16 default:
17 return
18 }
19 fmt.Printf(str + "\n")
20 }
21
22
23 func main() {
24 PrintAll("Hello world");
25 PrintAll(true);
26 PrintAll(false);
27 }

Now look at that :-) Hello World, here we Go.
$ 6g test.go && 6l test.6 && ./6.out
Hello world
True
False

PS: "!" replaced with ".", emphasising that I'm talking about "Go" and not the "Go!" language.

12 comments:

Unknown said...

ohhhh Uppercase method names... my eyes!!!!! :-)

Unknown said...

D programming language version:

module main;

import std.stdio;

void PrintAll(T)(T x) {
string str;
static if (typeid (bool) is typeid (T)) {
if (x) {
str = "True";
} else {
str = "False";
}
}
else if (typeid (string) == typeid (typeof (x)))
str = x;
else
return;
std.stdio.writefln(str);
}

void main() {
PrintAll("Hello world");
PrintAll(true);
PrintAll(false);
}

Unknown said...

Err... How to format code in comments?

Kenneth Rohde Christiansen said...

No idea how to format code in comments :-). Ah yeah, uppercase function names means that they are exported from the package, where as the lowercase named functions are not (thus private)

scottishwildcat said...

"By the time some newbie like Rob Pike comes up with an idea, it's already been in Haskell for years." -- Conrad Parker on #Go

rotatef said...

I wonder what 'idea' Conrad was referring to. Quite a few ideas behind Go can be seen in Squeak/Newsqueak (not the Smalltalk Squeak), Alef, and Limbo -- all 15+ years old.

Unknown said...

Look,Cheap GHD Straighteners,Discount GHD Styler,GHD Outlet,CHI hair Straighteners,2010 Cheap Sunglasses,Discount SunglassesSunglasses Outlet,wholesale Sunglasses,Sunglasses Wholesale. Do not worry. The urge to buy these goods will be very strong once you spot the shoes or clothes that you like. I am also a big fan for these products, although I like ED Hardy,cheap ED Hardy Clothes,discount ED Hardy Outlet,Wholesale Ed Hardy,Ed hardy wholesale, cheap Prada,discount Prada,Prada Outlet,newest Prada handbags,Prada handbags 2010, so I can understand. Online wholesale dealers have quite an array for you to choose from, including wholesale jewelry and handbags. And these are bags that bear the most famous names in the world of fashion, by the way -Prada, Spyder, Moncler, GHD, ED Hardy, designer Sunglasses, Ankh Royalty, Twisted Heart, or say AnkhRoyalty,Ankh Royalty,Ankh Royalty Clothing ,Ankh Royalty Clothes,AnkhRoyalty Outlet. Such variety that comes at incredibly affordable prices is a treat you can't possibly pass up on.

Unknown said...

www.monclerdesign.com
Moncler online
Moncler
Moncler Jackets
www.stylemoncler.com
moncler online shop
Moncler
Moncler Jackets
www.doudoune-moncler.net
Boutique en ligne Moncler
veste moncler
doudoune moncler

teralifeonline said...

Tera gold
Tera Item
Tera account

Runescape gold
buy Runescape gold

cheap wow gold
cheapest wow gold
lotro gold

Tera online
Tera gold
Tera items
Tera gold cheap
cheap Tera gold

Liz said...

3
江詩丹頓
隔熱紙
樟芝
白蟻
跳蚤
香港平價住宿
民宿
裝潢
外籍新娘
男性結紮

Download 2018 said...

I was about to say something on this topic. But now i can see that everything on this topic is very amazing and mind blowing, so i have nothing to say here. I am just going through all the topics and being appreciated. Thanks for sharing.

Jordan V said...

does strictiond really work