Linked by kragil on Wed 23rd Jan 2013 20:26 UTC
Google "Native Client enables Chrome to run high-performance apps compiled from your C and C++ code. One of the main goals of Native Client is to be architecture-independent, so that all machines can run NaCl content. Today we're taking another step toward that goal: our Native Client SDK now supports ARM devices, from version 25 and onwards."
Thread beginning with comment 550169
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE[4]: Comment by Laurence
by satsujinka on Wed 23rd Jan 2013 22:19 UTC in reply to "RE[3]: Comment by Laurence"
satsujinka
Member since:
2010-03-11

You've been space butchered, but it's not that weird.

The anonymous function is simply a closure that captures the variables a and b, then modifies them both to produce the next Fibonacci number when called.

It's really quite standard. I mean compare to a similar Scheme function (mind you it's been awhile):

(define fib (let ((a 0) (b1))
(lambda () (begin (set! a b) (set! b (+ b 1)) a)))

But of course, until you share what language you think does this "better," it's impossible to address your complaint.

Edited 2013-01-23 22:19 UTC

Reply Parent Score: 3

RE[5]: Comment by Laurence
by Hiev on Wed 23rd Jan 2013 22:27 in reply to "RE[4]: Comment by Laurence"
Hiev Member since:
2005-09-27

I can read the code:

func fib() func() int {

declares a function that returns a function.

a, b := 0, 1

declares a and b as integer then initialized them with a zero.


return func() int {
a, b = b, a+b
return a
}
}


That's the closure, but the difference with its counterparts like Javascript and C# is that you can mix that example with pointers and a weird array initialization syntax that Go allows.

I said Go is a C like language, why do you keep comparing it with Javascript and C#?

Reply Parent Score: 2

RE[6]: Comment by Laurence
by satsujinka on Thu 24th Jan 2013 03:22 in reply to "RE[5]: Comment by Laurence"
satsujinka Member since:
2010-03-11

I'm not comparing it with JavaScript or C#. I was just showing that it's a 1-to-1 match with how you'd normally write a function that returns a function that computes successive Fibonacci numbers.

Though since you mention it, the JavaScript version looks identical as well.

function fib() {
var a = 0; var b = 1;
return function() {a = b; b = b + 1; return a;};
}


How's pointer or array syntax weird?

func f() []int {...}
func f() *int {...}

There's nothing weird about those signatures.
Array initialization is almost exactly like C:

[]int{1,2,3,4}

Reply Parent Score: 2