Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. // The recursive function used by MAP
  2. var make_map =
  3. next_map =>
  4. new_list =>
  5. fn =>
  6. list =>
  7. (list_acc =>
  8. // Have we reached the end of the list?
  9. (IS_LAST(list)
  10. // Yup, so reverse the items in list_acc and
  11. // we're done
  12. (REVERSE(list_acc))
  13.  
  14. // Nope, so recursively call ourselves passing
  15. // in the list accumulator, the function being
  16. // applied and whatever is left in the current
  17. // list
  18. (f => (next_map(list_acc)
  19. (fn)
  20. (TAIL(list)))
  21. (f))))
  22. // Pass the first list item to the function and append the
  23. // modified value to the start of the new list. The
  24. // resulting list becomes the value of the
  25. // list_acc(umulator) parameter seen above
  26. (PAIR(fn(HEAD(list)))(new_list));
  27.  
  28. // Create the MAP function using the Y-Combinator and an initial
  29. // empty list
  30. var MAP = Y(make_map)(EMPTY);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement