test.mdl 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // list functions
  4. //
  5. //////////////////////////////////////////////////////////////////////////////
  6. map func list =
  7. if (empty list) then
  8. []
  9. else
  10. func (head list) :: map func (tail list);
  11. map2 func list1 list2 =
  12. if (empty list1) then
  13. []
  14. else
  15. func (head list1) (head list2) :: map2 func (tail list1) (tail list2);
  16. nth index list =
  17. if (equal index 0) then
  18. head list
  19. else
  20. nth (index - 1) (tail list);
  21. firstn index list =
  22. if (equal index 0) then
  23. []
  24. else
  25. head list :: firstn (index - 1) (tail list);
  26. aftern index list =
  27. if (empty list) then
  28. []
  29. else if (equal index 0) then
  30. list
  31. else
  32. aftern (index - 1) (tail list);
  33. middlen min max list =
  34. firstn (max - min) (aftern min list);
  35. filter func list =
  36. if (empty list) then
  37. []
  38. else if (func (head list)) then
  39. head list :: filter func (tail list)
  40. else
  41. filter func (tail list);
  42. //////////////////////////////////////////////////////////////////////////////
  43. //
  44. // Junk
  45. //
  46. //////////////////////////////////////////////////////////////////////////////
  47. integers = 1 :: map (1 +) integers;
  48. fib = 1 :: 2 :: map2 add fib (tail fib);
  49. //////////////////////////////////////////////////////////////////////////////
  50. //
  51. // TypeDelay
  52. //
  53. //////////////////////////////////////////////////////////////////////////////
  54. removens n list =
  55. filter (function x -> not (equal (mod x n) 0)) list;
  56. makeprimes numbers =
  57. head numbers :: makeprimes (removens (head numbers) numbers);
  58. primes = makeprimes (tail integers);
  59. diff = map2 sub (tail primes) primes;
  60. result = middlen 0 10 primes;