Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

filter
odd? ,5,9,2) -> ,,9fold 5foldLeft3){}3 /: List(1,4,1,5)){_ - _}
-> Int reduce-right
f
f(3, f(1, f(4, f(1, 5))))List).reduceLeft(_ - _)
-> Int = -8nth
2 4
 JavaScriptScalaOCamlF#
function literalfunction(x, y){return x*x + y*y}(3,4)
-> 25 
((x:Int, y:Int) => x*x + y*y)(3, 4)
-> Int = 25
(fun x y -> x*x + y*y) 3 4;;
-> int = 25

(fun x y -> x*x + y*y) 3 4;;
-> int = 25

bind a function literal
to a variable
var sos = function(x, y){return x*x + y*y};
sos(3,4)
-> 25
var sos = (x:Int, y:Int) => x*x + y*y
sos(3,4)
-> Int = 25

let sos = fun x y -> x*x + y*y;;
sos 3 4;;
-> int = 25

let sos = fun x y -> x*x + y*y;;
sos 3 4;;
-> int = 25
bind a function literal
to a variable in a scope 

function(){
var sos = function(x, y){return x*x + y*y};
return sos(3, 4);
}()
-> 25
sos(3,4)
-> sos is not defined

(() => {
var sos = (x:Int, y:Int) => x*x + y*y
sos(3, 4)
})()
-> Int = 25
sos(3, 4)
-> not found: value sos 

let sos = fun x y -> x*x + y*y in
sos 3 4;;
-> int = 25
sos 3 4;;
-> Unbound value sos 

let sos = fun x y -> x*x + y*y in sos 3 4
-> int = 25
sos 3 4;;
-> The value or constructor 'sos' is not defined 

named functionfunction sos(x, y){return x*x + y*y};
sos(3,4)
-> 25 
def sos(x:Int, y:Int) = x*x + y*y
sos(3, 4)
-> Int = 25 
let sos x y = x*x + y*y;;
sos 3 4;;
-> int = 25 
let sos x y = x*x + y*y;;
sos 3 4;;
-> int = 25 
named function in a scopefunction(){
function sos(x, y) {return x*x + y*y};
return sos(3, 4);
}()
-> 25
sos(3, 4)
-> sos is not defined 
(() => {
def sos(x:Int, y:Int) = x*x + y*y
sos(3, 4)
})()
-> Int = 25
sos(3, 4)
-> not found: value sos 
let sos x y = x*x + y*y in sos 3 4;;
-> int = 25
sos 3 4;;
-> Unbound value sos 
let sos x y = x*x + y*y in sos 3 4;;
-> int = 25
sos 3 4;;
-> The value or constructor 'sos' is not defined 
 JavaScriptScalaOCamlF#
car,head,first
(3,1,4,1,5,9,2) -> 3

[3,1,4,1,5,9,2].shift()
-> 3

List(3,1,4,1,5,9,2).head
-> Int = 3 

List.hd [3;1;4;1;5;9;2];;
-> - : int = 3

List.head [3;1;4;1;5;9;2];;
-> val it : int = 3

cdr,tail,next
(3,1,4,1,5,9,2) -> (1,4,1,5,9,2)

(function(x){x.shift(); return x})([3,1,4,1,5,9,2])
-> [ 1, 4, 1, 5, 9, 2 ]

List(3,1,4,1,5,9,2).tail
-> List[Int] = List(1,4,1,5,9,2) 
List.tl [3;1;4;1;5;9;2];;
-> - : int list = [1; 4; 1; 5; 9; 2]

List.tail [3;1;4;1;5;9;2];;
-> val it : int list = [1; 4; 1; 5; 9; 2]

cons
3 (1,4,1,5,9,2) -> (3,1,4,1,5,9,2)

(function(h,t){t.unshift(h); return t})(3, [1,4,1,5,9,2])
-> [ 3, 1, 4, 1, 5, 9, 2 ]

3::List(1,4,1,5,9,2)
-> List[Int] = List(3,1,4,1,5,9,2) 
3::[1;4;1;5;9;2];;
-> - : int list = [3; 1; 4; 1; 5; 9; 2]

3::[1;4;1;5;9;2];;
-> val it : int list = [3; 1; 4; 1; 5; 9; 2]

append,concat
(3,1,4) (1,5,9,2) -> (3,1,4,1,5,9,2)
[3,1,4].concat([1,5,9,2])
-> [ 3, 1, 4, 1, 5, 9, 2 ]
List(3,1,4):::List(1,5,9,2)
-> List[Int] = List(3,1,4,1,5,9,2) 

[3;1;4] @ [1;5;9;2];;
-> - : int list = [3; 1; 4; 1; 5; 9; 2] 

List.append [3;1;4] [1;5;9;2];;
-> - : int list = [3; 1; 4; 1; 5; 9; 2]

[3;1;4] @ [1;5;9;2];;
-> val it : int list = [3; 1; 4; 1; 5; 9; 2]

List.append [3;1;4] [1;5;9;2];;
-> val it : int list = [3; 1; 4; 1; 5; 9; 2]

take
5 (3,1,4,1,5,9,2) -> (3,1,4,1,5)

    
drop
5 (3,1,4,1,5,9,2) -> (9,2) 
    
 JavaScriptScalaOCamlF#
