Guest User

Untitled

a guest
Jan 4th, 2013
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.82 KB | None | 0 0
  1. (*FUNCIONES*)
  2.  
  3. # let <f> = function <x> -> <e>
  4. # let <f> <x> = <e>
  5. # function x ->
  6.         if x>=0 then x
  7.         else -x;;
  8. # let abs x = if x >= 0 then x else –x;;
  9.  
  10. (*FUNCIONES RECURSIVAS*)
  11.  
  12. # let fact n = if n = 0 then 1
  13.     else n * fact(n-1);;
  14. ----------------------------------------------------------------------
  15. (*Forma correcta*)
  16. # let rec fact n = if n=0 then 1
  17.     else n * fact(n-1);;
  18.  
  19. (*LISTA*)
  20.  
  21. # [1;3;3] @ [7,9];;                                      //concatenación
  22. # list.lenght [true:false];;
  23. # list.map                                                    //aplica una función a toda una lista
  24. # let par n = n mod = 0;;
  25. # list.filter par [3;7;9;12;3;4]                   //sale la lista de pares
  26. # list.for_all                                                //devuelve un bool si todos son pares
Advertisement
Add Comment
Please, Sign In to add comment