1
2
3
let poweroffourplus2 n = 
  let n = n * n 
  let n = n* n

The #light syntax is very similar to Python in that whitespace is significant. Therefore, the code must be indented - using spaces not tabs - to show code relationships. The function also needs to return a value in order to be valid. Finally, when using FSI the last line needs a double semcolon ";;" to end input:

1
2
3
4
5
let poweroffourplus2 n =
    let n = n * n
    let n = n* n
    n;;
By on 7/31/2008 8:30 AM ()

Thank you very much and yes Don also mentioned the same in the same paragraph and I was eager to try to code without reading all the meat. I have one another question, this is realted to funcation thinking what exactly happening to n in the above example

when I use the first let (on the funcation definition) it is coming in as argument value. In the second let, the value of n is pass and creats a new n value (even though Don did mentioned the value of n doesn't change) here it is changing... now the next let uses n, it is using modified n instead of original n........

so how the value 'n' is not changed.??

Thanks again.

By on 7/31/2008 9:13 AM ()

This is 'shadowing' - each new 'let n = ...' creates a new variable which hides the old one. So

1
2
let n = n * n
let n = n * n

is like

1
2
let n_2 = n_1 * n_1
let n_3 = n_2 * n_2

only they all have the same name. None of the objects referred to by the name n_i is being mutated. Instead there are three different objects, and at different points in the code, the name 'n' refers to different ones of those objects.

By on 7/31/2008 3:07 PM ()

Thank you very much. I have one more question, I realised if I don't understand this correctly I am going to assume too many things so here is one more

in the following example

1
2
3
4
let nbynplus5 n =
     let n = n * n
     let n = n + 5
     n;;

In the above example, the let n = n * n will be let n_1 = n * n since it is the first time n is referenced and in the second let, it will be let n_2 = n_1 + 5. Is this correct so if I have make the code it would be

1
2
3
4
let nbynplus5 n =
     let n_1 = n * n
     let n_2 = n_1 + 5
     n_2;;

Is this correct? also why would be doing instead of using this modified code itself? Is it a style or coding standard?

Thanks again for helping me started.

By on 8/1/2008 7:53 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper