with the multiple assignment (ie a,b=b,a) in f# its possible to write Fibonacci in a single line .. Can some one show how it is .. i know its possible in ruby
with the multiple assignment (ie a,b=b,a) in f# its possible to write Fibonacci in
Share
Scott Hanselman pretty much covers this in this blog post.
Here is the relevant snippet:
Scott got that from Dustin Cambell’s blog. I post Scott’s version because he also has the Ruby code for it. It’s worth noting that in F#, variables are generally immutable so
a,b = b,ais not actually reassigning anything (I don’t think it’s even valid syntax). Rather, a function likelet swap (a,b) = (b,a)is taking a tuple and returning a new tuple with the contents reversed.