Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. Data List
  2. {
  3. List = c_nil ++ double * List .c_cons;
  4. }
  5.  
  6. Data SearchTree
  7. {
  8. SearchTree = c_tnil ++ double * SearchTree * SearchTree .c_branch;
  9. }
  10.  
  11. Scheme ToTree
  12. {
  13. Fun Construct
  14. {
  15. Fun Split
  16. {
  17. current = [2].~c_cons.[1];
  18. rest = [2].~c_cons.[2];
  19. next = ([1] * rest) .Split;
  20. Split =
  21. [1].~c_nil ->
  22. (c_nil * c_nil),
  23. [2].~c_nil ->
  24. (c_nil * c_nil),
  25. (current * [1]) .equal ->
  26. next,
  27. (current * [1]) .less ->
  28. (current * next.[1]) .c_cons * next.[2] ,
  29. next.[1] * (current * next.[2]) .c_cons;
  30. }
  31. pivot = [1].~c_cons.[1];
  32. rest = [1].~c_cons.[2];
  33. res = (pivot * rest) .Split;
  34. @ = [1].~c_nil ->
  35. c_tnil,
  36. (res.[1].~c_nil ->
  37. (res.[2].~c_nil ->
  38. (pivot * c_tnil * c_tnil) .c_branch,
  39. (pivot * c_tnil * (res.[2]).Construct) .c_branch)
  40. ,(res.[2].~c_nil ->
  41. (pivot * (res.[1]).Construct * c_tnil) .c_branch,
  42. (pivot * (res.[1]).Construct * (res.[2]).Construct) .c_branch));
  43. }
  44.  
  45. Fun Contains
  46. {
  47. Fun or
  48. {
  49. or = [1] ->
  50. true,
  51. [2] ->
  52. true,
  53. false;
  54. }
  55. Contains = [1].~c_tnil ->
  56. false,
  57. (([1].~c_branch.[1]) * [2]) .equal ->
  58. true,
  59. ((([1].~c_branch.[2] * [2]).Contains) * (([1].~c_branch.[3] * [2]).Contains)) .or;
  60. }
  61.  
  62. Fun RandomList
  63. {
  64. @ = ([2] * 0).equal -> c_nil,
  65. (([1] * (rand * ([2] * [1]).sub).mul).add * ([1] * ([2] * 1).sub).RandomList).c_cons;
  66. }
  67.  
  68. // @ = ((
  69. // ((3.0 *
  70. // ((4.0 *
  71. // ((5.0 * (c_nil))
  72. // .c_cons))
  73. // .c_cons))
  74. // .c_cons)
  75. // .Construct)
  76. // * 4.0).Contains.print;
  77. @ = ((1*20).RandomList).Construct;
  78. }
  79.  
  80. Application
  81. % ToTree
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement