blog/content/post/2008/09/27/2008-09-27-00001038.md

98 lines
14 KiB
Markdown
Raw Normal View History

2019-03-31 11:00:21 +00:00
---
title: 自分でmaxを定義してみる
author: kazu634
date: 2008-09-27
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:4307;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}'
categories:
- gauche
- Lisp
---
<div class="section">
<p>
もしや
</p>
<pre class="syntax-highlight">
<span class="synSpecial">(</span>define <span class="synSpecial">(</span>my_max<span class="synStatement"> . </span>lis<span class="synSpecial">)</span>
<span class="synSpecial">(</span><span class="synStatement">cond</span> [<span class="synSpecial">(</span><span class="synStatement">null</span>? lis<span class="synSpecial">)</span> #f]
[<span class="synSpecial">(</span><span class="synStatement">=</span> <span class="synSpecial">(</span>my_length lis<span class="synSpecial">)</span> <span class="synConstant">1</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">car</span> lis<span class="synSpecial">)</span>]
[<span class="synSpecial">(</span><span class="synStatement">=</span> <span class="synSpecial">(</span>my_length lis<span class="synSpecial">)</span> <span class="synConstant">2</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cond</span> [<span class="synSpecial">(</span><span class="synStatement">&#60;=</span> <span class="synSpecial">(</span><span class="synStatement">car</span> lis<span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cadr</span> lis<span class="synSpecial">))</span> <span class="synSpecial">(</span><span class="synStatement">cadr</span> lis<span class="synSpecial">)</span>]
[<span class="synSpecial">(</span><span class="synStatement">&#62;=</span> <span class="synSpecial">(</span><span class="synStatement">car</span> lis<span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cadr</span> lis<span class="synSpecial">))</span> <span class="synSpecial">(</span><span class="synStatement">car</span> lis<span class="synSpecial">)</span>]<span class="synSpecial">)</span>]
[<span class="synSpecial">(</span><span class="synStatement">&#62;=</span> <span class="synSpecial">(</span>my_length lis<span class="synSpecial">)</span> <span class="synConstant">3</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cond</span> [<span class="synSpecial">(</span><span class="synStatement">&#60;=</span> <span class="synSpecial">(</span><span class="synStatement">car</span> lis<span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cadr</span> lis<span class="synSpecial">))</span> <span class="synSpecial">(</span>my_max <span class="synSpecial">(</span><span class="synStatement">cons</span> <span class="synSpecial">(</span><span class="synStatement">cadr</span> lis<span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cddr</span> lis<span class="synSpecial">)))</span>]
[<span class="synSpecial">(</span><span class="synStatement">&#62;=</span> <span class="synSpecial">(</span><span class="synStatement">car</span> lis<span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cadr</span> lis<span class="synSpecial">))</span> <span class="synSpecial">(</span>my_max <span class="synSpecial">(</span><span class="synStatement">cons</span> <span class="synSpecial">(</span><span class="synStatement">car</span> lis<span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cddr</span> lis<span class="synSpecial">)))</span>]<span class="synSpecial">)</span>]<span class="synSpecial">))</span>
gosh&#62; <span class="synSpecial">(</span>my_max <span class="synConstant">1</span> <span class="synConstant">2</span> <span class="synConstant">3</span> <span class="synConstant">4</span> <span class="synConstant">5</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span><span class="synConstant">2</span> <span class="synConstant">3</span> <span class="synConstant">4</span> <span class="synConstant">5</span><span class="synSpecial">)</span>
</pre>
<p>
になるのは、consすると二回目のmy_maxの引数の数が1だと思われているからちょっとがんばってみよう。
</p>
<blockquote>
<ul>
<li>
「gauche」に関連する最近のエントリ <ul>
<li>
<a href="http://d.hatena.ne.jp/sirocco634/20080924/1222268296" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/sirocco634/20080924/1222268296', ' 自力でmaxを定義する &#8211; なにかうまくいかないや &#8211; 武蔵の日記');" target="_blank"> 自力でmaxを定義する &#8211; なにかうまくいかないや &#8211; 武蔵の日記</a>
</li>
<li>
<a href="http://d.hatena.ne.jp/sirocco634/20080923/1222179326" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/sirocco634/20080923/1222179326', ' 『プログラミングGauche』自分でmaxを定義してみるアイディアを練ってみる &#8211; 武蔵の日記');" target="_blank"> 『プログラミングGauche』自分でmaxを定義してみるアイディアを練ってみる &#8211; 武蔵の日記</a>
</li>
<li>
<a href="http://d.hatena.ne.jp/sirocco634/20080921/1221983678" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/sirocco634/20080921/1221983678', ' 車輪の再発名だけど、ユークリッドの互除法 &#8211; 武蔵の日記');" target="_blank"> 車輪の再発名だけど、ユークリッドの互除法 &#8211; 武蔵の日記</a>
</li>
<li>
<a href="http://d.hatena.ne.jp/sirocco634/20080915/4062138271" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/sirocco634/20080915/4062138271', '武蔵の日記');" target="_blank">武蔵の日記</a>
</li>
</ul>
</li>
</ul>
</blockquote>
<p>
追記:
</p>
<pre class="syntax-highlight">
<span class="synSpecial">(</span>define <span class="synSpecial">(</span>my_max<span class="synStatement"> . </span>lis<span class="synSpecial">)</span>
<span class="synSpecial">(</span><span class="synStatement">cond</span> [<span class="synSpecial">(</span><span class="synStatement">null</span>? lis<span class="synSpecial">)</span> #f]
[<span class="synSpecial">(</span><span class="synStatement">=</span> <span class="synSpecial">(</span>my_length lis<span class="synSpecial">)</span> <span class="synConstant">1</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">car</span> lis<span class="synSpecial">)</span>]
[<span class="synSpecial">(</span><span class="synStatement">=</span> <span class="synSpecial">(</span>my_length lis<span class="synSpecial">)</span> <span class="synConstant">2</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cond</span> [<span class="synSpecial">(</span><span class="synStatement">&#60;=</span> <span class="synSpecial">(</span><span class="synStatement">car</span> lis<span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cadr</span> lis<span class="synSpecial">))</span> <span class="synSpecial">(</span><span class="synStatement">cadr</span> lis<span class="synSpecial">)</span>]
[<span class="synSpecial">(</span><span class="synStatement">&#62;=</span> <span class="synSpecial">(</span><span class="synStatement">car</span> lis<span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cadr</span> lis<span class="synSpecial">))</span> <span class="synSpecial">(</span><span class="synStatement">car</span> lis<span class="synSpecial">)</span>]<span class="synSpecial">)</span>]
[<span class="synSpecial">(</span><span class="synStatement">&#62;=</span> <span class="synSpecial">(</span>my_length lis<span class="synSpecial">)</span> <span class="synConstant">3</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cond</span> [<span class="synSpecial">(</span><span class="synStatement">&#60;=</span> <span class="synSpecial">(</span><span class="synStatement">car</span> lis<span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cadr</span> lis<span class="synSpecial">))</span> <span class="synSpecial">(</span><span class="synStatement">car</span> <span class="synSpecial">(</span><span class="synStatement">cons</span> <span class="synSpecial">(</span><span class="synStatement">cadr</span> lis<span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cddr</span> lis<span class="synSpecial">)))</span>]
[<span class="synSpecial">(</span><span class="synStatement">&#62;=</span> <span class="synSpecial">(</span><span class="synStatement">car</span> lis<span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cadr</span> lis<span class="synSpecial">))</span> <span class="synSpecial">(</span><span class="synStatement">car</span> <span class="synSpecial">(</span><span class="synStatement">cons</span> <span class="synSpecial">(</span><span class="synStatement">car</span> lis<span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cddr</span> lis<span class="synSpecial">)))</span>]<span class="synSpecial">)</span>]<span class="synSpecial">))</span>
gosh&#62; <span class="synSpecial">(</span>my_max <span class="synConstant">1</span> <span class="synConstant">2</span> <span class="synConstant">3</span> <span class="synConstant">4</span> <span class="synConstant">5</span><span class="synSpecial">)</span>
<span class="synConstant">2</span>
</pre>
<p>
となるから自分の勘違いかな?
</p>
<p>
追記の追記:
</p>
<pre class="syntax-highlight">
<span class="synSpecial">(</span>define <span class="synSpecial">(</span>my_max<span class="synStatement"> . </span>lis<span class="synSpecial">)</span>
<span class="synSpecial">(</span><span class="synStatement">cond</span> [<span class="synSpecial">(</span><span class="synStatement">null</span>? #?=lis<span class="synSpecial">)</span> #f]
[<span class="synSpecial">(</span><span class="synStatement">=</span> <span class="synSpecial">(</span>my_length lis<span class="synSpecial">)</span> <span class="synConstant">1</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">car</span> lis<span class="synSpecial">)</span>]
[<span class="synSpecial">(</span><span class="synStatement">=</span> <span class="synSpecial">(</span>my_length lis<span class="synSpecial">)</span> <span class="synConstant">2</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cond</span> [<span class="synSpecial">(</span><span class="synStatement">&#60;=</span> <span class="synSpecial">(</span><span class="synStatement">car</span> lis<span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cadr</span> lis<span class="synSpecial">))</span> <span class="synSpecial">(</span><span class="synStatement">cadr</span> lis<span class="synSpecial">)</span>]
[<span class="synSpecial">(</span><span class="synStatement">&#62;=</span> <span class="synSpecial">(</span><span class="synStatement">car</span> lis<span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cadr</span> lis<span class="synSpecial">))</span> <span class="synSpecial">(</span><span class="synStatement">car</span> lis<span class="synSpecial">)</span>]<span class="synSpecial">)</span>]
[<span class="synSpecial">(</span><span class="synStatement">&#62;=</span> <span class="synSpecial">(</span>my_length lis<span class="synSpecial">)</span> <span class="synConstant">3</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cond</span> [<span class="synSpecial">(</span><span class="synStatement">&#60;=</span> <span class="synSpecial">(</span><span class="synStatement">car</span> lis<span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cadr</span> lis<span class="synSpecial">))</span> <span class="synSpecial">(</span>my_max <span class="synSpecial">(</span><span class="synStatement">cons</span> <span class="synSpecial">(</span><span class="synStatement">cadr</span> lis<span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cddr</span> lis<span class="synSpecial">)))</span>]
[<span class="synSpecial">(</span><span class="synStatement">&#62;=</span> <span class="synSpecial">(</span><span class="synStatement">car</span> lis<span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cadr</span> lis<span class="synSpecial">))</span> <span class="synSpecial">(</span>my_max <span class="synSpecial">(</span><span class="synStatement">cons</span> <span class="synSpecial">(</span><span class="synStatement">car</span> lis<span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">cddr</span> lis<span class="synSpecial">)))</span>]<span class="synSpecial">)</span>]<span class="synSpecial">))</span>
gosh&#62; <span class="synSpecial">(</span>my_max <span class="synConstant">1</span> <span class="synConstant">2</span> <span class="synConstant">3</span> <span class="synConstant">4</span> <span class="synConstant">5</span><span class="synSpecial">)</span>
#?=lis
#?<span class="synStatement">-</span> <span class="synSpecial">(</span><span class="synConstant">1</span> <span class="synConstant">2</span> <span class="synConstant">3</span> <span class="synConstant">4</span> <span class="synConstant">5</span><span class="synSpecial">)</span>
#?=lis
#?<span class="synStatement">-</span> <span class="synSpecial">((</span><span class="synConstant">2</span> <span class="synConstant">3</span> <span class="synConstant">4</span> <span class="synConstant">5</span><span class="synSpecial">))</span>
<span class="synSpecial">(</span><span class="synConstant">2</span> <span class="synConstant">3</span> <span class="synConstant">4</span> <span class="synConstant">5</span><span class="synSpecial">)</span>
</pre>
<p>
いや、勘違いじゃなかったぞ!
</p>
</div>