~ chicken-core (chicken-5) /manual/Module (chicken format)
Trap1[[tags: manual]]2[[toc:]]34== Module (chicken format)56This module provides procedures for formatting output to ports and7strings.89=== The printf family of procedures1011==== printf12==== fprintf13==== sprintf1415<procedure>(fprintf PORT FORMATSTRING [ARG...])</procedure><br>16<procedure>(printf FORMATSTRING [ARG...])</procedure><br>17<procedure>(sprintf FORMATSTRING [ARG...])</procedure>1819Simple formatted output to a given port ({{fprintf}}), the20value of {{(current-output-port)}} ({{printf}}), or a string21({{sprintf}}). The {{FORMATSTRING}} can contain any sequence22of characters. There must be at least as many {{ARG}} arguments given as there are format directives that require an argument in {{FORMATSTRING}}. Extra {{ARG}} arguments are ignored. The character `~' prefixes special formatting directives:2324<table>25<tr><td>~%</td><td>26write newline character27</td></tr><tr><td> ~N</td><td>28the same as {{~%}}29</td></tr><tr><td> ~S</td><td>30write the next argument31</td></tr><tr><td> ~A</td><td>32display the next argument33</td></tr><tr><td> ~\n</td><td>34skip all whitespace in the format-string until the next non-whitespace character35</td></tr><tr><td> ~B</td><td>36write the next argument as a binary number37</td></tr><tr><td> ~O</td><td>38write the next argument as an octal number39</td></tr><tr><td> ~X</td><td>40write the next argument as a hexadecimal number41</td></tr><tr><td> ~C</td><td>42write the next argument as a character43</td></tr><tr><td> ~~</td><td>44display `~'45</td></tr><tr><td> ~!</td><td>46flush all pending output47</td></tr><tr><td> ~?</td><td>48invoke formatted output routine recursively with the next two arguments as format-string and list of parameters49</td></tr></table>505152=== format5354<procedure>(format [DESTINATION] FORMATSTRING [ARG...])</procedure>5556The parameters {{FORMATSTRING}} and {{ARG...}} are as for {{printf}}.5758The optional {{DESTINATION}}, when supplied, performs:5960; {{#f}} : {{sprintf}}61; {{#t}} : {{printf}}62; {{output-port}} : {{fprintf}}63; : {{sprintf}}646566---67Previous: [[Module (chicken foreign)]]6869Next: [[Module (chicken gc)]]