Guest User

Untitled

a guest
Nov 14th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. {
  2. : printf
  3. : print
  4. : print_line
  5. }
  6.  
  7. Where
  8.  
  9. Define (printf s)
  10. Define (push_static stack begin i)
  11. If [i > begin]
  12. [(STRING.clip s begin i) & stack]
  13. stack
  14. Define (push_dynamic stack c x)
  15. (LIST.cons
  16. Cond {
  17. | [c = `s`] x
  18. | [c = `d`] (Z.show x)
  19. }
  20. stack)
  21. Define (print_stack stack)
  22. Unfold stack
  23. Begin Match stack {
  24. | 'nil
  25. | 'cons.{s stack}
  26. (Fold stack)
  27. (print s)
  28. }
  29. Let m (STRING.length s)
  30. In
  31. Unfold {stack i} From {'nil 0}
  32. Iterate {stack begin i} From {stack i i}
  33. Cond {
  34. | [i = m] (print_stack (push_static stack begin i))
  35. | [(STRING.fetch s i) = `%`]
  36. Let j [i + 1]
  37. Let k [i + 2]
  38. In
  39. Let c (STRING.fetch s j)
  40. In
  41. Cond {
  42. | [c = `%`] (Continue (push_static stack begin j) k k)
  43. | True
  44. Let stack (push_static stack begin i)
  45. In
  46. Func x (Fold (push_dynamic stack c x) k)
  47. }
  48. | True (Continue stack begin [i + 1])
  49. }
  50.  
  51. Where
  52.  
  53. Define (print s)
  54. (Prim print s)
  55.  
  56. Define (print_line s)
  57. (Prim print_line s)
  58.  
  59. Where
  60.  
  61. Let LIST Package "list"
  62. Let OS Package "os"
  63. Let STRING Package "string"
  64. Let Z Package "z"
Add Comment
Please, Sign In to add comment