2019-03-31 11:00:21 +00:00
|
|
|
---
|
|
|
|
title: 第14章・入出力
|
|
|
|
author: kazu634
|
|
|
|
date: 2008-11-16
|
|
|
|
wordtwit_post_info:
|
|
|
|
- 'O:8:"stdClass":13:{s:6:"manual";b:0;s:11:"tweet_times";i:1;s:5:"delay";i:0;s:7:"enabled";i:1;s:10:"separation";s:2:"60";s:7:"version";s:3:"3.7";s:14:"tweet_template";b:0;s:6:"status";i:2;s:6:"result";a:0:{}s:13:"tweet_counter";i:2;s:13:"tweet_log_ids";a:1:{i:0;i:4381;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}'
|
|
|
|
categories:
|
|
|
|
- gauche
|
|
|
|
- Lisp
|
|
|
|
|
|
|
|
---
|
|
|
|
<div class="section">
|
|
|
|
<p>
|
|
|
|
ゆっくりと勉強は進行中。今日は入出力です。
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<h4>
|
|
|
|
入力(文字や行を読み取る)
|
|
|
|
</h4>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
readなどの手続きを用いるようです。
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<h4>
|
|
|
|
出力
|
|
|
|
</h4>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
このような手続きがある:
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<th>
|
|
|
|
write
|
|
|
|
</th>
|
|
|
|
|
|
|
|
<td>
|
|
|
|
引数に渡されたオブジェクトの外部表現を出力します
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
<th>
|
|
|
|
display
|
|
|
|
</th>
|
|
|
|
|
|
|
|
<td>
|
|
|
|
引数に渡されたオブジェクトそれぞれが読みやすい形で出力します
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
<th>
|
|
|
|
print
|
|
|
|
</th>
|
|
|
|
|
|
|
|
<td>
|
|
|
|
displayと基本的に同じだけど、最後に改行を挿入します
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
<th>
|
|
|
|
format
|
|
|
|
</th>
|
|
|
|
|
|
|
|
<td>
|
|
|
|
C言語でいうところのprintfです
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
formatについては
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<pre class="syntax-highlight">
|
|
|
|
<span class="synSpecial">(</span><span class="synStatement">format</span> <出力先> <書式指定> <引数><span class="synSpecial">)</span>
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
という使い方です。出力先は#tの場合、デフォルトでは標準出力にフォーマットされた結果が出力される。#fの場合、formatした結果を戻り値とする。書式指定には以下のようなパラメータがあるよ:
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<th>
|
|
|
|
~d
|
|
|
|
</th>
|
|
|
|
|
|
|
|
<th>
|
|
|
|
~b
|
|
|
|
</th>
|
|
|
|
|
|
|
|
<th>
|
|
|
|
~o
|
|
|
|
</th>
|
|
|
|
|
|
|
|
<th>
|
|
|
|
~x
|
|
|
|
</th>
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
10進数
|
|
|
|
</td>
|
|
|
|
|
|
|
|
<td>
|
|
|
|
2進数
|
|
|
|
</td>
|
|
|
|
|
|
|
|
<td>
|
|
|
|
8進数
|
|
|
|
</td>
|
|
|
|
|
|
|
|
<td>
|
|
|
|
16進数
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<h5>
|
|
|
|
例
|
|
|
|
</h5>
|
|
|
|
|
|
|
|
<pre class="syntax-highlight">
|
|
|
|
gosh> <span class="synSpecial">(</span><span class="synStatement">write</span> <span class="synConstant">123</span><span class="synSpecial">)</span>
|
|
|
|
<span class="synConstant">123</span>#<undef>
|
|
|
|
gosh> <span class="synSpecial">(</span>display #\a<span class="synSpecial">)</span>
|
|
|
|
a#<undef>
|
|
|
|
gosh> <span class="synSpecial">(</span>display <span class="synConstant">"Gauche\n"</span><span class="synSpecial">)</span>
|
|
|
|
Gauche
|
|
|
|
#<undef>
|
|
|
|
gosh> <span class="synSpecial">(</span><span class="synStatement">print</span> <span class="synConstant">"gauche"</span><span class="synSpecial">)</span>
|
|
|
|
gauche
|
|
|
|
#<undef>
|
|
|
|
gosh> <span class="synSpecial">(</span><span class="synStatement">format</span> #f <span class="synConstant">"Result = |~10@a|\n"</span> <span class="synSpecial">(</span><span class="synStatement">*</span> <span class="synConstant">3</span> <span class="synConstant">4</span><span class="synSpecial">))</span>
|
|
|
|
<span class="synConstant">"Result = | 12|\n"</span>
|
|
|
|
gosh> <span class="synSpecial">(</span><span class="synStatement">format</span> #t <span class="synConstant">"Result = |~10@a|\n"</span> <span class="synSpecial">(</span><span class="synStatement">*</span> <span class="synConstant">3</span> <span class="synConstant">4</span><span class="synSpecial">))</span>
|
|
|
|
Result <span class="synStatement">=</span> | <span class="synConstant">12</span>|
|
|
|
|
#<undef>
|
|
|
|
</pre>
|
2019-04-02 16:06:15 +00:00
|
|
|
</div>
|