take-while
odd? (3,1,4,1,5,9,2) -> (3,1) 
    
drop-while
odd? (3,1,4,1,5,9,2) -> (4,1,5,9,2)
    
map
square (3,1,4,1,5,9,2)
-> (9,1,16,1,25,81,4) 
 List(3,1,4,1,5,9,2).map(x => x * x)
-> List[Int] = List(9,1,16,1,25,81,4) 
  

List.map (fun x->x*x) [3;1;4;1;5;9;2];;
-> - : int list = [9; 1; 16; 1; 25; 81; 4]

List.map (fun x->x*x) [3;1;4;1;5;9;2];;
-> val it : int list = [9; 1; 16; 1; 25; 81; 4]

filter
odd? (3,1,4,1,5,9,2) -> (3,1,1,5,9)
 List(3,1,4,1,5,9,2).filter(x => x % 2 != 0)
-> List[Int] = List(3,1,1,5,9) 

List.filter (fun x->(x mod 2) != 0) [3;1;4;1;5;9;2];;
-> - : int list = [3; 1; 1; 5; 9]

List.filter (fun x->(x%2)<>0) [3;1;4;1;5;9;2];;
-> val it : int list = [3; 1; 1; 5; 9]

fold-right
f
(3,1,4,1) 5
-> f(3, f(1, f(4, f(1, 5))))
 

List(3,1,4,1).foldRight(5){_ - _}
-> Int = 10

(List(3,1,4,1) :\ 5){_ - _}
-> Int = 10

List.fold_right (-) [3;1;4;1

] 5;;
-> - : int = 10

List.foldBack (-) [3;1;4;1] 5;;
-> val it : int = 10

fold-left
f
3 (1,4,1,5)
-> f(f(f(f(3, 1), 4), 1
) 5) 

List(

3,

1,4,1,5

,9,2

).

filter(x => x % 2 != 0)
-> List[Int] = List(3,1,1,5,9) 
  

foldLeft(3){_ - _}
-> Int = -8

(3 /: List(1,4,1,5)){_ - _}
-> Int = -8

List.fold_left (-) 3 [1;4;1;5];;
- : int = -8

List.fold (-) 3 [1;4;1;5];;
-> val it : int = -8
reduce-right
f (3,1,4,1,5)

-> f(3, f(1, f(4, f(1, 5)))) 
 List(3,1,4,1,5).foldRightreduceRight(5){_ - _})
-> Int = 10
 

(List.reduceBack (-) [3,;1,;4,;1) :\ 5){_ - _};5];;
-> Int val it : int = 10

  
foldreduce-left
f (3 (,1,4,1,5)
-> f(f(f(f(3, 1), 4), 1), 5) 
 List(3,1,4,1,5).reduceLeft(_ - _)
-> Int = -8
 

List.reduce (

-) [3;1;4;1;5];;
-> val it : int = -8

  JavaScriptScalaOCamlF#
nth
2 (3, 1, 4, 1, 5)
-> 4  

List

(

.nth [3

,

;1

,

;4

,

;1

,5).reduceRight(_ - _)

;5;9;2] 2;;
->

Int

- : int =

10
  reduce-left
f (3,1,4,1,5)
-> f(f(f(f(3, 1), 4), 1), 5) 
 

4

List.nth [3;1;4;1;5;9;2] 2;;
-> val it : int = 4

elem, member
2 (3,1,4,1,5
  
 JavaScriptScalaOCamlF#
,9,2) -> true
7 (3,1,4,1,5,9,2) ->
false    
elem, member
2 (3,1,4,1,5,9,2) -> true
7 (3,1,4,1,5,9,2) -> false 
    

List.mem 2 [3;1;4;1;5;9;2];;
-> - : bool = true
List.mem 7 [3;1;4;1;5;9;2];;
-> - : bool = false

 
some, any
even? '(3 1 4 1) -> true
even? '(3 5 7 9) -> false 
    
every?, all
odd? '(3 1 4 1) -> false
odd? '(3 5 7 9) -> true 
    
 JavaScriptScalaOCamlF#
0, 1, 2, ... infinite    
0, 1, 2, 3, 4 List.range(0,5)
-> List[Int] = List(0,1,2,3,4) 
  
2, 3, 4, 5, 6 List.range(2,7)
-> List[Int] = List(2,3,4,5,6) 
  
3, 5, 7, 9, 11 List.range(3,12,2)
-> List[Int] = List(3,5,7,9,11) 
  
(3, 1, 4, 1, 5) -> 14    
unfold
x f g
-> x, f(x), f(f(x)), ... until g(x) 
    

iterate
x f
-> x, f(x), f(f(x)), f(f(f(x))), ...

    
finite iterate
x f 5
-> x, f(x), f(f(x)), f(f(f(x))), f(f(f(f(x)))) 
    
repeat
x
-> (x, x, x, ...) 
    
finite repeat
x 5
-> (x, x, x, x, x)
    
 JavaScriptScalaOCamlF#
assoc    
show contents of a file    

OCaml reference: http://caml.inria.fr/pub/docs/manual-ocaml/libref/List.html
F# reference: http://msdn.microsoft.com/en-us/library/ee353738.aspx

Processors

...