retroforth/example/CaptureOutput.retro
crc 848ba7303b use .retro instead of .forth in examples
FossilOrigin-Name: b5feea667d30aac255d1cfca61fed355d438d2ce6021677f1e53af6302b15eee
2019-08-20 18:46:40 +00:00

23 lines
450 B
Text

# Capturing Output
By taking advantage of the hook in `c:put`, it's possible to
write a combinator to capture output to a user specified
buffer.
~~~
{{
:capture{ &buffer:add &c:put set-hook ;
:} &c:put unhook ;
---reveal---
:capture-output (qa-)
[ buffer:set capture{ call } ] buffer:preserve ;
}}
~~~
## A Test Case
```
'Output d:create #256 #1024 * n:inc allot
[ d:words ] &Output capture-output
Output s:length n:put nl
```