Advertisement
Guest User

Meag Coding Manual [SML]

a guest
Oct 13th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (*Standard ML Language Guide and Reference
  2. ML Rules:
  3.     Everything is Immutable, nothing can be changed after the fact
  4.     Type Matters, make sure types don't conflict
  5.     Command Input is usually how things work
  6. *)
  7. (*Useful Commands:*)
  8. it; (*Returns Previous*)
  9. use "filename.sml"; (*File access*)
  10. op operation (*Displays the purpose of a function*)
  11.  
  12. (*Variable Declaration, note: can be applied to a function*)
  13. val name = value;
  14.  
  15. (*Variable Types:
  16. int - integer
  17. real - double
  18. string- string
  19. tuple - two things of the same type together (x,y)
  20. `a - Alpha, everything*)
  21.  
  22. val tuple= (5,4)
  23. #1 tuple; (*Returns the first value of the tuple, 5*)
  24. val tuple2= ((5,4),(3,2));
  25. #1 (#2 tuple2); (*Returns the First value of the Second tuple, 3*)
  26.  
  27. (*Functions:*)
  28. val functionName = fn(input:type, input:type) => Code to be run;
  29. val functionNameAlt = fn(input) => fn(input) => output;
  30.  
  31. fun functionName2 (input:type) (input:type) = x*y;
  32.  
  33. (*Using Functions*)
  34. functionName (input,input); (*First Method*)
  35. functionNameAlt input input; (*Second Method*)
  36.  
  37. (*Auxillary Commands that can come in handy*)
  38. Ceil Floor 5.6; (*Returns 6 or 5*)
  39. real 5 (*Returns 5.0*)
  40. explode "String" (*Returns  [#"S",#"t",#"r",#"i",#"n",#"g"]*)
  41. implode [#"S",#"t",#"r",#"i",#"n",#"g"] (*Returns "String"*)
  42. o (*Chain commands together*)
  43. (implode o explode) (*Explodes first, then implodes*)
  44.  
  45. (*If/Else and the like*)
  46. if something then something else something (*No Brackets*)
  47.  
  48.  (*Switch System:*)
  49. fun Check 0 = true  (*First Case: Function Name (the if code) = what happens then*)
  50. |   Check 1 = false (*Function Name (Second case) = What happens*)
  51. |   Check n = false; (*Function Name (n= Everything else/Default) = What happens*)
  52. (*In Recursion, the first line can be the base case, while the second onwards are for recursive stuff*)
  53.  
  54. (*Lists: Tuples that only store stuff of the SAME Data Type, can ONLY access head (first element) and tail (the rest) *)
  55.  
  56. [element 1, element 2] (*Standard List*)
  57. [[list1-a, list1-b], [list2-a, list2-b]] (*List inside a list*)
  58. hd [1,2,3] (*Returns 1*)
  59. tl [1,2,3] (*Returns [2,3]*)
  60. 8::[1,2,3] (*Returns [8,1,2,3]*)
  61. null [1] (*checks if empty, returns t/f*)
  62.  
  63. (*Todo: Data Types and their Declarations
  64.     Anything I might encounter while doing CW*)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement