98 lines
14 KiB
Markdown
98 lines
14 KiB
Markdown
---
|
||
title: 自分でmaxを定義してみる
|
||
author: kazu634
|
||
date: 2008-09-27
|
||
url: /2008/09/27/_1115/
|
||
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"><=</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">>=</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">>=</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"><=</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">>=</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> <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を定義する – なにかうまくいかないや – 武蔵の日記');" target="_blank"> 自力でmaxを定義する – なにかうまくいかないや – 武蔵の日記</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を定義してみる(アイディアを練ってみる) – 武蔵の日記');" target="_blank"> 『プログラミングGauche』自分でmaxを定義してみる(アイディアを練ってみる) – 武蔵の日記</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', ' 車輪の再発名だけど、ユークリッドの互除法 – 武蔵の日記');" target="_blank"> 車輪の再発名だけど、ユークリッドの互除法 – 武蔵の日記</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"><=</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">>=</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">>=</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"><=</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">>=</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> <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"><=</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">>=</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">>=</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"><=</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">>=</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> <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> |