Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- : printf
- : print
- : print_line
- }
- Where
- Define (printf s)
- Define (push_static stack begin i)
- If [i > begin]
- [(STRING.clip s begin i) & stack]
- stack
- Define (push_dynamic stack c x)
- (LIST.cons
- Cond {
- | [c = `s`] x
- | [c = `d`] (Z.show x)
- }
- stack)
- Define (print_stack stack)
- Unfold stack
- Begin Match stack {
- | 'nil
- | 'cons.{s stack}
- (Fold stack)
- (print s)
- }
- Let m (STRING.length s)
- In
- Unfold {stack i} From {'nil 0}
- Iterate {stack begin i} From {stack i i}
- Cond {
- | [i = m] (print_stack (push_static stack begin i))
- | [(STRING.fetch s i) = `%`]
- Let j [i + 1]
- Let k [i + 2]
- In
- Let c (STRING.fetch s j)
- In
- Cond {
- | [c = `%`] (Continue (push_static stack begin j) k k)
- | True
- Let stack (push_static stack begin i)
- In
- Func x (Fold (push_dynamic stack c x) k)
- }
- | True (Continue stack begin [i + 1])
- }
- Where
- Define (print s)
- (Prim print s)
- Define (print_line s)
- (Prim print_line s)
- Where
- Let LIST Package "list"
- Let OS Package "os"
- Let STRING Package "string"
- Let Z Package "z"
Add Comment
Please, Sign In to add comment