123 lines
10 KiB
Markdown
123 lines
10 KiB
Markdown
---
|
|
title: isbn13からisbn10を求めるlispスクリプト
|
|
author: kazu634
|
|
date: 2008-11-07
|
|
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:4363;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}'
|
|
categories:
|
|
- gauche
|
|
- Lisp
|
|
|
|
---
|
|
<div class="section">
|
|
<p>
|
|
「<a href="http://d.hatena.ne.jp/sirocco634/20081026/1224993758" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/sirocco634/20081026/1224993758', ' isbn13からisbn10を求めるスクリプトを作る(途中) – 武蔵の日記');" target="_blank"> isbn13からisbn10を求めるスクリプトを作る(途中) – 武蔵の日記</a>」の続きです。
|
|
</p>
|
|
|
|
<blockquote>
|
|
<ul>
|
|
<li>
|
|
「isbn」に関連する最近のエントリ <ul>
|
|
<li>
|
|
<a href="http://d.hatena.ne.jp/sirocco634/20081026/1224993758" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/sirocco634/20081026/1224993758', ' isbn13からisbn10を求めるスクリプトを作る(途中) – 武蔵の日記');" target="_blank"> isbn13からisbn10を求めるスクリプトを作る(途中) – 武蔵の日記</a>
|
|
</li>
|
|
<li>
|
|
<a href="http://d.hatena.ne.jp/sirocco634/20080702/1215008700" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/sirocco634/20080702/1215008700', ' isbn13 –&gt; isbn10 – 武蔵の日記');" target="_blank"> isbn13 –> isbn10 – 武蔵の日記</a>
|
|
</li>
|
|
<li>
|
|
<a href="http://d.hatena.ne.jp/sirocco634/20080209/4797336803" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/sirocco634/20080209/4797336803', '武蔵の日記');" target="_blank">武蔵の日記</a>
|
|
</li>
|
|
<li>
|
|
<a href="http://d.hatena.ne.jp/sirocco634/20071208/1197124331" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/sirocco634/20071208/1197124331', ' スクリプト起動時に引数をもらう – 武蔵の日記');" target="_blank"> スクリプト起動時に引数をもらう – 武蔵の日記</a>
|
|
</li>
|
|
<li>
|
|
<a href="http://d.hatena.ne.jp/sirocco634/20071206/1196942024" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/sirocco634/20071206/1196942024', ' ちょっとミスしてた – 武蔵の日記');" target="_blank"> ちょっとミスしてた – 武蔵の日記</a>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</blockquote>
|
|
|
|
<p>
|
|
<a name="seemore"></a>
|
|
</p>
|
|
|
|
<p>
|
|
前回まではここまでできました。
|
|
</p>
|
|
|
|
<pre class="syntax-highlight">
|
|
<span class="synComment">;; 9784774135045</span>
|
|
<span class="synSpecial">(</span>define <span class="synSpecial">(</span>isbn arg<span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span><span class="synStatement">if</span> <span class="synSpecial">(</span>rxmatch #/\d\d\d\d\d\d\d\d\d\d\d\d\d/ <span class="synSpecial">(</span>number->string arg<span class="synSpecial">))</span>
|
|
<span class="synSpecial">(</span><span class="synStatement">print</span> <span class="synConstant">"Match"</span><span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span><span class="synStatement">print</span> <span class="synConstant">"Not match"</span><span class="synSpecial">)))</span>
|
|
<span class="synSpecial">(</span>define <span class="synSpecial">(</span>number->list <span class="synStatement">number</span><span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>define <span class="synSpecial">(</span><span class="synStatement">loop</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> <span class="synSpecial">'()</span>]
|
|
[else <span class="synSpecial">(</span><span class="synStatement">cons</span> <span class="synSpecial">(</span>digit->integer <span class="synSpecial">(</span><span class="synStatement">car</span> lis<span class="synSpecial">))</span> <span class="synSpecial">(</span><span class="synStatement">loop</span> <span class="synSpecial">(</span><span class="synStatement">cdr</span> lis<span class="synSpecial">)))</span>]<span class="synSpecial">))</span>
|
|
<span class="synSpecial">(</span><span class="synStatement">let</span> <span class="synSpecial">((</span>num_list <span class="synSpecial">(</span>string->list <span class="synSpecial">(</span>number->string <span class="synStatement">number</span><span class="synSpecial">))))</span>
|
|
<span class="synSpecial">(</span><span class="synStatement">loop</span> num_list<span class="synSpecial">)))</span>
|
|
</pre>
|
|
|
|
<p>
|
|
今回は13桁の数字から必要な部分を抜き出して、チェックディジットを求める巻数を作りました。
|
|
</p>
|
|
|
|
<pre class="syntax-highlight">
|
|
<span class="synComment">;; isbn13から必要な部分だけを抜き出してリストにする</span>
|
|
<span class="synSpecial">(</span>define <span class="synSpecial">(</span>split-list <span class="synStatement">list</span><span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>drop-right <span class="synSpecial">(</span>take-right <span class="synStatement">list</span> <span class="synConstant">10</span><span class="synSpecial">)</span> <span class="synConstant">1</span><span class="synSpecial">))</span>
|
|
<span class="synSpecial">(</span>define <span class="synSpecial">(</span>chkdigit num<span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>define <span class="synSpecial">(</span>proc <span class="synStatement">list</span><span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span><span class="synStatement">cond</span> [<span class="synSpecial">(</span><span class="synStatement">null</span>? <span class="synStatement">list</span><span class="synSpecial">)</span> <span class="synConstant"></span>]
|
|
[else <span class="synSpecial">(</span><span class="synStatement">+</span> <span class="synSpecial">(</span><span class="synStatement">*</span> <span class="synSpecial">(</span><span class="synStatement">car</span> <span class="synStatement">list</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synStatement">+</span> <span class="synConstant">1</span> <span class="synSpecial">(</span><span class="synStatement">length</span> <span class="synStatement">list</span><span class="synSpecial">)))</span> <span class="synSpecial">(</span>proc <span class="synSpecial">(</span><span class="synStatement">cdr</span> <span class="synStatement">list</span><span class="synSpecial">)))</span>]<span class="synSpecial">))</span>
|
|
<span class="synSpecial">(</span><span class="synStatement">let</span> <span class="synSpecial">((</span>result <span class="synSpecial">(</span><span class="synStatement">-</span> <span class="synConstant">11</span> <span class="synSpecial">(</span>modulo <span class="synSpecial">(</span>proc <span class="synSpecial">(</span>split-list <span class="synSpecial">(</span>number->list num<span class="synSpecial">)))</span> <span class="synConstant">11</span><span class="synSpecial">))))</span>
|
|
<span class="synSpecial">(</span><span class="synStatement">if</span> <span class="synSpecial">(</span><span class="synStatement">=</span> result <span class="synConstant">10</span><span class="synSpecial">)</span>
|
|
<span class="synSpecial">'</span><span class="synIdentifier">X</span>
|
|
result<span class="synSpecial">)))</span>
|
|
gosh> <span class="synSpecial">(</span>define isbn13 <span class="synConstant">9784873113487</span><span class="synSpecial">)</span>
|
|
isbn<span class="synConstant">13</span>
|
|
gosh> <span class="synSpecial">(</span>chkdigit isbn13<span class="synSpecial">)</span>
|
|
<span class="synConstant">2</span>
|
|
</pre>
|
|
|
|
<p>
|
|
fold使うともっとelegantなんじゃなかろうかと思っているから、考え中。
|
|
</p>
|
|
|
|
<div class="hatena-asin-detail">
|
|
<a href="http://www.amazon.co.jp/dp/4873113482/?tag=hatena_st1-22&ascsubtag=d-7ibv" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://www.amazon.co.jp/dp/4873113482/?tag=hatena_st1-22&ascsubtag=d-7ibv', '');"><img src="https://images-na.ssl-images-amazon.com/images/I/51Exg14b4uL._SL160_.jpg" class="hatena-asin-detail-image" alt="プログラミングGauche" title="プログラミングGauche" /></a></p>
|
|
|
|
<div class="hatena-asin-detail-info">
|
|
<p class="hatena-asin-detail-title">
|
|
<a href="http://www.amazon.co.jp/dp/4873113482/?tag=hatena_st1-22&ascsubtag=d-7ibv" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://www.amazon.co.jp/dp/4873113482/?tag=hatena_st1-22&ascsubtag=d-7ibv', 'プログラミングGauche');">プログラミングGauche</a>
|
|
</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<span class="hatena-asin-detail-label">作者:</span> <a href="http://d.hatena.ne.jp/keyword/Kahua%A5%D7%A5%ED%A5%B8%A5%A7%A5%AF%A5%C8" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/Kahua%A5%D7%A5%ED%A5%B8%A5%A7%A5%AF%A5%C8', 'Kahuaプロジェクト');" class="keyword">Kahuaプロジェクト</a>,<a href="http://d.hatena.ne.jp/keyword/%C0%EE%B9%E7%BB%CB%CF%AF" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%C0%EE%B9%E7%BB%CB%CF%AF', '川合史朗');" class="keyword">川合史朗</a>
|
|
</li>
|
|
<li>
|
|
<span class="hatena-asin-detail-label">出版社/メーカー:</span> <a href="http://d.hatena.ne.jp/keyword/%A5%AA%A5%E9%A5%A4%A5%EA%A1%BC%A5%B8%A5%E3%A5%D1%A5%F3" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%A5%AA%A5%E9%A5%A4%A5%EA%A1%BC%A5%B8%A5%E3%A5%D1%A5%F3', 'オライリージャパン');" class="keyword">オライリージャパン</a>
|
|
</li>
|
|
<li>
|
|
<span class="hatena-asin-detail-label">発売日:</span> 2008/03/14
|
|
</li>
|
|
<li>
|
|
<span class="hatena-asin-detail-label">メディア:</span> 大型本
|
|
</li>
|
|
<li>
|
|
<span class="hatena-asin-detail-label">購入</span>: 22人 <span class="hatena-asin-detail-label">クリック</span>: 713回
|
|
</li>
|
|
<li>
|
|
<a href="http://d.hatena.ne.jp/asin/4873113482" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/asin/4873113482', 'この商品を含むブログ (272件) を見る');" target="_blank">この商品を含むブログ (272件) を見る</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="hatena-asin-detail-foot">
|
|
</div>
|
|
</div>
|
|
</div>
|