継続は力にゃりん。毎日続けることができるのか? とばし * 定義 define-in-module、4.11 モジュール * 5. マクロ * 6.7 Identifier * 6.15.3 継続 * 6.16 例外 * 6.18.2 ポートとスレッド * 6.18 入出力 途中不明多し * 6.21.6 シグナル * オブジェクトシステム 途中から Gauche拡張モジュール 残り * gauche.fcntl - 低レベルファイル操作 * gauche.hook - フック * gauche.listener - リスナー * gauche.logger - ユーザレベルのロギング * gauche.mop.singleton - シングルトン * gauche.mop.validator - Validator付きスロット * gauche.net - ネットワーキング * gauche.parameter - パラメータ * gauche.parseopt - コマンドライン引数の解析 * gauche.reload - モジュールの再ロード * gauche.selector - 簡単なディスパッチャ * gauche.syslog - Syslog * gauche.termios - Termios * gauche.test - 単体テスト * gauche.threads - スレッド * gauche.time - 時間の計測 * gauche.uvector - ユニフォームベクタ * gauche.vport - 仮想ポート SRFI 残り * srfi-7 - 機能ベースプログラム設定言語 * srfi-29 - 地域化 ライブラリモジュール - ユーティリティ 残り * binary.io - バイナリI/O * binary.pack - バイナリデータのパック * dbi - Database independent access layer * dbm.ndbm - NDBMインタフェース * dbm.odbm - オリジナルのDBMインタフェース * file.filter - ファイルのフィルタ * math.mt-random - Mersenne Twister乱数発生器 * rfc.822 - RFC822メッセージ形式 * rfc.base64 - Base64エンコーディング * rfc.cookie - HTTPクッキー * rfc.hmac - HMAC鍵付きハッシング * rfc.md5 - MD5メッセージダイジェスト * rfc.mime - MIMEメッセージ処理 * rfc.quoted-printable - Quoted-printableエンコーディング * rfc.sha1 - SHA1メッセージダイジェスト * slib - SLIBインタフェース * sxml.ssax - 関数的なXMLパーザ * sxml.sxpath - SXMLクエリ言語 * sxml.tools - SXML構造を操作する * SXMLからXMLとXHTMLのシリアライゼーション * text.gettext - 地域化メッセージ * text.sql - SQL parsing and construction * util.digest - メッセージダイジェストフレームワーク * util.isomorph - 同型判定 * util.lcs - 最長共通サブシーケンス * util.match - パターンマッチング * util.rbtree - 赤黒木 * util.record - SLIB-互換のレコード型 * util.relation - Relation framework * util.stream - ストリームライブラリ * util.toposort - トポロジカルソート * www.cgi - CGIユーティリティ * www.cgi-test - CGIのテスト 進捗 * 2007-11-06 中断、休眠 * 2007-11-05 ライブラリモジュール - ユーティリティ compat.norational - 有理数のない算術演算 * 2007-10-20 ライブラリモジュール - ユーティリティ dbm.gdbm - GDBMインタフェース * 2007-10-08 ライブラリモジュール - ユーティリティ dbm - 汎用DBMインタフェース * 2007-09-21 Treemaps * 2007-09-04 Ruby との比較 集合 * 2007-08-28 Ruby との比較 Dir * 2007-07-23 Ruby との比較 File * 2007-07-06 fold 祭り * 2007-06-13 Ruby との比較 Hash * 2007-06-01 Ruby との比較 Array(Enumerable、リストで) * 2007-04-12 Ruby との比較 Array (リストで) * 2007-02-15 Ruby との比較 文字列 * 2006-12-28 Ruby との比較 数 * 2006-12-24 Ruby との比較 Bool * 2006-12-21 ライブラリモジュール - ユーティリティ rfc.http - HTTP * 2006-12-19 ライブラリモジュール - ユーティリティ text.diff - テキストストリームの相違点を計算する * 2006-11-26 ライブラリモジュール - ユーティリティ util.trie - Trie * 2006-10-29 ライブラリモジュール - Gauche拡張モジュール gauche.process * 2006-10-26 ライブラリモジュール - ユーティリティ text.tree - 怠惰なテキスト構築 * 2006-10-24 ライブラリモジュール - ユーティリティ text.csv - CSVテーブル * 2006-10-23 ライブラリモジュール - SRFI srfi-55 - Requiring extensions * 2006-10-17 ライブラリモジュール - SRFI srfi-37 - args-fold プログラム引数処理 * 2006-10-16 ライブラリモジュール - SRFI srfi-5 - シグネチャとrest引数に互換性のあるlet形式 * 2006-10-15 ライブラリモジュール - SRFI srfi-9 - レコード型 * 2006-09-18 ライブラリモジュール - SRFI srfi-42 - Eager comprehensions * 2006-09-14 ライブラリモジュール - ユーティリティ text.parse - 入力ストリームのパージング * 2006-09-10 ライブラリモジュール - ユーティリティ text.html-lite - シンプルなHTMLドキュメントの構築 * 2006-08-28 ライブラリモジュール - ユーティリティ util.queue - キュー * 2006-07-23 ライブラリモジュール - ユーティリティ file.util - ファイルシステムユーティリティ * 2006-07-15 ライブラリモジュール - ユーティリティ text.parse - 入力ストリームのパージング * 2006-07-06 ライブラリモジュール - ユーティリティ rfc.uri - URIの解析と作成 * 2006-07-03 ライブラリモジュール - ユーティリティ text.tr - 文字変換 * 2006-06-25 ライブラリモジュール - ユーティリティ util.combinations - 組み合わせ * 2006-06-11 ライブラリモジュール - ユーティリティ util.list - その他のリストライブラリ * 2006-06-09 ライブラリモジュール - ユーティリティ math.const - 定数 * 2006-04-26 ライブラリモジュール - SRFI srfi-14 - 文字集合ライブラリ * 2006-04-02 ライブラリモジュール - SRFI srfi-43 - Vector library * 2006-03-31 ライブラリモジュール - SRFI srfi-11 - Let-values * 2006-03-06 ライブラリモジュール - SRFI srfi-19 - 時間のデータ型と手続き * 2006-02-24 ライブラリモジュール - SRFI srfi-27 - ランダムビットのソース * 2006-01-13 ライブラリモジュール - SRFI srfi-13 - 文字列ライブラリ * 2005-11-10 ライブラリモジュール - SRFI srfi-1 - List library * 2005-11-09 ライブラリモジュール - SRFI srfi-0 - 機能条件式 * 2005-10-31 ライブラリモジュール - Gauche拡張モジュール gauche.charconv * 2005-09-25 ライブラリモジュール - Gauche拡張モジュール gauche.array * 2005-09-16 ライブラリモジュール - Gauche拡張モジュール gauche.sequence * 2005-08-22 ライブラリモジュール - Gauche拡張モジュール gauche.collection * 2005-08-15 ライブラリモジュール - Gauche拡張モジュール gauche.regexp * 2005-08-11 ライブラリモジュール - Gauche拡張モジュール gauche.interactive * 2005-08-10 ライブラリモジュール - Gauche拡張モジュール gauche.config * 2005-08-08 ライブラリモジュール - Gauche拡張モジュール gauche.version * 2005-07-31 オブジェクトシステム * 2005-07-28 開発補助API * 2005-05-06 システムインタフェース * 2005-04-30 比較とソート * 2005-04-20 プログラムのロード * 2005-02-19 入出力 * 2005-02-16 eval と repl * 2005-01-24 制御 * 2005-01-21 Weak ポインタ * 2005-01-04 ハッシュテーブル * 2004-12-22 ベクタ * 2004-12-11 正規表現 * 2004-11-12 文字列 * 2004-11-06 文字集合 * 2004-10-26 文字 * 2004-10-21 キーワード * 2004-10-16 シンボル * 2004-09-27 ペアとリスト * 2004-09-26 論理値 * 2004-08-17 数値 * 2004-08-13 等価 !2007-11-05 Mon まんま gosh> (/ 2 3) 2/3 gosh> (/ 5) 1/5 gosh> (/ 4 2) 2 gosh> (use compat.norational) # gosh> (/ 2 3) 0.6666666666666666 gosh> (/ 5) 0.2 gosh> (/ 4 2) 2 gosh> 1/3 1/3 gosh> #i1/3 0.3333333333333333 !2007-11-04 Sun gosh> (use dbm) # gosh> (use dbm.gdbm) # gosh> (gdbm-version) "GDBM version 1.8.3. 10/15/2002 (built Sep 9 2003 00:02:26)" gdbm-errno って何? gdbm.stub にはあるみたいだけど(←報告済) gosh> (use dbm) # gosh> (use dbm.gdbm) # gosh> (with-module dbm.gdbm (export GDBM_SYNCMODE gdbm-errno)) # gosh> (gdbm-errno) 0 !2007-11-03 Sat gosh> (use dbm) # gosh> (use dbm.gdbm) # gosh> (define *db* (gdbm-open "mydb" 0 GDBM_WRCREAT)) *db* gosh> (gdbm-setopt *db* GDBM_CACHESIZE 1) 0 gosh> (gdbm-setopt *db* GDBM_FASTMODE #t) 0 gosh> (gdbm-setopt *db* GDBM_SYNCMODE #t) *** ERROR: unbound variable: GDBM_SYNCMODE Stack Trace: _______________________________________ gosh> (gdbm-setopt *db* GDBM_CENTFREE #t) 0 gosh> (gdbm-setopt *db* GDBM_COALESCEBLKS #t) 0 マニュアル間違い?「GDBM_SYNCMODE」なし(←報告済) gosh> (use dbm) # gosh> (use dbm.gdbm) # gosh> (with-module dbm.gdbm (export GDBM_SYNCMODE gdbm-errno)) # gosh> (define *db* (gdbm-open "mydb" 0 GDBM_WRCREAT)) *db* gosh> (gdbm-setopt *db* GDBM_SYNCMODE #t) 0 !2007-11-02 Fri gosh> (use dbm) # gosh> (use dbm.gdbm) # gosh> (gdbm-strerror 0) "No error" gosh> (gdbm-strerror 1) "Malloc error" gosh> (gdbm-strerror 3) "File open error" gosh> (gdbm-strerror 4) "File write error" !2007-11-01 Thu gosh> (use dbm) # gosh> (use dbm.gdbm) # gosh> (define *db* (gdbm-open "mydb" 0 GDBM_WRCREAT)) *db* gosh> (gdbm-exists *db* "key1") *** ERROR: unbound variable: gdbm-exists Stack Trace: _______________________________________ gosh> (gdbm-exists? *db* "key1") #f gosh> (gdbm-store *db* "key1" "value1") 0 gosh> (gdbm-exists? *db* "key1") #t gosh> (gdbm-delete *db* "key1") 0 gosh> (gdbm-exists? *db* "key1") #f gosh> (gdbm-close *db*) # マニュアル間違い。「?」が抜けているようだ(←報告済) !2007-10-31 Wed gosh> (use dbm) # gosh> (use dbm.gdbm) # gosh> (define *db* (gdbm-open "mydb" 0 GDBM_WRCREAT)) *db* gosh> (gdbm-sync *db*) # gosh> (gdbm-sync *db*) # gosh> (gdbm-close *db*) # !2007-10-30 Tue gosh> (use dbm) # gosh> (use dbm.gdbm) # gosh> (define *db* (gdbm-open "mydb" 0 GDBM_WRCREAT)) *db* gosh> (gdbm-reorganize *db*) 0 gosh> (gdbm-store *db* "key1" "value1") 0 gosh> (gdbm-reorganize *db*) 0 gosh> (gdbm-delete *db* "key1") 0 gosh> (gdbm-reorganize *db*) 0 gosh> (gdbm-close *db*) # !2007-10-29 Mon gosh> (use dbm) # gosh> (use dbm.gdbm) # gosh> (define *db* (gdbm-open "mydb" 0 GDBM_WRCREAT)) *db* gosh> (gdbm-store *db* "key1" "value1") 0 gosh> (gdbm-store *db* "key2" "value2") 0 gosh> (gdbm-firstkey *db*) "key2" gosh> (gdbm-nextkey *db* "key2") "key1" gosh> (gdbm-nextkey *db* "key1") #f gosh> (gdbm-close *db*) # うーむ、gdbm-nextkey で key も渡さなきゃいけないっていうのが、、、 !2007-10-28 Sun gosh> (use dbm) # gosh> (use dbm.gdbm) # gosh> (define *db* (gdbm-open "mydb" 0 GDBM_WRCREAT)) *db* gosh> (gdbm-firstkey *db*) #f gosh> (gdbm-store *db* "key1" "value1") 0 gosh> (gdbm-firstkey *db*) "key1" gosh> (gdbm-store *db* "key2" "value2") 0 gosh> (gdbm-firstkey *db*) "key2" gosh> (gdbm-close *db*) # !2007-10-27 Sat gosh> (use dbm) # gosh> (use dbm.gdbm) # gosh> (define *db* (gdbm-open "mydb" 0 GDBM_WRCREAT)) *db* gosh> (gdbm-store *db* "key1" "value1") 0 gosh> (gdbm-delete *db* "key1") 0 gosh> (gdbm-delete *db* "key1") -1 gosh> (gdbm-delete *db* "key1") -1 gosh> (gdbm-close *db*) # !2007-10-26 Fri gosh> (use dbm) # gosh> (use dbm.gdbm) # gosh> (define *db* (gdbm-open "mydb" 0 GDBM_WRCREAT)) *db* gosh> (gdbm-store *db* "key1" "value1") 0 gosh> (gdbm-fetch *db* "key1") "value1" gosh> (gdbm-store *db* "key1" "hoge") 1 gosh> (gdbm-fetch *db* "key1") "value1" gosh> (gdbm-store *db* "key1" "hoge" GDBM_INSERT) 1 gosh> (gdbm-fetch *db* "key1") "value1" gosh> (gdbm-store *db* "key1" "hoge" GDBM_REPLACE) 0 gosh> (gdbm-fetch *db* "key1") "hoge" !2007-10-25 Thu gosh> (use dbm) # gosh> (use dbm.gdbm) # gosh> (define *db* (gdbm-open "mydb" 0 GDBM_WRCREAT)) *db* gosh> (gdbm-closed? *db*) #f gosh> (gdbm-close *db*) # gosh> (gdbm-closed? *db*) #t !2007-10-24 Wed gosh> (use dbm) # gosh> (use dbm.gdbm) # gosh> GDBM_READER 0 gosh> GDBM_WRITER 1 gosh> GDBM_WRCREAT 2 gosh> GDBM_NEWDB 3 gosh> GDBM_FAST 16 gosh> GDBM_SYNC 32 gosh> GDBM_NOLOCK 64 !2007-10-23 Tue gosh> (use dbm) # gosh> (use dbm.gdbm) # gosh> (define *db* (gdbm-open "mydb")) *** ERROR: couldn't open gdbm file "mydb" (gdbm_errno=3) Stack Trace: _______________________________________ 0 (gdbm-open "mydb") At line 3 of "(stdin)" gosh> (define *db* (gdbm-open "mydb" 0 :write)) *** ERROR: small integer required, but got :write Stack Trace: _______________________________________ 0 (gdbm-open "mydb" 0 :write) At line 4 of "(stdin)" gosh> GDBM_READER 0 gosh> (define *db* (gdbm-open "mydb" 0 GDBM_WRITER)) *** ERROR: couldn't open gdbm file "mydb" (gdbm_errno=3) Stack Trace: _______________________________________ 0 (gdbm-open "mydb" 0 GDBM_WRITER) At line 6 of "(stdin)" gosh> GDBM_WRITER 1 gosh> (define *db* (gdbm-open "mydb" 0 GDBM_WRCREAT)) *db* gosh> (dbm-put! *db* "key1" "value1") *** ERROR: no applicable method for # with arguments (# "key1" "value1") Stack Trace: _______________________________________ gosh> (gdbm-store *db* "key1" "value1") 0 gosh> (gdbm-fetch *db* "key1") "value1" gosh> (gdbm-close *db*) # !2007-10-22 Mon Instance Variable of : sync Instance Variable of : nolock Instance Variable of : bsize にアクセスするにはどうすれば? gosh> (use dbm) # gosh> (use dbm.gdbm) # gosh> (define *db* (dbm-open :path "mydb" :rw-mode :write)) *db* gosh> (slot-ref *db* 'sync) #f gosh> *db* #< 0x82ae5a0> gosh> (slot-ref *db* 'nolock) #f gosh> (slot-ref *db* 'path) "mydb" gosh> (slot-ref *db* 'bsize) 0 gosh> (dbm-put! *db* "key1" "value1") # gosh> (slot-ref *db* 'bsize) 0 gosh> (dbm-close *db*) # gosh> (define *db* (dbm-open :path "mydb" :rw-mode :write)) *db* gosh> (slot-ref *db* 'bsize) 0 gosh> (dbm-close *db*) # !2007-10-21 Sun gosh> (use dbm) # gosh> *** ERROR: unbound variable: Stack Trace: _______________________________________ gosh> (use dbm.gdbm) # gosh> #> !2007-10-20 Sat dbm のところのまんま gosh> (use dbm) # gosh> (use dbm.gdbm) # gosh> (define *db* (dbm-open :path "mydb" :rw-mode :write)) *db* gosh> (dbm-put! *db* "key1" "value1") # gosh> (define val (dbm-get *db* "key1")) val gosh> (dbm-for-each *db* (lambda (key val) (foo key val))) *** ERROR: unbound variable: foo Stack Trace: _______________________________________ 0 proc gosh> (dbm-for-each *db* (lambda (key val) (print key val))) key1value1 # gosh> (dbm-close *db*) # !2007-10-19 Fri gosh> (use dbm) # gosh> (use dbm.fsdbm) # gosh> (dbm-db-exists? "mydb") #f gosh> (define *db* (dbm-open :path "mydb" :rw-mode :write)) *db* gosh> (dbm-close *db*) #t gosh> (dbm-db-move "mydb" "mydb2") *** ERROR: unbound variable: dbm-db-move ↓うむ? fsdbmは、全てのDBMプロトコルを実装しています !2007-10-18 Thu gosh> (use dbm) # gosh> (use dbm.fsdbm) # gosh> (dbm-db-exists? "mydb") #f gosh> (define *db* (dbm-open :path "mydb" :rw-mode :write)) *db* gosh> (dbm-db-copy "mydb" "mydb2") *** ERROR: dbm-db-copy: not supported in #> !2007-10-17 Wed gosh> (use dbm) # gosh> (use dbm.fsdbm) # gosh> (dbm-db-exists? "mydb") #f gosh> (dbm-db-remove "mydb") *** ERROR: given path is not an fsdbm database: mydb Stack Trace: _______________________________________ 0 (errorf "given path is not an fsdbm database: ~a" name) At line 181 of "/usr/local/share/gauche/0.8.11/lib/dbm/fsdbm.scm" gosh> (define *db* (dbm-open :path "mydb" :rw-mode :write)) *db* gosh> (dbm-db-exists? "mydb") #t gosh> (dbm-db-remove "mydb") #t gosh> (dbm-db-exists? "mydb") #f gosh> (dbm-close *db*) #t !2007-10-16 Tue gosh> (use dbm) # gosh> (use dbm.fsdbm) # gosh> (dbm-db-exists? "mydb") *** ERROR: unbound variable: Stack Trace: _______________________________________ gosh> (dbm-db-exists? "mydb") #f gosh> (define *db* (dbm-open :path "mydb" :rw-mode :write)) *db* gosh> (dbm-db-exists? "mydb") #t gosh> (dbm-close *db*) #t gosh> (dbm-db-exists? "mydb") #t gosh> (use dbm.odbm) # gosh> (dbm-db-exists? "mydb") *** ERROR: list required, but got ".pag" Stack Trace: _______________________________________ 0 (odbm-files name) At line 151 of "/usr/local/share/gauche/0.8.11/lib/dbm/odbm.scm" !2007-10-15 Mon gosh> (use dbm) # gosh> (use dbm.fsdbm) # gosh> (define *db* (dbm-open :path "mydb" :rw-mode :write)) *db* gosh> (dbm-put! *db* "key1" "1") #t gosh> (dbm-put! *db* "key2" "2") #t gosh> (dbm-put! *db* "key3" "3") #t gosh> (dbm-map *db* (lambda (k v) (number->string (+ (x->integer v) 1)))) ("2" "3" "4") gosh> (dbm-map *db* (lambda (k v) (+ (x->integer v) 1))) (2 3 4) gosh> (dbm-close *db*) #t !2007-10-14 Sun gosh> (use dbm) # gosh> (use dbm.fsdbm) # gosh> (define *db* (dbm-open :path "mydb" :rw-mode :write)) *db* gosh> (dbm-put! *db* "key1" "1") #t gosh> (dbm-put! *db* "key2" "2") #t gosh> (dbm-put! *db* "key3" "3") #t gosh> (dbm-for-each *db* (lambda (k v) (print k " " v))) key1 1 key2 2 key3 3 # gosh> (dbm-close *db*) #t !2007-10-13 Sat gosh> (use dbm) # gosh> (use dbm.fsdbm) # gosh> (define *db* (dbm-open :path "mydb" :rw-mode :write)) *db* gosh> (dbm-put! *db* "key1" "1") #t gosh> (dbm-put! *db* "key2" "2") #t gosh> (dbm-put! *db* "key3" "3") #t gosh> (dbm-fold *db* (lambda (k v r) (+ (x->integer v) r)) 0) 6 gosh> (dbm-close *db*) #t !2007-10-12 Fri gosh> (use dbm) # gosh> (use dbm.fsdbm) # gosh> (define *db* (dbm-open :path "mydb" :rw-mode :write)) *db* gosh> (dbm-put! *db* "key1" "value1") #t gosh> (dbm-exists? *db* "key1") #t gosh> (dbm-delete! *db* "key1") #t gosh> (dbm-exists? *db* "key1") #f gosh> (dbm-close *db*) #t !2007-10-11 Thu gosh> (use dbm) # gosh> (use dbm.fsdbm) # gosh> (define *db* (dbm-open :path "mydb" :rw-mode :write)) *db* gosh> (dbm-put! *db* "key1" "value1") #t gosh> (dbm-exists? *db* "key1") #t gosh> (dbm-exists? *db* "hogehoge") #f gosh> (dbm-close *db*) #t !2007-10-10 Wed gosh> (use dbm) # gosh> (use dbm.fsdbm) # gosh> (define *db* (dbm-open :path "mydb" :rw-mode :write)) *db* gosh> (dbm-put! *db* "key1" "value1") #t gosh> (dbm-get *db* "key1") "value1" gosh> (dbm-get *db* "hogehoge") *** ERROR: fsdbm: no data for key "hogehoge" in database #< 0x820fd90> Stack Trace: _______________________________________ gosh> (dbm-get *db* "hogehoge" "no") "no" gosh> (dbm-close *db*) #t !2007-10-09 Tue gosh> (use dbm) # gosh> (use dbm.fsdbm) # gosh> (define *db* (dbm-open :path "mydb" :rw-mode :write)) *db* gosh> (dbm-closed? *db*) #f gosh> (dbm-close *db*) #t gosh> (dbm-closed? *db*) #t gosh> (dbm-close *db*) #t !2007-10-08 Mon なぜか dbm.gdbm が入っていないので(gdbm.h が入っていなかったようだ…)、、、 gdbm -> fsdbm 以外はまんま gosh> (use dbm) # gosh> (use dbm.fsdbm) # gosh> (define *db* (dbm-open :path "mydb" :rw-mode :write)) *db* gosh> (dbm-put! *db* "key1" "value1") #t gosh> (define val (dbm-get *db* "key1")) val gosh> (dbm-for-each *db* (lambda (key val) (foo key val))) *** ERROR: unbound variable: foo Stack Trace: _______________________________________ gosh> (dbm-for-each *db* (lambda (key val) (display key val))) *** ERROR: output port required, but got "value1" Stack Trace: _______________________________________ gosh> (dbm-for-each *db* (lambda (key val) (display key))) key1# gosh> (dbm-for-each *db* (lambda (key val) (display val))) value1# gosh> (dbm-close *db*) #t !2007-10-07 Sun gosh> (define tree (alist->tree-map '((3 . a) (7 . b) (5 . c)) = <)) tree gosh> (tree-map->alist tree) ((3 . a) (5 . c) (7 . b)) !2007-10-06 Sat gosh> (define tree (alist->tree-map '((3 . a) (7 . b) (5 . c)) = <)) tree gosh> (tree-map-keys tree) (3 5 7) gosh> (tree-map-values tree) (a c b) !2007-10-05 Fri まんま gosh> (define tree (alist->tree-map '((3 . a) (7 . b) (5 . c)) = <)) tree gosh> (tree-map-fold tree list* '()) (7 b 5 c 3 a) gosh> (tree-map-fold-right tree list* '()) (3 a 5 c 7 b) !2007-10-04 Thu gosh> (define t (make-tree-map = <)) t gosh> (tree-map-push! t 1 "foo") # gosh> (tree-map-push! t 9 "foo") # gosh> (tree-map-pop-max! t) (9 "foo") gosh> (tree-map-pop-max! t) (1 "foo") gosh> (tree-map-pop-max! t) #f !2007-10-03 Wed gosh> (define t (make-tree-map = <)) t gosh> (tree-map-push! t 1 "foo") # gosh> (tree-map-push! t 9 "foo") # gosh> (tree-map-pop-min! t) (1 "foo") gosh> t # gosh> (tree-map-get t 1) *** ERROR: # doesn't have an entry for key 1 Stack Trace: _______________________________________ gosh> (tree-map-get t 9) ("foo") gosh> (tree-map-num-entries t) 2 !2007-10-02 Tue gosh> (define t (make-tree-map = <)) t gosh> (tree-map-push! t 1 "foo") # gosh> (tree-map-push! t 9 "foo") # gosh> (tree-map-min t) (1 "foo") gosh> (tree-map-max t) (9 "foo") !2007-10-01 Mon gosh> (define t (make-tree-map = <)) t gosh> (tree-map-push! t 1 "foo") # gosh> (tree-map-pop! t 1) "foo" gosh> (tree-map-pop! t 1) *** ERROR: #'s value for key 1 is not a pair: () Stack Trace: _______________________________________ gosh> (tree-map-pop! t 1 99) 99 !2007-09-30 Sun gosh> (define t (make-tree-map = <)) t gosh> (tree-map-push! t 1 "foo") # gosh> (tree-map-get t 1) ("foo") gosh> (tree-map-push! t 1 "bar") # gosh> (tree-map-get t 1) ("bar" "foo") !2007-09-29 Sat gosh> (define t (make-tree-map = <)) t gosh> (tree-map-update! t 1 (cut + 1 <>)) *** ERROR: # doesn't have an entry for key 1 Stack Trace: _______________________________________ gosh> (tree-map-put! t 1 10) # gosh> (tree-map-update! t 1 (cut + 1 <>)) 11 gosh> (tree-map-get t 1) 11 !2007-09-28 Fri gosh> (define t (make-tree-map = <)) t gosh> (tree-map-delete! t 1) #f gosh> (tree-map-put! t 1 "foo") # gosh> (tree-map-delete! t 1) #t !2007-09-27 Thu gosh> (define t (make-tree-map = <)) t gosh> (tree-map-put! t 1 "foo") # gosh> (tree-map-get t 1) "foo" gosh> (tree-map-put! t 1 "bar") # gosh> (tree-map-get t 1) "bar" !2007-09-26 Wed gosh> (define t (make-tree-map = <)) t gosh> (tree-map-get t 1) *** ERROR: # doesn't have an entry for key 1 Stack Trace: _______________________________________ gosh> (tree-map-get t 1 99) 99 gosh> (tree-map-put! t 1 "foo") # gosh> (tree-map-get t 1) "foo" !2007-09-25 Tue gosh> (define t (make-tree-map = <)) t gosh> (tree-map-exists? t 1) #f gosh> (tree-map-put! t 1 "foo") # gosh> (tree-map-exists? t 1) #t !2007-09-24 Mon gosh> (define t (make-tree-map = <)) t gosh> (tree-map-num-entries t) 0 gosh> (tree-map-put! t 1 "foo") # gosh> (tree-map-num-entries t) 1 !2007-09-23 Sun gosh> (define t (make-tree-map = <)) t gosh> (tree-map-empty? t) #t gosh> (tree-map-put! t 1 "foo") # gosh> (tree-map-empty? t) #f !2007-09-22 Sat gosh> (define t (make-tree-map = <)) t gosh> (tree-map-put! t 1 "foo") # gosh> t # gosh> (define t2 (tree-map-copy t)) t2 gosh> (tree-map-put! t 2 "bar") # gosh> t # gosh> t2 # !2007-09-21 Fri gosh> #> gosh> (define t (make-tree-map)) *** ERROR: wrong number of arguments for # (required 2, got 0) Stack Trace: _______________________________________ 0 (make-tree-map) At line 2 of "(stdin)" gosh> (define t (make-tree-map = <)) t !2007-09-20 Thu ; Ruby >> require "set" => true >> Set[1,2,3].classify {|o| o % 2 == 0} => {false=>#, true=>#} ; Gauche gosh> (define (set-classify s proc) (define h (make-hash-table)) (for-each (lambda (x) (begin (if (not (hash-table-exists? h (proc x))) (hash-table-put! h (proc x) (list x)) (set-cdr! (last-pair (hash-table-get h (proc x))) (list x))))) s) h) set-classify gosh> (set-classify '(1 2 3) (lambda (x) (= (remainder x 2) 0))) # gosh> (define h (set-classify '(1 2 3) (lambda (x) (= (remainder x 2) 0)))) h gosh> (hash-table-keys h) (#f #t) gosh> (hash-table-get h #t) (2) gosh> (hash-table-get h #f) (1 3) divide とばし !2007-09-19 Wed ; Ruby >> require "set" => true >> Set[1,2,3] == Set[1,2,3] => true >> Set[1,2,3] == Set[3,2,1] => true >> Set[1,2,3] == Set[1,2] => false ; Gauche gosh> (use srfi-1) # gosh> (lset= eq? '(1 2 3) '(1 2 3)) #t gosh> (lset= eq? '(1 2 3) '(3 2 1)) #t gosh> (lset= eq? '(1 2 3) '(1 2)) #f !2007-09-18 Tue ; Ruby >> require "set" => true >> Set[1,2,3] ^ Set[1,2] => # ; Gauche gosh> (use srfi-1) # gosh> (lset-xor eq? '(1 2 3) '(1 2)) (3) gosh> (lset-xor equal? '("foo" "bar" "baz") '("bar" "foo")) ("baz") !2007-09-17 Mon ; Ruby >> require "set" => true >> Set[1,2,3] & Set[1,2] => # >> Set[1,2,3] & Set[10,20,30] => # ; Gauche gosh> (use srfi-1) # gosh> (lset-intersection eq? '(1 2 3) '(1 2)) (1 2) gosh> (lset-intersection eq? '(1 2 3) '(10 20 30)) () !2007-09-16 Sun ; Ruby >> require "set" => true >> Set[1,2,3] - Set[10,20,30] => # >> Set[1,2,3] - Set[1,2,3] => # >> Set[1,2,3] - Set[1,2] => # ; Gauche gosh> (use srfi-1) # gosh> (lset-difference eq? '(1 2 3) '(10 20 30)) (1 2 3) gosh> (lset-difference eq? '(1 2 3) '(1 2 3)) () gosh> (lset-difference eq? '(1 2 3) '(1 2)) (3) !2007-09-15 Sat ; Ruby >> require "set" => true >> Set[1,2,3] + Set[10,20,30] => # >> Set[1,2,3] | Set[10,20,30] => # >> Set[1,2,3] | Set[1,2,3] => # ; Gauche gosh> (use srfi-1) # gosh> (lset-union eq? '(1 2 3) '(10 20 30)) (30 20 10 1 2 3) gosh> (lset-union equal? '(1 2 3) '(10 20 30)) (30 20 10 1 2 3) gosh> (lset-union equal? '("foo" "bar" "baz") '("foo" "hoge")) ("hoge" "foo" "bar" "baz") !2007-09-14 Fri ; Ruby >> require "set" => true >> s = Set[1,2,3] => # >> s.subtract([1,2]) => # >> s => # >> s.subtract([10]) => # ; Gauche gosh> (use srfi-1) # gosh> (lset-difference eq? '(1 2 3) '(1 2)) (3) gosh> (lset-difference eq? '(1 2 3) '(10)) (1 2 3) !2007-09-13 Thu reject! とばし ; Ruby >> require "set" => true >> s = Set[1,2,3] => # >> s.merge([10,20,30]) => # >> s => # ; Gauche gosh> (use srfi-1) # gosh> (lset-union eq? '(1 2 3) '(10 20 30)) (30 20 10 1 2 3) gosh> (lset-union equal? '(1 2 3) '(10 20 30)) (30 20 10 1 2 3) gosh> (lset-union equal? '("foo" "bar" "baz") '("foo" "hoge")) ("hoge" "foo" "bar" "baz") !2007-09-12 Wed ; Ruby >> require "set" => true >> s = Set[1,2,3] => # >> s.delete_if {|x| x % 2 == 0} => # ; Gauche gosh> (use srfi-1) # gosh> (remove (lambda (x) (= (remainder x 2) 0)) '(1 2 3)) (1 3) !2007-09-11 Tue ; Ruby >> require "set" => true >> Set[1,2,3].delete(1) => # >> Set["foo","bar","baz"].delete("foo") => # >> Set["foo","bar","baz"].delete("hoge") => # ; Gauche gosh> (use srfi-1) # gosh> (lset-difference eq? '(1 2 3) '(1)) (2 3) gosh> (lset-difference equal? '(1 2 3) '(1)) (2 3) gosh> (lset-difference equal? '("foo" "bar" "baz") '("foo")) ("bar" "baz") gosh> (lset-difference equal? '("foo" "bar" "baz") '("hoge")) ("foo" "bar" "baz") lset-difference に、ミス発見! 与えれらた場合 ↑報告済 !2007-09-10 Mon each とばし ; Ruby >> require "set" => true >> Set[1,2,3].add(4) => # >> Set[1,2,3].add(Set[4,5,6]) => #}> >> Set[1,2,3].add([4,5,6]) => # ; Gauche gosh> (use srfi-1) # gosh> (lset-adjoin eq? '(1 2 3) 4) (4 1 2 3) gosh> (lset-adjoin equal? '(1 2 3) 4) (4 1 2 3) gosh> (lset-adjoin equal? '(1 2 3) 3 4) (4 1 2 3) gosh> (lset-adjoin equal? '("foo" "bar" "baz") "foo") ("foo" "bar" "baz") gosh> (lset-adjoin equal? '("foo" "bar" "baz") "hoge") ("hoge" "foo" "bar" "baz") !2007-09-09 Sun ; Ruby >> require "set" => true >> Set[1,2,3].proper_subset?(Set[1,2,3]) => false >> Set[1,2,3].proper_subset?(Set[1,2,3,4]) => true >> Set[1,2,3].proper_subset?(Set[1,2]) => false ; Gauche gosh> (use srfi-1) # gosh> (define (proper-subset? s s2) (and (lset<= equal? s s2) (not (lset= equal? s s2)))) proper-subset? gosh> (proper-subset? '(1 2 3) '(1 2 3)) #f gosh> (proper-subset? '(1 2 3) '(1 2 3 4)) #t gosh> (proper-subset? '(1 2 3) '(1 2)) #f gosh> (proper-subset? '("foo" "bar" "baz") '("foo" "bar" "baz")) #f gosh> (proper-subset? '("foo" "bar" "baz") '("foo" "bar" "baz" "hoge")) #t gosh> (proper-subset? '("foo" "bar" "baz") '("foo" "bar")) #f !2007-09-08 Sat ; Ruby >> require "set" => true >> Set[1,2,3].subset?(Set[1,2,3]) => true >> Set[1,2,3].subset?(Set[1,2,3,4]) => true >> Set[1,2,3].subset?(Set[1,2]) => false ; Gauche gosh> (use srfi-1) # gosh> (lset<= equal? '(1 2 3) '(1 2 3)) #t gosh> (lset<= equal? '(1 2 3) '(1 2 3 4)) #t gosh> (lset<= equal? '(1 2 3) '(1 2)) #f gosh> (lset<= equal? '("foo" "bar" "baz") '("foo" "bar" "baz")) #t gosh> (lset<= equal? '("foo" "bar" "baz") '("foo" "bar" "baz" "hoge")) #t gosh> (lset<= equal? '("foo" "bar" "baz") '("foo" "bar")) #f !2007-09-07 Fri ; Ruby >> require "set" => true >> Set[1,2,3].proper_superset?(Set[1,2,3]) => false >> Set[1,2,3].superset?(Set[1,2]) => true >> Set[1,2,3].superset?(Set[1,2,3,4]) => false ; Gauche gosh> (define (proper-superset? s s2) (and (lset<= equal? s2 s) (not (lset= equal? s2 s)))) proper-superset? gosh> (proper-superset? '(1 2 3) '(1 2 3)) #f gosh> (proper-superset? '(1 2 3) '(1 2)) #t gosh> (proper-superset? '(1 2 3) '(1 2 3 4)) #f gosh> (proper-superset? '("foo" "bar" "baz") '("foo" "bar" "baz")) #f gosh> (proper-superset? '("foo" "bar" "baz") '("foo" "bar")) #t gosh> (proper-superset? '("foo" "bar" "baz") '("foo" "bar" "baz" "hoge")) #f !2007-09-06 Thu ; Ruby >> require "set" => true >> Set[1,2,3].superset?(Set[1,2,3]) => true >> Set[1,2,3].superset?(Set[1,2]) => true >> Set[1,2,3].superset?(Set[1,2,3,4]) => false ; Gauche gosh> (use srfi-1) # gosh> (lset<= eq? '(1 2 3) '(1 2 3)) #t gosh> (lset<= eq? '(1 2) '(1 2 3)) #t gosh> (lset<= eq? '(1 2 3 4) '(1 2 3)) #f gosh> (lset<= eq? '("foo" "bar" "baz") '("foo" "bar" "baz")) #f gosh> (lset<= equal? '("foo" "bar" "baz") '("foo" "bar" "baz")) #t gosh> (lset<= equal? '("foo" "bar") '("foo" "bar" "baz")) #t gosh> (lset<= equal? '("foo" "bar" "baz" "hoge") '("foo" "bar" "baz")) #f !2007-09-05 Wed dup, size, length, empty?, clear, replace, flatten とばし ; Ruby >> require "set" => true >> Set[1,2,3].include?(1) => true >> Set[1,2,3].include?(10) => false >> Set["foo","bar","baz"].include?("foo") => true >> Set["foo","bar","baz"].include?("hoge") => false >> Set["foo","bar","baz","foo"].include?("foo") => true ; Gauche gosh> (memq 1 '(1 2 3)) (1 2 3) gosh> (memq 10 '(1 2 3)) #f gosh> (list? (memq 1 '(1 2 3))) #t gosh> (list? (memq 10 '(1 2 3))) #f gosh> (memq "foo" '("foo" "bar" "baz")) #f gosh> (eq? "foo" "foo") #f gosh> (eqv? "foo" "foo") #f gosh> (equal? "foo" "foo") #t gosh> (member "foo" '("foo" "bar" "baz")) ("foo" "bar" "baz") gosh> (list? (member "foo" '("foo" "bar" "baz"))) #t gosh> (list? (member "hoge" '("foo" "bar" "baz"))) #f !2007-09-04 Tue ; Ruby >> require "set" => true >> Set.new ["foo", "bar", "baz", "foo"] => # >> Set["foo", "bar", "baz", "foo"] => # ; Gauche gosh> '("foo" "bar" "baz" "foo") ("foo" "bar" "baz" "foo") 単なるリストなので… !2007-09-03 Mon ; Ruby >> Dir.mkdir("bar") => 0 ; Gauche gosh> (sys-mkdir "bar" #o777) #t Dir.new に相当するものはないよね? !2007-09-02 Sun ; Ruby >> Dir.pwd => "/home/nnakamur" ; Gauche gosh> (sys-getcwd) "/home/nnakamur" gosh> (use file.util) # gosh> (current-directory) "/home/nnakamur" !2007-09-01 Sat ; Ruby >> Dir.foreach('..') {|x| puts x} . .. lost+found nnakamur local => nil ; Gauche gosh> (for-each (lambda (x) (print x)) (sys-readdir "..")) . .. lost+found nnakamur local # gosh> (for-each (cut print <>) (sys-readdir "..")) . .. lost+found nnakamur local # cut って、さっぱり分かっていないんだけど… !2007-08-31 Fri ; Ruby >> Dir.entries("..") => [".", "..", "lost+found", "nnakamur", "local"] ; Gauche gosh> (sys-readdir "..") ("." ".." "lost+found" "nnakamur" "local") gosh> (use file.util) # gosh> (directory-list "..") ("." ".." "local" "lost+found" "nnakamur") !2007-08-30 Thu Dir.chroot 不明 ; Ruby >> Dir.mkdir("bar") => 0 >> Dir.delete("bar") => 0 >> Dir.delete("bar") Errno::ENOENT: No such file or directory - bar ; Gauche gosh> (sys-mkdir "bar" #o777) #t gosh> (sys-rmdir "bar") #t gosh> (sys-rmdir "bar") *** SYSTEM-ERROR: rmdir failed: No such file or directory gosh> (sys-mkdir "bar" #o777) #t gosh> (sys-remove "bar") #t sys-remove は、 システムによってはfilenameが空のディレクトリであっても動作しますが、 ということらしい sys-remove と sys-unlink の違いは? !2007-08-29 Wed ; Ruby >> Dir.pwd => "/home/nnakamur" >> Dir.chdir('..') => 0 >> Dir.pwd => "/home" >> Dir.chdir => 0 >> Dir.pwd => "/home/nnakamur" ; Gauche gosh> (sys-getcwd) "/home/nnakamur" gosh> (sys-chdir "..") #t gosh> (sys-getcwd) "/home" gosh> (sys-chdir "..") #t gosh> (sys-chdir "..") #t gosh> (sys-chdir "..") #t gosh> (sys-getcwd) "/" gosh> (use file.util) # gosh> (sys-chdir (home-directory)) #t gosh> (sys-getcwd) "/home/nnakamur" !2007-08-28 Tue ; Ruby >> Dir['foo*'] => ["foo", "foo2.rb", "foo.txt", "foo.tcl", "foo.py", "foo2.py", "foo.csv", "foo.hs"] >> Dir.glob('foo*') => ["foo", "foo2.rb", "foo.txt", "foo.tcl", "foo.py", "foo2.py", "foo.csv", "foo.hs"] ; Gauche gosh> (sys-glob "foo*") ("foo" "foo.csv" "foo.hs" "foo.py" "foo.tcl" "foo.txt" "foo2.py" "foo2.rb") 「**/」はあるのだろうか? !2007-08-27 Mon ; Ruby >> open("foo", "w") {} => nil >> File.zero?("foo") => true >> File.zero?(".emacs") => false ; Gauche gosh> (use file.util) # gosh> (touch-file "foo") gosh> (= (slot-ref (sys-stat "foo") 'size) 0) #t gosh> (= (slot-ref (sys-stat ".emacs") 'size) 0) #f * インスタンスメソッドの方はやらないことにする * flock 不明。gauche.fcntl のところに sys-flock というのあり * 定数も相当するものがなさそう? !2007-08-26 Sun ; Ruby >> File.writable?(".emacs") => true >> File.writable?("/") => false ; Gauche gosh> (use file.util) # gosh> (file-is-writable? ".emacs") #t gosh> (file-is-writable? "/") #f !2007-08-25 Sat ; Ruby >> open("foo", "w") {} => nil >> File.symlink("foo", "bar") => 0 >> File.symlink?("foo") => false >> File.symlink?("bar") => true ; Gauche gosh> (use file.util) # gosh> (touch-file "foo") gosh> (sys-symlink "foo" "bar") #t gosh> (file-is-symlink? "foo") #f gosh> (file-is-symlink? "bar") #t !2007-08-24 Fri File.socket? とばし ; Ruby >> File.sticky?(".emacs") => false >> File.sticky?("/tmp") => true ; Gauche gosh> (slot-ref (sys-stat ".emacs") 'mode) 33188 gosh> (logand (slot-ref (sys-stat ".emacs") 'mode) #o1000) 0 gosh> (logand (slot-ref (sys-stat "/tmp") 'mode) #o1000) 512 gosh> (slot-ref (sys-stat "/tmp") 'mode) 17407 gosh> (string->number "041777" 8) 17407 !2007-08-23 Thu File.setgid?, File.setuid? とばし ; Ruby >> File.size(".emacs") => 8151 ; Gauche gosh> (slot-ref (sys-stat ".emacs") 'size) 8151 Ruby の FileTest.size? の filename が存在しない時や filename のサイズが0の時には nil を返します という、「filename のサイズが0」のときにも nil を返すっていうのが面白いな。 そんなんで良いのか? !2007-08-22 Wed File.pipe? とばし ; Ruby >> File.readable?(".emacs") => true >> File.readable?("/var/spool/lpd") => false ; Gauche gosh> (use file.util) # gosh> (file-is-readable? ".emacs") #t gosh> (file-is-readable? "/var/spool/lpd") #f !2007-08-21 Tue ruby-1.8.6 使用 ; Ruby まんま >> open("a", "w") {} => nil >> File.identical?("a", "a") => true >> File.identical?("a", "./a") => true >> File.identical?("a", "../nnakamur/a") => true >> File.link("a", "b") => 0 >> File.identical?("a", "b") => true >> File.symlink("a", "c") => 0 >> File.identical?("a", "c") => true >> open("d", "w") {} => nil >> File.identical?("a", "d") => false ; Gauche gosh> (use file.util) # gosh> (touch-file "a") gosh> (file-eq? "a" "a") #t gosh> (file-eqv? "a" "a") #t gosh> (file-equal? "a" "a") #t gosh> (file-eq? "a" "./a") #t gosh> (file-eq? "a" "../nnakamur/a") #t gosh> (sys-link "a" "b") #t gosh> (file-eq? "a" "b") #t gosh> (file-eqv? "a" "b") #t gosh> (file-equal? "a" "b") #t gosh> (sys-symlink "a" "c") #t gosh> (file-eq? "a" "c") #f gosh> (file-eqv? "a" "c") #t gosh> (file-equal? "a" "c") #t gosh> (touch-file "d") gosh> (file-eq? "a" "d") #f gosh> (file-eqv? "a" "d") #f gosh> (file-equal? "a" "d") #t !2007-08-20 Mon ; Ruby >> File.owned?(".emacs") => true >> File.owned?("/") => false ; Gauche gosh> (sys-getuid) 1000 gosh> (slot-ref (sys-stat ".emacs") 'uid) 1000 gosh> (= (slot-ref (sys-stat ".emacs") 'uid) (sys-getuid)) #t gosh> (= (slot-ref (sys-stat "/") 'uid) (sys-getuid)) #f sys-getuid でなく、sys-geteuid かもしれない !2007-08-19 Sun ; Ruby >> File.grpowned?(".emacs") => true >> File.grpowned?("/") => false ; Gauche gosh> (sys-getgid) 100 gosh> (sys-getegid) 100 gosh> (= (slot-ref (sys-stat ".emacs") 'gid) (sys-getgid)) #t gosh> (= (slot-ref (sys-stat "/") 'gid) (sys-getgid)) #f sys-getgid でなく、sys-getegid かもしれない !2007-08-18 Sat $ ln -s hoge baz ; Ruby >> File.file?(".emacs") => true >> File.file?("tmp") => false >> File.file?("hoge") => false >> File.file?("baz") => false ; Gauche gosh> (file-is-regular? ".emacs") #t gosh> (file-is-regular? "tmp") #f gosh> (file-is-regular? "hoge") #f gosh> (file-is-regular? "baz") #f !2007-08-17 Fri ; Ruby >> File.exist?(".emacs") => true >> File.exist?("hoge") => false ; Gauche gosh> (file-exists? ".emacs") #t gosh> (file-exists? "hoge") #f !2007-08-16 Thu ; Ruby >> File.executable?("/usr/bin/ruby") => true >> File.executable?("tmp") => true >> File.executable?(".emacs") => false ; Gauche gosh> (use file.util) # gosh> (file-is-executable? "/usr/bin/ruby") #t gosh> (file-is-executable? "tmp") #t gosh> (file-is-executable? ".emacs") #f !2007-08-15 Wed ; Ruby >> File.directory?("tmp") => true >> File.directory?(".emacs") => false ; Gauche gosh> (file-is-directory? "tmp") #t gosh> (file-is-directory? ".emacs") #f !2007-08-14 Tue ; Ruby >> File.chardev?("/dev/mouse") => true >> File.chardev?("/dev/hda1") => false ; Gauche gosh> (eq? (slot-ref (sys-stat "/dev/mouse") 'type) 'character) #t gosh> (eq? (slot-ref (sys-stat "/dev/hda1") 'type) 'character) #f !2007-08-13 Mon ; Ruby >> File.blockdev?("/dev/hda1") => true >> File.blockdev?("/dev/mouse") => false ; Gauche gosh> (slot-ref (sys-stat "/dev/hda1") 'type) block gosh> (slot-ref (sys-stat "/dev/mouse") 'type) character gosh> (eq? (slot-ref (sys-stat "/dev/hda1") 'type) 'block) #t gosh> (eq? (slot-ref (sys-stat "/dev/mouse") 'type) 'block) #f !2007-08-12 Sun ; Ruby >> File.stat("foo") => # >> File.utime(Time.now, Time.now, "foo") => 1 >> File.stat("foo") => # ; Gauche gosh> (describe (sys-stat "foo")) #< 0x817cf00> is an instance of class slots: type : regular perm : 420 mode : 33188 ino : 36618 dev : 2072 rdev : 0 nlink : 1 uid : 1000 gid : 100 size : 0 atime : 1187838358 mtime : 1187838358 ctime : 1187838358 gosh> (sys-utime "foo") # gosh> (describe (sys-stat "foo")) #< 0x817cd20> is an instance of class slots: type : regular perm : 420 mode : 33188 ino : 36618 dev : 2072 rdev : 0 nlink : 1 uid : 1000 gid : 100 size : 0 atime : 1187838453 mtime : 1187838453 ctime : 1187838453 Gauche の場合は、 atimeとmtimeが省略された場合は現在の時刻が使われます という仕様のようだ。Ruby でもこうでも良いかも !2007-08-11 Sat ; Ruby >> File.umask() => 18 >> File.umask(0x022) => 18 >> File.umask() => 34 >> File.umask(18) => 34 >> File.umask() => 18 ; Gauche gosh> (sys-umask) 18 gosh> (sys-umask 34) 18 gosh> (sys-umask) 34 gosh> (sys-umask 18) 34 gosh> (sys-umask) 18 !2007-08-10 Fri ; Ruby >> File.truncate("foo", 3) => 0 ; Gauche gosh> (sys-truncate "foo" 3) #t !2007-08-09 Thu ; Ruby >> File.symlink("foo", "foo.new") => 0 >> File.symlink("foo", "foo.new") Errno::EEXIST: File exists - foo or foo.new ; Gauche gosh> (sys-symlink "foo" "foo.new") #t gosh> (sys-symlink "foo" "foo.new") *** SYSTEM-ERROR: link failed: File exists !2007-08-08 Wed ; Ruby >> open("foo", "w") {} => nil >> File.symlink("foo", "bar") => 0 >> File.stat("foo") => # >> File.stat("bar") => # >> File.lstat("foo") => # >> File.lstat("bar") => # ; Gauche gosh> (use file.util) # gosh> (touch-file "foo") gosh> (sys-symlink "foo" "bar") #t gosh> (describe (sys-stat "foo")) #< 0x817cd80> is an instance of class slots: type : regular perm : 420 mode : 33188 ino : 36618 dev : 2072 rdev : 0 nlink : 1 uid : 1000 gid : 100 size : 0 atime : 1187838180 mtime : 1187838180 ctime : 1187838180 gosh> (describe (sys-stat "bar")) #< 0x817cd20> is an instance of class slots: type : regular perm : 420 mode : 33188 ino : 36618 dev : 2072 rdev : 0 nlink : 1 uid : 1000 gid : 100 size : 0 atime : 1187838180 mtime : 1187838180 ctime : 1187838180 gosh> (describe (sys-lstat "foo")) #< 0x817ccc0> is an instance of class slots: type : regular perm : 420 mode : 33188 ino : 36618 dev : 2072 rdev : 0 nlink : 1 uid : 1000 gid : 100 size : 0 atime : 1187838180 mtime : 1187838180 ctime : 1187838180 gosh> (describe (sys-lstat "bar")) #< 0x817cc60> is an instance of class slots: type : symlink perm : 511 mode : 41471 ino : 37593 dev : 2072 rdev : 0 nlink : 1 uid : 1000 gid : 100 size : 3 atime : 1187838217 mtime : 1187838186 ctime : 1187838186 !2007-08-07 Tue ; Ruby >> File.stat(".emacs") => # ; Gauche gosh> (sys-stat ".emacs") #< 0x817cf00> gosh> (describe (sys-stat ".emacs")) #< 0x817cea0> is an instance of class slots: type : regular perm : 420 mode : 33188 ino : 34236 dev : 2072 rdev : 0 nlink : 1 uid : 1000 gid : 100 size : 8151 atime : 1187771636 mtime : 1187659346 ctime : 1187659346 !2007-08-06 Mon ; Ruby >> File.split("dir/file.ext") => ["dir", "file.ext"] >> File.split("file.ext") => [".", "file.ext"] >> File.split("foo/bar/") => ["foo", "bar"] >> File.split("foo//bar") => ["foo", "bar"] ; Gauche gosh> (use file.util) # gosh> (decompose-path "dir/file.ext") "dir" "file" "ext" gosh> (decompose-path "file.ext") "." "file" "ext" gosh> (decompose-path "foo/bar/") "foo/bar" #f #f gosh> (decompose-path "foo//bar") "foo" "bar" #f 細工しないと同じにはならないな gosh> (use file.util) # gosh> (use srfi-13) # gosh> (define (file-split path) (receive (b d e) (decompose-path path) (cons b (string-concatenate (list (if d d "") (if e "." "") (if e e "")))))) file-split gosh> (file-split "dir/file.ext") ("dir" . "file.ext") gosh> (file-split "file.ext") ("." . "file.ext") gosh> (file-split "foo/bar/") ("foo/bar" . "") gosh> (file-split "foo//bar") ("foo" . "bar") うむー、ダメだ… 素直に sys-dirname, sys-basename を使えば大丈夫??? !2007-08-05 Sun ; Ruby >> File.rename("foo", "foo.new") => 0 >> File.rename("foo", "foo.new") Errno::ENOENT: No such file or directory - foo or foo.new ; Gauche gosh> (sys-rename "foo" "foo.new") #t gosh> (sys-rename "foo" "foo.new") *** SYSTEM-ERROR: renaming foo to foo.new failed: No such file or directory Ruby のマニュアルには同じデバイス上にない場合どうなるか書いていないな !2007-08-04 Sat ; Ruby >> File.readlink("bar") => "foo" >> File.readlink("foo") Errno::EINVAL: Invalid argument - foo ; Gauche gosh> (sys-readlink "bar") "foo" gosh> (sys-readlink "foo") *** SYSTEM-ERROR: readlink failed: Invalid argument !2007-08-03 Fri ; Ruby >> open(".emacs") => # >> File.open(".emacs") => # ; Gauche gosh> (define f (open-input-file ".emacs")) f gosh> f # !2007-08-02 Thu ; Ruby >> File.link("foo", "bar") => 0 ; Gauche gosh> (sys-link "foo" "bar") #t !2007-08-01 Wed ; Ruby >> File.join('/home', 'foo') => "/home/foo" >> File.join("/home", "foo", "bar") => "/home/foo/bar" >> File.join('/home/', 'foo') => "/home/foo" >> File.join('/home/', '/foo') => "/home//foo" >> File.join('/home/', '../foo') => "/home/../foo" >> File.join('/home', '../foo') => "/home/../foo" >> File.join('.', 'foo') => "./foo" ; Gauche gosh> (use file.util) # gosh> (build-path "/home" "foo") "/home/foo" gosh> (build-path "/home" "foo" "bar") "/home/foo/bar" gosh> (build-path "/home/" "foo") "/home/foo" gosh> (build-path "/home/" "/foo") *** ERROR: can't append absolute path after other path "/foo" Stack Trace: _______________________________________ gosh> (build-path "/home/" "../foo") "/home/../foo" gosh> (build-path "/home" "../foo") "/home/../foo" gosh> (build-path "." "foo") "./foo" File::SEPARATOR に相当するものはあるのか? !2007-07-31 Tue File.fnmatch 相当あるのか? そもそも File.fnmatch の意義ってなんだっけ? 簡易正規表現でマッチがチェックできるってこと??? ; Ruby >> File.ftype(".emacs") => "file" >> File.ftype("bar") => "link" >> File.ftype("tmp") => "directory" >> File.ftype("hogehoge") Errno::ENOENT: No such file or directory - hogehoge ; Gauche gosh> (sys-stat->file-type (sys-stat ".emacs")) regular gosh> (sys-stat->file-type (sys-stat "bar")) regular gosh> (sys-stat->file-type (sys-stat "tmp")) directory "bar" はなぜか symlink が戻ってこないな〜 「Deprecated.」ってどういう意味だっけ? 「slot-refを使って下さ」ってことらしいが? gosh> (slot-ref (sys-stat ".emacs") 'type) regular gosh> (slot-ref (sys-stat "bar") 'type) regular gosh> (slot-ref (sys-stat "tmp") 'type) directory !2007-07-30 Mon ; Ruby >> File.extname("foo/foo.txt") => ".txt" >> File.extname("foo/foo.tar.gz") => ".gz" >> File.extname("foo/bar") => "" >> File.extname("foo/.bar") => "" >> File.extname("foo.txt/bar") => "" >> File.extname(".foo") => "" >> File.extname("a.foo") => ".foo" ; Gauche gosh> (use file.util) # gosh> (path-extension "foo/foo.txt") "txt" gosh> (path-extension "foo/foo.tar.gz") "gz" gosh> (path-extension "foo/bar") #f gosh> (path-extension "foo/.bar") #f gosh> (path-extension "foo.txt/bar") #f gosh> (path-extension ".foo") #f gosh> (path-extension "a.foo") "foo" 基本的に同じように思えるが、「.」のありなしが違うや !2007-07-29 Sun 二つ引数を取って path を合成するような関数は見あたらないので? そっちはとりあえず、あきらめる それっぽいのはいくつかあるのだが、なんか違うものが多い ; Ruby >> File.expand_path('..') => "/home" >> File.expand_path('~') => "/home/nnakamur" >> File.expand_path('~/bar') => "/home/nnakamur/bar" >> File.expand_path('~root') => "/root" >> File.expand_path('/home//bar') => "/home/bar" ; Gauche gosh> (sys-normalize-pathname ".." :absolute #t) "/home/nnakamur/.." gosh> (sys-normalize-pathname ".." :expand #t) ".." gosh> (sys-normalize-pathname ".." :canonicalize #t) ".." gosh> (sys-realpath "..") "/home" gosh> (use file.util) # gosh> (expand-path "..") ".." gosh> (resolve-path "..") ".." gosh> (simplify-path "..") ".." gosh> (resolve-path (sys-normalize-pathname ".." :absolute #t)) "/home/" つまり、".." を展開するのは、sys-realpath が近いか? gosh> (sys-normalize-pathname "~" :absolute #t) "/home/nnakamur/~" gosh> (sys-normalize-pathname "~" :expand #t) "/home/nnakamur/" gosh> (sys-normalize-pathname "~" :canonicalize #t) "~" gosh> (sys-realpath "~") *** SYSTEM-ERROR: realpath failed: No such file or directory Stack Trace: _______________________________________ 0 (sys-realpath "~") At line 4 of "(stdin)" 1 (sys-realpath "~") At line 4 of "(stdin)" gosh> (use file.util) # gosh> (expand-path "~") "/home/nnakamur/" gosh> (resolve-path "~") "/home/nnakamur" gosh> (simplify-path "~") "~" つまり、"~" を展開するのは、(sys-normalize-pathname "~" :expand #t) expand-path, resolve-path あたりか? gosh> (sys-normalize-pathname "~/bar" :absolute #t) "/home/nnakamur/~/bar" gosh> (sys-normalize-pathname "~/bar" :expand #t) "/home/nnakamur/bar" gosh> (sys-normalize-pathname "~/bar" :canonicalize #t) "~/bar" gosh> (sys-realpath "~/bar") *** SYSTEM-ERROR: realpath failed: No such file or directory Stack Trace: _______________________________________ 0 (sys-realpath "~/bar") At line 4 of "(stdin)" 1 (sys-realpath "~/bar") At line 4 of "(stdin)" gosh> (use file.util) # gosh> (expand-path "~/bar") "/home/nnakamur/bar" gosh> (resolve-path "~/bar") *** ERROR: path doesn't exist "~/bar" Stack Trace: _______________________________________ gosh> (simplify-path "~/bar") "~/bar" resolve-path はファイルが存在しないとダメらしい gosh> (sys-normalize-pathname "~root" :absolute #t) "/home/nnakamur/~root" gosh> (sys-normalize-pathname "~root" :expand #t) "/root/" gosh> (sys-normalize-pathname "~root" :canonicalize #t) "~root" gosh> (sys-realpath "~root") *** SYSTEM-ERROR: realpath failed: No such file or directory Stack Trace: _______________________________________ 0 (sys-realpath "~root") At line 4 of "(stdin)" 1 (sys-realpath "~root") At line 4 of "(stdin)" gosh> (use file.util) # gosh> (expand-path "~root") "/root/" gosh> (resolve-path "~root") "/root/" gosh> (simplify-path "~root") "~root" gosh> (sys-normalize-pathname "/home//bar" :expand #t) "/home//bar" gosh> (use file.util) # gosh> (expand-path "/home//bar") "/home//bar" !2007-07-28 Sat ; Ruby >> File.delete('foo') => 1 >> File.delete('foo') Errno::ENOENT: No such file or directory - foo ; Gauche gosh> (sys-remove "foo") #t gosh> (sys-remove "foo") *** SYSTEM-ERROR: removing foo failed: No such file or directory * Ruby の File.delete ではディレクトリは消せないようだが、Gauche の sys-remove はディレクトリも消せるようだ。 * Ruby の File.delete, File.unlink に相当するのは、sys-unlink の方だったみたい… !2007-07-27 Fri 実行はスキップ ; Ruby File.chown(owner, group[, filename[, ...]]) ; Gauche sys-chown path owner-id group-id !2007-07-26 Thu ; Ruby >> File.chmod(0666, 'foo') => 1 >> File.chmod(0666, 'foo') => 1 ; Gauche gosh> (sys-chmod "foo" #o666) #t gosh> (sys-chmod "foo" #o666) #t File.lchmod() に相当するものがあるかは不明 !2007-07-25 Wed ; Ruby >> File.dirname("dir/file.ext") => "dir" >> File.dirname("file.ext") => "." >> File.dirname("foo/bar/") => "foo" >> File.dirname("foo//bar") => "foo" >> File.dirname("foo/bar/bar.z") => "foo/bar" >> File.dirname("coo.scm") => "." >> File.dirname("x/y/") => "x" >> File.dirname("") => "." >> File.dirname("/") => "/" ; Gauche gosh> (sys-dirname "dir/file.ext") "dir" gosh> (sys-dirname "file.ext") "." gosh> (sys-dirname "foo/bar/") "foo" gosh> (sys-dirname "foo//bar") "foo" gosh> (sys-dirname "foo/bar/bar.z") "foo/bar" gosh> (sys-dirname "coo.scm") "." gosh> (sys-dirname "x/y/") "x" gosh> (sys-dirname "") "." gosh> (sys-dirname "/") "/" !2007-07-24 Tue ; Ruby >> File.basename('/home/foo') => "foo" >> File.basename('/home/foo/') => "foo" >> File.basename("ruby/ruby.c") => "ruby.c" >> File.basename("foo/bar/bar.z") => "bar.z" >> File.basename("coo.scm") => "coo.scm" >> File.basename("x/y/") => "y" >> File.basename("") => "" >> File.basename("/") => "/" ; Gauche gosh> (sys-basename "/home/foo") "foo" gosh> (sys-basename "/home/foo/") "foo" gosh> (sys-basename "ruby/ruby.c") "ruby.c" gosh> (sys-basename "foo/bar/bar.z") "bar.z" gosh> (sys-basename "coo.scm") "coo.scm" gosh> (sys-basename "x/y/") "y" gosh> (sys-basename "") "" gosh> (sys-basename "/") "" !2007-07-23 Mon ; Ruby >> File.atime(".emacs") => Fri Aug 03 11:47:12 JST 2007 >> File.ctime(".emacs") => Mon Jun 25 16:12:27 JST 2007 >> File.mtime(".emacs") => Mon Jun 25 16:12:27 JST 2007 >> File.atime(".emacs").class => Time ; Gauche gosh> (use file.util) # gosh> (file-atime ".emacs") 1186109232 gosh> (sys-localtime (file-atime ".emacs")) # gosh> (sys-localtime (file-ctime ".emacs")) # gosh> (sys-localtime (file-mtime ".emacs")) # !2007-07-22 Sun 2007-05-31 Thu で書いた ary-values を fold を使って書いてみる gosh> (define (ary-values_at ary index) (let ((length (length ary))) (fold-right (lambda (x r) (cons (if (< x length) (list-ref ary x) '()) r)) '() index))) ary-values_at gosh> (ary-values_at '("a" "b" "c" "d" "e") '(0 2 4)) ("a" "c" "e") gosh> (ary-values_at '("a" "b" "c" "d" "e") '(3 4 5 6 35)) ("d" "e" () () ()) !2007-07-21 Sat 2007-05-29 Tue で書いた ary-uniq を fold を使って書いてみる gosh> (define (ary-uniq ary) (fold-right (lambda (x r) (if (memq x r) r (append (list x) r))) '() ary)) ary-uniq gosh> (ary-uniq '(1 1 1)) (1) gosh> (ary-uniq '(1 4 1)) (4 1) gosh> (ary-uniq '(1 3 2 2 3)) (1 2 3) gosh> (define (ary-uniq ary) (fold-right (lambda (x r) (if (memq x r) r (cons x r))) '() ary)) ary-uniq gosh> (ary-uniq '(1 1 1)) (1) gosh> (ary-uniq '(1 4 1)) (4 1) gosh> (ary-uniq '(1 3 2 2 3)) (1 2 3) 順番が変わってしまう gosh> (define (ary-uniq ary) (fold (lambda (x r) (if (memq x r) r (append r (list x)))) '() ary)) ary-uniq gosh> (ary-uniq '(1 1 1)) (1) gosh> (ary-uniq '(1 4 1)) (1 4) gosh> (ary-uniq '(1 3 2 2 3)) (1 3 2) なんか すっきりしないような? !2007-07-20 Fri 2007-05-28 Mon で書いた ary-transpose を fold を使って書いてみる gosh> (define (ary-transpose ary) (define (ary-transpose-car ary) (fold-right (lambda (x r) (cons (car x) r)) '() ary)) (define (ary-transpose-cdr ary) (fold-right (lambda (x r) (cons (cadr x) r)) '() ary)) (list (ary-transpose-car ary) (ary-transpose-cdr ary))) ary-transpose gosh> (ary-transpose '((1 2) (3 4) (5 6))) ((1 3 5) (2 4 6)) !2007-07-19 Thu 2007-05-16 Wed で書いた ary-insert を 2007-07-18 Wed で書いた fold-right-with-index を使って書いてみる gosh> (define (ary-insert ary index val) (fold-right-with-index (lambda (i x r) (if (= i index) (cons val (cons x r)) (cons x r))) '() ary)) ary-insert gosh> (ary-insert '(1 2 3) 0 10) (10 1 2 3) gosh> (ary-insert '(1 2 3) 1 10) (1 10 2 3) gosh> (ary-insert '(1 2 3) 0 '(1)) ((1) 1 2 3) !2007-07-18 Wed ちょっと使いたいので fold-right-with-index を書いてみる gosh> (define (fold-right-with-index proc init ary) (let ((len-1 (- (length ary) 1))) (cdr (fold-right (lambda (x r) (let ((i (car r)) (ni (- (car r) 1)) (nr (cdr r))) (cons ni (proc i x nr)))) (cons len-1 init) ary)))) fold-right-with-index gosh> (fold-right-with-index (lambda (i x r) (print i " " x " " r) (+ r 2)) 0 '(1 2 3)) 2 3 0 1 2 2 0 1 4 6 gosh> (fold-right-with-index (lambda (i x r) (cons x r)) '() '(a b c d e)) (a b c d e) !2007-07-17 Tue 2007-05-14 Mon で書いた ary-index を fold-with-index を使って書いてみる gosh> (use gauche.sequence) # gosh> (define (ary-index ary val) (fold-with-index (lambda (i x r) (if r r (if (eq? x val) i r))) #f ary)) ary-index gosh> (ary-index '(1 2 3) 1) 0 gosh> (ary-index '(1 2 3) 2) 1 gosh> (ary-index '(1 2 3) 3) 2 gosh> (ary-index '(1 2 3) 4) #f cond で gosh> (use gauche.sequence) # gosh> (define (ary-index ary val) (fold-with-index (lambda (i x r) (cond (r r) ((eq? x val) i) (#t r))) #f ary)) ary-index gosh> (ary-index '(1 2 3) 1) 0 gosh> (ary-index '(1 2 3) 2) 1 gosh> (ary-index '(1 2 3) 4) #f !2007-07-16 Mon 2007-05-14 Mon で書いた ary-index を fold を使って書いてみる gosh> (define (ary-index ary val) (let ((ret (fold (lambda (x r) (let ((nr (car r)) (i (cdr r))) (if nr r (if (eq? x val) (cons #t i) (cons #f (+ i 1)))))) '(#f . 0) ary))) (if (car ret) (cdr ret) #f))) ary-index gosh> (ary-index '(1 2 3) 1) 0 gosh> (ary-index '(1 2 3) 2) 1 gosh> (ary-index '(1 2 3) 3) 2 gosh> (ary-index '(1 2 3) 4) #f 分かりにくくなっているような気がする… cond を使えば少しはまとも??? !2007-07-15 Sun 2007-05-13 Sun で書いた ary-flatten を fold を使って書いてみる gosh> (define (ary-flatten ary) (fold-right (lambda (x r) (if (list? x) (cons (ary-flatten x) r) (cons x r))) '() ary)) ary-flatten gosh> (ary-flatten '(1 (2 3 (4) 5))) (1 (2 3 (4) 5)) gosh> (define (ary-flatten ary) (fold-right (lambda (x r) (if (list? x) (append (ary-flatten x) r) (append (list x) r))) '() ary)) ary-flatten gosh> (ary-flatten '(1 (2 3 (4) 5))) (1 2 3 4 5) !2007-07-14 Sat take、というより、take* を fold で書いてみる gosh> (define (ary-take ary n) (let ((len (length ary))) (cdr (fold-right (lambda (x r) (let ((i (- len (car r) 1)) (rr (cdr r)) (ni (+ (car r) 1))) (if (>= i n) (cons ni rr) (cons ni (cons x rr))))) '(0 . ()) ary)))) ary-take gosh> (ary-take '(0 1 2) 0) () gosh> (ary-take '(0 1 2) 1) (0) gosh> (ary-take '(0 1 2) 2) (0 1) gosh> (ary-take '(0 1 2) 3) (0 1 2) gosh> (ary-take '(0 1 2) 4) (0 1 2) !2007-07-13 Fri 2007-05-10 Thu で書いた、破壊的でない fill も fold で書ける gosh> (fold (lambda (x r) (cons 10 r)) '() '(1 2 3)) (10 10 10) !2007-07-12 Thu for-each-with-index も fold で書ける gosh> (fold (lambda (x r) (print r) (+ r 1)) 0 '(1 2 3)) 0 1 2 3 !2007-07-11 Wed for-each も fold で書ける gosh> (fold (lambda (x r) (print x)) '() '(1 2 3)) 1 2 3 # !2007-07-10 Tue 2007-05-04 Fri で書いた ary-delete_at を fold を使って書いてみる gosh> (define (ary-delete_at ary pos) (let ((len (length ary))) (cdr (fold-right (lambda (x r) (let ((i (- len (car r) 1)) (rr (cdr r)) (ni (+ (car r) 1))) (if (= i pos) (cons ni rr) (cons ni (cons x rr))))) '(0 . ()) ary)))) ary-delete_at gosh> (ary-delete_at '(0 1 2 3 4) 2) (0 1 3 4) gosh> (ary-delete_at '(0 1 2 3 4) 4) (0 1 2 3) gosh> (ary-delete_at '(0 1 2 3 4) 5) (0 1 2 3 4) なんかごちゃごちゃしているんだけど… reverse して fold-with-index するのと何が違う? !2007-07-09 Mon 2007-04-28 Sat で書いた ary-assoc を fold を使って書いてみる gosh> (define (ary-assoc ary key) (fold (lambda (x y) (if y y (if (eq? (car x) key) x #f))) #f ary)) ary-assoc gosh> (ary-assoc '((1 15) (2 25) (3 35)) 2) (2 25) gosh> (ary-assoc '((1 . 15) (2 . 25) (3 . 35)) 2) (2 . 25) gosh> (ary-assoc '((1 15) (2 25) (3 35)) 100) #f gosh> (ary-assoc '((1 . 15) (2 . 25) (3 . 35)) 100) #f !2007-07-08 Sun 2007-04-27 Fri で書いた ary-eq を fold を使って書いてみる gosh> (define (ary-eq ary1 ary2) (let ((eq (fold (lambda (x y z) (if z (= x y) z)) 0 ary1 ary2))) (if eq (= (length ary1) (length ary2)) eq))) ary-eq gosh> (ary-eq '(1 2 3) '(1 2 3)) #t gosh> (ary-eq '(1 2 3) '(1 2 4)) #f gosh> (ary-eq '(1 2 3) '(1 2 3 4)) #f !2007-07-07 Sat gosh> (fold (lambda (x y z) (print x)) '() '(a b c) '(1 2 3 4 5)) a b c # gosh> (fold (lambda (x y z) (print y)) '() '(a b c) '(1 2 3 4 5)) 1 2 3 # gosh> (fold (lambda (x y z) (print z)) '() '(a b c) '(1 2 3 4 5)) () # # # 2007-04-26 Thu で書いた ary-cmp を fold を使って書いてみる gosh> (define (ary-cmp ary1 ary2) (fold (lambda (x y z) (cond ((or (= z 1) (= z -1)) z) (else (cond ((> x y) 1) ((< x y) -1) (else 0))))) 0 ary1 ary2)) ary-cmp gosh> (ary-cmp '(1) '()) 0 gosh> (ary-cmp '() '()) 0 gosh> (ary-cmp '() '(1)) 0 gosh> (ary-cmp '(1 2) '(1 2)) 0 gosh> (ary-cmp '(1 2) '(1 2 3)) 0 gosh> (ary-cmp '(1 2 3) '(1 2 4)) -1 gosh> (ary-cmp '(1 2 3) '(1 2)) 0 gosh> (ary-cmp '(1 2 4) '(1 2 3)) 1 リストの長さが違うと間違った答えになってしまう… gosh> (define (ary-cmp ary1 ary2) (let ((cmp (fold (lambda (x y z) (cond ((or (= z 1) (= z -1)) z) (else (cond ((> x y) 1) ((< x y) -1) (else 0))))) 0 ary1 ary2))) (if (= cmp 0) (cond ((> (length ary1) (length ary2)) 1) ((< (length ary1) (length ary2)) -1) (else 0)) cmp))) ary-cmp gosh> (ary-cmp '(1) '()) 1 gosh> (ary-cmp '() '()) 0 gosh> (ary-cmp '() '(1)) -1 gosh> (ary-cmp '(1 2) '(1 2)) 0 gosh> (ary-cmp '(1 2) '(1 2 3)) -1 gosh> (ary-cmp '(1 2 3) '(1 2 4)) -1 gosh> (ary-cmp '(1 2 3) '(1 2)) 1 gosh> (ary-cmp '(1 2 4) '(1 2 3)) 1 2007-01-15 Mon で定義したような cmp をあらかじめ定義しておくべきだったか !2007-07-06 Fri gosh> (fold + 0 '(3 1 4 1 5 9)) 23 gosh> (fold (lambda (x y) (+ x y)) 0 '(3 1 4 1 5 9)) 23 gosh> (fold (lambda (x y) (begin (display x) (+ x y))) 0 '(3 1 4 1 5 9)) 31415923 gosh> (fold (lambda (x y) (begin (print x) (+ x y))) 0 '(3 1 4 1 5 9)) 3 1 4 1 5 9 23 2007-04-22 Sun で書いた ary-diff を fold を使って書いてみる gosh> (use srfi-1) # gosh> (fold (lambda (x y) (delete x y)) '(1 2 1 3 1 4 1 5) '(2 3 4 5)) (1 1 1 1) gosh> (fold (lambda (x y) (delete x y)) '(1 2 1 3 1 4 1 5) '(1 2 3 4 5)) () !2007-07-05 Thu ; Ruby >> h = {1=>"a", 2=>"b", 3=>"c"} => {1=>"a", 2=>"b", 3=>"c"} >> h.values_at(1,3,4) => ["a", "c", nil] ; Gauche gosh> (define (hash-values_at h keys) (if (null? keys) () (cons (assoc (car keys) h) (hash-values_at h (cdr keys))))) hash-values_at gosh> (hash-values_at '((1 . "a") (2 . "b") (3 . "c")) '(1 3 4)) ((1 . "a") (3 . "c") #f) !2007-07-04 Wed ; Ruby >> h = {"foo" => 1, "bar" => 2} => {"foo"=>1, "bar"=>2} >> h.values => [1, 2] >> {"foo" => 1, "bar" => 2, "hoge" => 1}.values => [1, 1, 2] ; Gauche gosh> (define (hash-values h) (if (null? h) () (cons (cdar h) (hash-values (cdr h))))) hash-values gosh> (hash-values '(("foo" . 1) ("bar" . 2))) (1 2) gosh> (hash-values '(("foo" . 1) ("bar" . 2) ("hoge" . 1))) (1 2 1) !2007-07-03 Tue ; Ruby >> h = {"foo" => 1, "bar" => 2} => {"foo"=>1, "bar"=>2} >> h.shift => ["foo", 1] >> h => {"bar"=>2} ; Gauche gosh> (car '(("foo" . 1) ("bar" . 2))) ("foo" . 1) gosh> (cdr '(("foo" . 1) ("bar" . 2))) (("bar" . 2)) gosh> (cdr '(("foo" . 1) ("bar" . 2) ("hoge" . 3))) (("bar" . 2) ("hoge" . 3)) !2007-07-02 Mon ; Ruby >> {"foo" => 1, "bar" => 2}.merge({"hoge" => 3, "hi" => 4}) => {"hi"=>4, "hoge"=>3, "foo"=>1, "bar"=>2} >> {"foo" => 1, "bar" => 2}.merge({"hoge" => 3, "foo" => 4}) => {"hoge"=>3, "foo"=>4, "bar"=>2} ; Gauche gosh> (append '(("foo" . 1) ("bar" . 2)) '(("hoge" . 3) ("hi" . 4))) (("foo" . 1) ("bar" . 2) ("hoge" . 3) ("hi" . 4)) gosh> (append '(("foo" . 1) ("bar" . 2)) '(("hoge" . 3) ("foo" . 4))) (("foo" . 1) ("bar" . 2) ("hoge" . 3) ("foo" . 4)) 重複の解消ができていない gosh> (use srfi-1) # gosh> (define (hash-merge h1 h2) (delete-duplicates (append h2 h1) (lambda (x y) (equal? (car x) (car y))))) hash-merge gosh> (hash-merge '(("foo" . 1) ("bar" . 2)) '(("hoge" . 3) ("foo" . 4))) (("hoge" . 3) ("foo" . 4) ("bar" . 2)) !2007-07-01 Sun ; Ruby >> {"foo" => 1, "bar" => 2}.length => 2 >> {"foo" => 1, "bar" => 2}.size => 2 ; Gauche gosh> (length '(("foo" . 1) ("bar" . 2))) 2 !2007-06-30 Sat ; Ruby >> {"foo" => 1, "bar" => 2}.keys => ["foo", "bar"] ; Gauche gosh> (define (hash-keys h) (if (null? h) () (cons (caar h) (hash-keys (cdr h))))) hash-keys gosh> (hash-keys '(("foo" . 1) ("bar" . 2))) ("foo" "bar") !2007-06-29 Fri ; Ruby >> { "n" => 100, "m" => 100, "y" => 300, "d" => 200, "a" => 0 }.invert => {0=>"a", 100=>"n", 200=>"d", 300=>"y"} ; Gauche gosh> (define (hash-invert h) (if (null? h) () (cons (cons (cdar h) (caar h)) (hash-invert (cdr h))))) hash-invert gosh> (hash-invert '(("foo" . 1) ("bar" . 2))) ((1 . "foo") (2 . "bar")) gosh> (hash-invert '(("n" . 100) ("m" . 100) ("y" . 300) ("d" . 200) ("a" . 0))) ((100 . "n") (100 . "m") (300 . "y") (200 . "d") (0 . "a")) 重複の解消なし !2007-06-28 Thu ; Ruby >> {"foo" => 1, "bar" => 2}.index(1) => "foo" >> {"foo" => 1, "bar" => 2}.index(10) => nil ; Gauche gosh> (use util.list) # gosh> (rassoc 1 '(("foo" . 1) ("bar" . 2))) ("foo" . 1) gosh> (rassoc 10 '(("foo" . 1) ("bar" . 2))) #f gosh> (rassoc-ref '(("foo" . 1) ("bar" . 2)) 1) "foo" gosh> (rassoc-ref '(("foo" . 1) ("bar" . 2)) 10) #f !2007-06-27 Wed ; Ruby >> {"foo" => 1, "bar" => 2}.has_value?(1) => true >> {"foo" => 1, "bar" => 2}.has_value?(10) => false ; Gauche gosh> (use util.list) # gosh> (rassoc 1 '(("foo" . 1) ("bar" . 2))) ("foo" . 1) gosh> (rassoc 10 '(("foo" . 1) ("bar" . 2))) #f gosh> (pair? (rassoc 1 '(("foo" . 1) ("bar" . 2)))) #t gosh> (pair? (rassoc 10 '(("foo" . 1) ("bar" . 2)))) #f !2007-06-26 Tue ; Ruby >> {"foo" => 1, "bar" => 2}.has_key?("foo") => true >> {"foo" => 1, "bar" => 2}.has_key?("hoge") => false ; Gauche gosh> (not (null? (assoc "foo" '(("foo" . 1) ("bar" . 2))))) #t gosh> (pair? (assoc "foo" '(("foo" . 1) ("bar" . 2)))) #t gosh> (pair? (assoc "hoge" '(("foo" . 1) ("bar" . 2)))) #f !2007-06-25 Mon ; Ruby >> {"foo" => 1, "bar" => 2}.fetch("foo") => 1 >> {"foo" => 1, "bar" => 2}.fetch("hoge") IndexError: key not found >> {"foo" => 1, "bar" => 2}.fetch("hoge", "default") => "default" ; Gauche gosh> (assoc "foo" '(("foo" . 1) ("bar" . 2))) ("foo" . 1) gosh> (use util.list) # gosh> (assoc-ref '(("foo" . 1) ("bar" . 2)) "foo") 1 gosh> (assoc-ref '(("foo" . 1) ("bar" . 2)) "baz") #f gosh> (assoc-ref '(("foo" . 1) ("bar" . 2)) "baz" "default") "default" !2007-06-24 Sun ; Ruby >> {}.empty? => true ; Gauche gosh> (define h '(("foo" . 1) ("bar" . 2))) h gosh> (length h) 2 gosh> (= (length h) 0) #f gosh> (= (length '()) 0) #t gosh> (null? h) #f gosh> (null? '()) #t gosh> (use srfi-1) # gosh> (null? (alist-delete "foo" '(("foo" . 1)))) #t !2007-06-23 Sat ; Ruby >> {"foo" => 1, "bar" => 2}.each_value {|v| p v} 1 2 => {"foo"=>1, "bar"=>2} ; Gauche gosh> (define h '(("foo" . 1) ("bar" . 2))) h gosh> (for-each (lambda (x) (print (cdr x))) h) 1 2 # !2007-06-22 Fri ; Ruby >> {"foo" => 1, "bar" => 2}.each_key {|k| p k} "foo" "bar" => {"foo"=>1, "bar"=>2} ; Gauche gosh> (define h '(("foo" . 1) ("bar" . 2))) h gosh> (for-each (lambda (x) (print (car x))) h) foo bar # !2007-06-21 Thu ; Ruby >> {"foo" => 1, "bar" => 2}.each {|k,v| p [k,v]} ["foo", 1] ["bar", 2] => {"foo"=>1, "bar"=>2} ; Gauche gosh> (define h '(("foo" . 1) ("bar" . 2))) h gosh> (for-each (lambda (x) (print x)) h) (foo . 1) (bar . 2) # gosh> (for-each print h) (foo . 1) (bar . 2) # !2007-06-20 Wed ; Ruby >> h = {"foo" => 1, "bar" => 2} => {"foo"=>1, "bar"=>2} >> h.delete_if {|k,v| v % 2 == 0} => {"foo"=>1} >> h => {"foo"=>1} ; Gauche gosh> (define h '(("foo" . 1) ("bar" . 2))) h gosh> (use srfi-1) # gosh> (remove (lambda (x) (= (remainder (cdr x) 2) 0)) h) (("foo" . 1)) !2007-06-19 Tue ; Ruby >> {"foo" => 1, "bar" => 2}.reject {|k,v| v % 2 == 0} => {"foo"=>1} ; Gauche gosh> (define h '(("foo" . 1) ("bar" . 2))) h gosh> (use srfi-1) # gosh> (remove (lambda (x) (not (= (remainder (cdr x) 2) 0))) h) (("bar" . 2)) !2007-06-18 Mon ; Ruby >> h = {"foo" => 1, "bar" => 2} => {"foo"=>1, "bar"=>2} >> h.delete("foo") => 1 >> h.delete("foo") => nil >> h => {"bar"=>2} ; Gauche gosh> (define h '(("foo" . 1) ("bar" . 2))) h gosh> (use srfi-1) # gosh> (alist-delete "foo" h) (("bar" . 2)) gosh> h (("foo" . 1) ("bar" . 2)) gosh> (alist-delete "hoge" h) (("foo" . 1) ("bar" . 2)) !2007-06-17 Sun ; Ruby >> h = Hash.new(0) => {} >> h["foo"] = 1 => 1 >> h["bar"] = 2 => 2 >> h => {"foo"=>1, "bar"=>2} >> h["hoge"] => 0 ; Gauche gosh> (define h '(("foo" . 1) ("bar" . 2))) h gosh> (use util.list) # gosh> (assoc-ref h "foo") 1 gosh> (assoc-ref h "hoge") #f gosh> (assoc-ref h "hoge" 0) 0 !2007-06-16 Sat Hash#clear うーん、そういう概念があるんだろうか? やはり破壊的な行為はどうもやりにくい。 そういう意味ではやっぱり関数型なの??? ということで、とばし。 ; Ruby >> h = {"foo" => 1, "bar" => 2} => {"foo"=>1, "bar"=>2} >> h2 = h.dup => {"foo"=>1, "bar"=>2} >> h2["foo"] = 10 => 10 >> h => {"foo"=>1, "bar"=>2} >> h2 => {"foo"=>10, "bar"=>2} ; Gauche gosh> (define h '(("foo" . 1) ("bar" . 2))) h gosh> (define h2 (list-copy h)) h2 gosh> (use util.list) # gosh> (assoc-set! h "foo" 10) (("foo" . 10) ("bar" . 2)) gosh> h (("foo" . 10) ("bar" . 2)) gosh> h2 (("foo" . 10) ("bar" . 2)) * そもそも assoc-set! は値を破壊的に変更することを意図しているわけでもなさそうなのだが…(一応返された値を使うというふうに理解している) * 浅いコピーだからだめなのか… alist-copy というのがあった gosh> (define h '(("foo" . 1) ("bar" . 2))) h gosh> (use srfi-1) # gosh> (define h2 (alist-copy h)) h2 gosh> h (("foo" . 1) ("bar" . 2)) gosh> h2 (("foo" . 1) ("bar" . 2)) gosh> (use util.list) # gosh> (assoc-set! h "foo" 10) (("foo" . 10) ("bar" . 2)) gosh> h (("foo" . 10) ("bar" . 2)) gosh> h2 (("foo" . 1) ("bar" . 2)) !2007-06-15 Fri ; Ruby >> h = {"foo" => 1, "bar" => 2} => {"foo"=>1, "bar"=>2} >> h["foo"] = 10 => 10 >> h => {"foo"=>10, "bar"=>2} >> h["hoge"] = 3 => 3 >> h => {"hoge"=>3, "foo"=>10, "bar"=>2} ; Gauche gosh> (use util.list) # gosh> (define h '(("foo" . 1) ("bar" . 2))) h gosh> (assoc-set! h "foo" 10) (("foo" . 10) ("bar" . 2)) gosh> h (("foo" . 10) ("bar" . 2)) gosh> (assoc-set! h "hoge" 3) (("hoge" . 3) ("foo" . 10) ("bar" . 2)) gosh> h (("foo" . 10) ("bar" . 2)) !2007-06-14 Thu ; Ruby >> {"foo" => 1, "bar" => 2}["foo"] => 1 >> {"foo" => 1, "bar" => 2}["hoge"] => nil ; Gauche gosh> (assoc "foo" '(("foo" . 1) ("bar" . 2))) ("foo" . 1) gosh> (assoc "hoge" '(("foo" . 1) ("bar" . 2))) #f !2007-06-13 Wed ; Ruby >> {"foo" => 1, "bar" => 2} => {"foo"=>1, "bar"=>2} ; Gauche gosh> '(("foo" . 1) ("bar" . 2)) (("foo" . 1) ("bar" . 2)) !2007-06-12 Tue ; Ruby >> [1,2,3].zip([4,5,6], [7,8,9]) => [[1, 4, 7], [2, 5, 8], [3, 6, 9]] >> [1,2].zip([4,5,6], [7,8,9,10]) => [[1, 4, 7], [2, 5, 8]] >> [1,2,3,3].zip([4,5,6], [7,8,9]) => [[1, 4, 7], [2, 5, 8], [3, 6, 9], [3, nil, nil]] ; Gauche gosh> (use srfi-1) # gosh> (zip '(1 2 3) '(4 5 6) '(7 8 9)) ((1 4 7) (2 5 8) (3 6 9)) gosh> (zip '(1 2) '(4 5 6) '(7 8 9 10)) ((1 4 7) (2 5 8)) gosh> (zip '(1 2 3 3) '(4 5 6) '(7 8 9)) ((1 4 7) (2 5 8) (3 6 9)) !2007-06-11 Mon ; Ruby >> [3, 1, 4, 5, 9, 2, 6].reject {|x| x % 2 != 0 } => [4, 2, 6] >> [3, 1, 4, 5, 9, 2, 6, 6].reject {|x| x % 2 != 0 } => [4, 2, 6, 6] ; Gauche gosh> (use srfi-1) # gosh> (remove odd? '(3 1 4 5 9 2 6)) (4 2 6) gosh> (remove odd? '(3 1 4 5 9 2 6 6)) (4 2 6 6) !2007-06-10 Sun ; Ruby >> [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0].partition { |i| i % 3 == 0 } => [[9, 6, 3, 0], [10, 8, 7, 5, 4, 2, 1]] ; Gauche gosh> (use srfi-1) # gosh> (partition (lambda (x) (= (remainder x 3) 0)) '(10 9 8 7 6 5 4 3 2 1 0)) (9 6 3 0) (10 8 7 5 4 2 1) !2007-06-09 Sat ; Ruby >> [3, 1, 5].min => 1 >> [3, 1, 5].min {|a, b| b <=> a} => 5 ; Gauche gosh> (min 3 1 5) 1 !2007-06-08 Fri ; Ruby >> [3, 1, 5].max => 5 >> [3, 1, 5].max {|a, b| b <=> a} => 1 ; Gauche gosh> (max 3 1 5) 5 * リストを引数にとる max は? * ソートしてから取り出せばできることは分かるのだが… gosh> (fold (lambda (x y) (if (> x y) x y)) -1 '(3 1 5)) 5 要素が全て正と仮定… !2007-06-07 Thu ; Ruby >> [1,2,3,4,5].inject(0) {|result, item| result + item } => 15 ; Gauche gosh> (fold + 0 '(1 2 3 4 5)) 15 gosh> (fold (lambda (x y) (+ x y)) 0 '(1 2 3 4 5)) 15 「(use srfi-1)」しなくても使えるようだが? !2007-06-06 Wed ; Ruby >> ["foo", "bar", "1", "2"].grep(/\d+/) => ["1", "2"] >> ["foo", "bar", "1", "2"].grep(/\d+/) {|x| x.to_i + 1} => [2, 3] ; Gauche gosh> (use srfi-1) # gosh> (filter (lambda (x) (#/\d+/ x)) '("foo" "bar" "1" "2")) ("1" "2") gosh> (map (lambda (x) (+ (x->integer x) 1)) (filter (lambda (x) (#/\d+/ x)) '("foo" "bar" "1" "2"))) (2 3) !2007-06-05 Tue ; Ruby >> [1, 2, 3].find_all {|x| x == 1} => [1] >> [1, 2, 3].find_all {|x| x % 2 == 0} => [2] >> [1, 2, 3].find_all {|x| x > 1} => [2, 3] >> [1, 2, 3].find_all {|x| x > 3} => [] ; Gauche gosh> (use srfi-1) # gosh> (filter (lambda (x) (eq? x 1)) '(1 2 3)) (1) gosh> (filter (lambda (x) (= (remainder x 2) 0)) '(1 2 3)) (2) gosh> (filter (lambda (x) (> x 1)) '(1 2 3)) (2 3) gosh> (filter (lambda (x) (> x 3)) '(1 2 3)) () !2007-06-04 Mon ; Ruby >> [1, 2, 3].find {|x| x == 1} => 1 >> [1, 2, 3].find {|x| x % 2 == 0} => 2 >> [1, 2, 3].find {|x| x > 3} => nil ; Gauche gosh> (use srfi-1) # gosh> (find (lambda (x) (eq? x 1)) '(1 2 3)) 1 gosh> (find (lambda (x) (= (remainder x 2) 0)) '(1 2 3)) 2 gosh> (find (lambda (x) (> x 3)) '(1 2 3)) #f !2007-06-03 Sun ; Ruby >> [1, 2, 3].each_with_index {|x,i| p [x, i] } [1, 0] [2, 1] [3, 2] => [1, 2, 3] ; Gauche gosh> (use gauche.sequence) # gosh> (for-each-with-index (lambda (i x) (print x " " i)) '(1 2 3)) 1 0 2 1 3 2 #t !2007-06-02 Sat ; Ruby >> [1,2,3].any? => true >> [1,2,3,false].any? => true >> [false,false,false].any? => false >> [1,2,3].any? {|v| v > 3} => false >> [1,2,3].any? {|v| v > 1} => true ; Gauche gosh> (use srfi-1) # gosh> (any (lambda (x) x) '(1 2 3)) 1 gosh> (any (lambda (x) x) '(1 2 3 #f)) 1 gosh> (any (lambda (x) x) '(#f #f #f)) #f gosh> (any (lambda (x) (> x 3)) '(1 2 3)) #f gosh> (any (lambda (x) (> x 1)) '(1 2 3)) #t !2007-06-01 Fri ; Ruby >> [1,2,3].all? => true >> [1,2,3,false].all? => false >> [1,2,3].all? {|v| v > 0} => true >> [1,2,3].all? {|v| v > 1} => false ; Gauche gosh> (use srfi-1) # gosh> (every (lambda (x) x) '(1 2 3)) 3 gosh> (every (lambda (x) x) '(1 2 3 #f)) #f gosh> (every (lambda (x) (> x 0)) '(1 2 3)) #t gosh> (every (lambda (x) (> x 1)) '(1 2 3)) #f !2007-05-31 Thu ; Ruby >> ary = %w[ a b c d e ] => ["a", "b", "c", "d", "e"] >> ary.values_at( 0, 2, 4 ) => ["a", "c", "e"] >> ary.values_at( 3, 4, 5, 6, 35 ) => ["d", "e", nil, nil, nil] >> ary.values_at( 0, -1, -2 ) => ["a", "e", "d"] ; Gauche gosh> (define (ary-values_at ary index) (let ((length (length ary))) (if (null? index) () (cons (if (< (car index) length) (list-ref ary (car index)) '()) (ary-values_at ary (cdr index)))))) ary-values_at gosh> (ary-values_at '("a" "b" "c" "d" "e") '(0 2 4)) ("a" "c" "e") gosh> (ary-values_at '("a" "b" "c" "d" "e") '(3 4 5 6 35)) ("d" "e" () () ()) * 「#f」あたりにした方が良い? * 負の index もやろうかと思ったが、やめた…。拡張した list-ref を作っておけば良いだけか !2007-05-30 Wed ; Ruby >> a = [1, 2, 3] => [1, 2, 3] >> a.unshift 0 => [0, 1, 2, 3] >> a => [0, 1, 2, 3] >> a.unshift [0] => [[0], 0, 1, 2, 3] ; Gauche gosh> (cons 0 '(1 2 3)) (0 1 2 3) gosh> (cons '(0) '(1 2 3)) ((0) 1 2 3) gosh> (append '(0) '(1 2 3)) (0 1 2 3) gosh> (append '((0)) '(1 2 3)) ((0) 1 2 3) 破壊的じゃないけど… !2007-05-29 Tue ; Ruby >> [1, 1, 1].uniq => [1] >> [1, 4, 1].uniq => [1, 4] >> [1, 3, 2, 2, 3].uniq => [1, 3, 2] ; Gauche gosh> (define (ary-uniq ary) (define (iter ary ret) (if (null? ary) ret (if (memq (car ary) ret) (iter (cdr ary) ret) (iter (cdr ary) (append ret (list (car ary))))))) (iter ary '())) ary-uniq gosh> (ary-uniq '(1 1 1)) (1) gosh> (ary-uniq '(1 4 1)) (1 4) gosh> (ary-uniq '(1 3 2 2 3)) (1 3 2) append 使わずにできるの?(順序変えずに) gosh> (define (ary-uniq ary) (define (iter ary ret) (if (null? ary) '() (if (memq (car ary) ret) (iter (cdr ary) ret) (cons (car ary) (iter (cdr ary) (cons (car ary) ret)))))) (iter ary '())) ary-uniq gosh> (ary-uniq '(1 1 1)) (1) gosh> (ary-uniq '(1 4 1)) (1 4) gosh> (ary-uniq '(1 3 2 2 3)) (1 3 2) これでどうだ! !2007-05-28 Mon ; Ruby >> [[1,2], ?> [3,4], ?> [5,6]].transpose => [[1, 3, 5], [2, 4, 6]] ; Gauche gosh> (define (ary-transpose ary) (define (ary-transpose-car ary) (if (null? ary) () (cons (caar ary) (ary-transpose-car (cdr ary))))) (define (ary-transpose-cdr ary) (if (null? ary) () (cons (cadar ary) (ary-transpose-cdr (cdr ary))))) (list (ary-transpose-car ary) (ary-transpose-cdr ary))) ary-transpose gosh> (ary-transpose '((1 2) (3 4) (5 6))) ((1 3 5) (2 4 6)) !2007-05-27 Sun ; Ruby >> [10, 2, 3, 1].sort => [1, 2, 3, 10] >> ["10", "2", "3", "1"].sort => ["1", "10", "2", "3"] >> [10, 2, 3, 1].sort {|a, b| b <=> a} => [10, 3, 2, 1] ; Gauche gosh> (sort '(10 2 3 1)) (1 2 3 10) gosh> (sort '("10" "2" "3" "1")) ("1" "10" "2" "3") gosh> (sort '(10 2 3 1) (lambda (x y) (> x y))) (10 3 2 1) 「比較とソート」にあったか。見逃すところだった… !2007-05-26 Sat ; Ruby >> a = [1, 2, 3] => [1, 2, 3] >> a.shift => 1 >> a => [2, 3] >> a = [] => [] >> a.shift => nil >> a => [] ; Gauche gosh> (define x '(1 2 3)) x gosh> (car x) 1 gosh> (define x (cdr x)) x gosh> x (2 3) 関数化ってどうやれば良いのだろうか? !2007-05-25 Fri Array#reverse_each {|item| ... } とばし ; Ruby >> [1, 2, 3, 4, 1, 2, 3].rindex(0) => nil >> [1, 2, 3, 4, 1, 2, 3].rindex(1) => 4 >> [1, 2, 3, 4, 1, 2, 3].rindex(4) => 3 ; Gauche gosh> (use srfi-1) # gosh> (define (ary-rindex ary val) (let ((rindex (list-index (lambda (x) (eq? x val)) (reverse ary)))) (if rindex (- (length ary) rindex 1) rindex))) ary-rindex gosh> (ary-rindex '(1 2 3 4 1 2 3) 0) #f gosh> (ary-rindex '(1 2 3 4 1 2 3) 1) 4 gosh> (ary-rindex '(1 2 3 4 1 2 3) 4) 3 手抜き。けど、それほどよい方法はない気も。 そもそも、*-right みたいなのはないのか??? !2007-05-24 Thu Array#replace(another) とばし ; Ruby >> [1, 2, 3].reverse => [3, 2, 1] ; Gauche gosh> (reverse '(1 2 3)) (3 2 1) !2007-05-23 Wed ; Ruby >> [[15,1], [25,2], [35,3]].rassoc(2) => [25, 2] ; Gauche gosh> (use util.list) # gosh> (rassoc 2 '((15 . 1) (25 . 2) (35 3))) (25 . 2) !2007-05-22 Tue ; Ruby >> a = [1, 2, 3] => [1, 2, 3] >> a.push 4 => [1, 2, 3, 4] >> a => [1, 2, 3, 4] ; Gauche gosh> (define x '(1 2 3)) x gosh> (set-cdr! (last-pair x) '(4)) # gosh> x (1 2 3 4) !2007-05-21 Mon ; Ruby >> a = [1, 2, 3] => [1, 2, 3] >> a.pop => 3 >> a => [1, 2] ; Gauche gosh> (use srfi-1) # gosh> (define x '(1 2 3)) x gosh> (define y (list-tail x (- (length x) 2))) y gosh> (cadr y) 3 gosh> (set-cdr! y '()) # gosh> x (1 2) 長さが短いとまずい… !2007-05-20 Sun ; Ruby >> [1, nil, nil, 2, 3].nitems => 3 ; Gauche gosh> (use srfi-1) # gosh> (filter (lambda (x) (not (null? x))) '(1 () () 2 3)) (1 2 3) gosh> (length (filter (lambda (x) (not (null? x))) '(1 () () 2 3))) 3 !2007-05-19 Sat ; Ruby >> [1, 2, 3].length => 3 ; Gauche gosh> (length '(1 2 3)) 3 !2007-05-18 Fri ; Ruby >> [1, 2, 3].last => 3 >> [1, 2, 3].last(0) => [] >> [1, 2, 3].last(1) => [3] >> [1, 2, 3].last(2) => [2, 3] >> [1, 2, 3].last(3) => [1, 2, 3] ; Gauche gosh> (car (last-pair '(1 2 3))) 3 gosh> (use srfi-1) # gosh> (take-right '(1 2 3) 0) () gosh> (take-right '(1 2 3) 1) (3) gosh> (take-right '(1 2 3) 2) (2 3) gosh> (take-right '(1 2 3) 3) (1 2 3) !2007-05-17 Thu ; Ruby >> ['a', 'b', 'c'].join => "abc" >> ['a', 'b', 'c'].join(":") => "a:b:c" >> [1, 2, 3].join(":") => "1:2:3" ; Gauche gosh> (string-join '(a b c) "") *** ERROR: string required, but got a Stack Trace: _______________________________________ 0 (string-join '(a b c) "") At line 1 of "(stdin)" 1 (string-join '(a b c) "") At line 1 of "(stdin)" gosh> (string-join '("a" "b" "c")) "a b c" gosh> (string-join '("a" "b" "c") "") "abc" gosh> (string-join '("a" "b" "c") ":") "a:b:c" gosh> (define (my-string-join ary sep) (string-join (map (lambda (x) (x->string x)) ary) sep)) my-string-join gosh> (my-string-join '(a b c) "") "abc" !2007-05-16 Wed ; Ruby >> [1, 2, 3].insert(0, 10) => [10, 1, 2, 3] >> [1, 2, 3].insert(1, 10) => [1, 10, 2, 3] >> [1, 2, 3].insert(-1, 20) => [1, 2, 3, 20] >> [1, 2, 3].insert(0, [1]) => [[1], 1, 2, 3] ; Gauche gosh> (define (ary-insert ary index val) (define (iter ary index val pos) (if (null? ary) () (if (= pos index) (append (list val) (iter ary index val (+ pos 1))) (append (list (car ary)) (iter (cdr ary) index val (+ pos 1)))))) (iter ary index val 0)) ary-insert gosh> (ary-insert '(1 2 3) 0 10) (10 1 2 3) gosh> (ary-insert '(1 2 3) 1 10) (1 10 2 3) gosh> (ary-insert '(1 2 3) 0 '(1)) ((1) 1 2 3) gosh> (use srfi-1) # gosh> (append (take '(1 2 3) 0) '(10) (drop '(1 2 3) 0)) (10 1 2 3) gosh> (append (take '(1 2 3) 1) '(10) (drop '(1 2 3) 1)) (1 10 2 3) gosh> (append (take '(1 2 3) 0) '((1)) (drop '(1 2 3) 0)) ((1) 1 2 3) 破壊的なのは良く分からない… !2007-05-15 Tue ; Ruby >> [1, 2, 3].index(1) => 0 >> [1, 2, 3].index(4) => nil ; Gauche gosh> (define (ary-index ary val) (define (iter ary val index) (if (null? ary) #f (if (eq? (car ary) val) index (iter (cdr ary) val (+ index 1))))) (iter ary val 0)) ary-index gosh> (ary-index '(1 2 3) 1) 0 gosh> (ary-index '(1 2 3) 2) 1 gosh> (ary-index '(1 2 3) 3) 2 gosh> (ary-index '(1 2 3) 4) #f gosh> (use srfi-1) # gosh> (list-index (lambda (x) (eq? x 1)) '(1 2 3)) 0 gosh> (list-index (lambda (x) (eq? x 4)) '(1 2 3)) #f 「#index {|item| ...} (ruby 1.9 feature)」は、まんま list-index か !2007-05-14 Mon ; Ruby >> [1, 2, 3].include?(1) => true >> [1, 2, 3].include?(4) => false ; Gauche gosh> (memq 1 '(1 2 3)) (1 2 3) gosh> (list? (memq 1 '(1 2 3))) #t gosh> (list? (memq 4 '(1 2 3))) #f gosh> (use srfi-1) # gosh> (find (lambda (x) (eq? x 1)) '(1 2 3)) 1 gosh> (find (lambda (x) (eq? x 4)) '(1 2 3)) #f そのものズバリはないのだろうか?ありそうなのだが… !2007-05-13 Sun ; Ruby >> [1, [2, 3, [4], 5]].flatten => [1, 2, 3, 4, 5] ; Gauche gosh> (use srfi-1) # gosh> (concatenate '(1 (2 3 (4) 5))) *** ERROR: pair required, but got 1 ダメか… こういうのがちゃちゃっと書けないのがおバカなところ… gosh> (define (ary-flatten ary) (if (null? ary) () (if (list? (car ary)) (append (ary-flatten (car ary)) (ary-flatten (cdr ary))) (append (list (car ary)) (ary-flatten (cdr ary)))))) ary-flatten gosh> (ary-flatten '(1 (2 3 (4) 5))) (1 2 3 4 5) OK??? こうやった方が良い??? gosh> (define (ary-flatten ary) (if (null? ary) () (append (if (list? (car ary)) (ary-flatten (car ary)) (list (car ary))) (ary-flatten (cdr ary))))) ary-flatten gosh> (ary-flatten '(1 (2 3 (4) 5))) (1 2 3 4 5) append 使わないで書けるのだろうか? !2007-05-12 Sat ; Ruby >> [0, 1, 2].first(0) => [] >> [0, 1, 2].first(1) => [0] >> [0, 1, 2].first(2) => [0, 1] >> [0, 1, 2].first(3) => [0, 1, 2] >> [0, 1, 2].first(4) => [0, 1, 2] ; Gauche gosh> (use srfi-1) # gosh> (take '(0 1 2) 0) () gosh> (take '(0 1 2) 1) (0) gosh> (take '(0 1 2) 2) (0 1) gosh> (take '(0 1 2) 3) (0 1 2) gosh> (take '(0 1 2) 4) *** ERROR: pair required, but got () gosh> (use util.list) # gosh> (take* '(0 1 2) 4) (0 1 2) !2007-05-11 Fri ; Ruby >> [0, 1, 2].first => 0 >> [].first => nil ; Gauche gosh> (car '(0 1 2)) 0 gosh> (car '()) *** ERROR: pair required, but got () gosh> (use srfi-1) # gosh> (first '(0 1 2)) 0 gosh> (first '()) *** ERROR: pair required, but got () gosh> (take '() 1) *** ERROR: pair required, but got () !2007-05-10 Thu ; Ruby >> a = [1, 2, 3] => [1, 2, 3] >> a.fill(10) => [10, 10, 10] >> a => [10, 10, 10] ; Gauche gosh> (define a '(1 2 3)) a gosh> (define (ary-fill ary val) (if (null? ary) () (begin (set-car! ary val) (ary-fill (cdr ary) val)))) ary-fill gosh> (ary-fill a 10) () gosh> a (10 10 10) ちょっと気持ち悪いな gosh> (define (ary-fill ary val) (if (not (null? ary)) (begin (set-car! ary val) (ary-fill (cdr ary) val)))) ary-fill gosh> (define a '(1 2 3)) a gosh> (ary-fill a 10) # gosh> a (10 10 10) 破壊的でなければ、、 gosh> (define a '(1 2 3)) a gosh> (map (lambda (x) 10) a) (10 10 10) gosh> a (1 2 3) !2007-05-09 Wed ; Ruby >> [1, 2, 3].fetch(2) => 3 >> [1, 2, 3].fetch(3) IndexError: index 3 out of array from (irb):2:in `fetch' from (irb):2 >> [1, 2, 3].fetch(3, 20) => 20 ; Gauche gosh> (list-ref '(1 2 3) 2) 3 gosh> (list-ref '(1 2 3) 3) *** ERROR: argument out of range: 3 Stack Trace: _______________________________________ 0 (list-ref '(1 2 3) 3) At line 2 of "(stdin)" 1 (list-ref '(1 2 3) 3) At line 2 of "(stdin)" gosh> (list-ref '(1 2 3) 3 20) 20 !2007-05-08 Tue ; Ruby >> [1, 2, 3].empty? => false >> [].empty? => true ; Gauche gosh> (null? '(1 2 3)) #f gosh> (null? '()) #t 多少不安だけど良いのか? !2007-05-07 Mon ; Ruby >> [1, 2, 3].each_index {|i| p i } 0 1 2 => [1, 2, 3] ; Gauche gosh> (use gauche.sequence) # gosh> (for-each-with-index (lambda (i x) (print i)) '(1 2 3)) 0 1 2 #t !2007-05-06 Sun ; Ruby >> [1, 2, 3].each {|x| p x } 1 2 3 => [1, 2, 3] ; Gauche gosh> (for-each (lambda (x) (print x)) '(1 2 3)) 1 2 3 # gosh> (for-each print '(1 2 3)) 1 2 3 # !2007-05-05 Sat ; Ruby >> a = [1, 2, 3, 4, 5] => [1, 2, 3, 4, 5] >> a.delete_if {|x| x % 2 == 0} => [1, 3, 5] >> a => [1, 3, 5] ; Gauche gosh> (use srfi-1) # gosh> (remove (lambda (x) (= (remainder x 2) 0)) '(1 2 3 4 5)) (1 3 5) 破壊的なのは良く分からない、、、 !2007-05-04 Fri ; Ruby >> array = [0, 1, 2, 3, 4] => [0, 1, 2, 3, 4] >> array.delete_at 2 => 2 >> array => [0, 1, 3, 4] ; Gauche gosh> (define (ary-delete_at ary pos) (define (iter ary pos n) (if (null? ary) () (if (= n pos) (iter (cdr ary) pos (+ 1 n)) (cons (car ary) (iter (cdr ary) pos (+ 1 n)))))) (iter ary pos 0)) ary-delete_at gosh> (ary-delete_at '(0 1 2 3 4) 2) (0 1 3 4) 破壊的なのは良く分からない、、、 !2007-05-03 Thu ; Ruby >> array = [1, 2, 3, 2, 1] => [1, 2, 3, 2, 1] >> array.delete(2) => 2 >> array => [1, 3, 1] ; Gauche gosh> (use srfi-1) # gosh> (delete 2 '(1 2 3 2 1)) (1 3 1) 破壊的なのは良く分からない、、、 !2007-05-02 Wed ; Ruby >> array = [1, 2] => [1, 2] >> array.concat [3, 4] => [1, 2, 3, 4] >> array => [1, 2, 3, 4] ; Gauche gosh> (define x '(1 2)) x gosh> (set-cdr! (last-pair x) '(3 4)) # gosh> x (1 2 3 4) 本当にこれで良い? !2007-05-01 Tue ; Ruby >> [1, nil, 2, nil, 3, nil].compact => [1, 2, 3] ; Gauche gosh> (use srfi-1) # gosh> (delete #f '(1 #f 2 #f 3 #f)) (1 2 3) gosh> (delete '() '(1 '() 2 '() 3 '())) (1 '() 2 '() 3 '()) gosh> (delete '() '(1 () 2 () 3 ())) (1 2 3) !2007-04-30 Mon ; Ruby >> [1, 2, 3].map {|i| i * 3 } => [3, 6, 9] ; Gauche gosh> (use gauche.collection) # gosh> (map (lambda (x) (* x 3)) '#(1 2 3)) (3 6 9) !2007-04-29 Sun ; Ruby >> ary1 = [1] => [1] >> ary2 = ary1 => [1] >> ary2[0] = 2 => 2 >> ary1 => [2] >> ary2 => [2] >> ary1 = [1] => [1] >> ary2 = ary1.clone => [1] >> ary2[0] = 2 => 2 >> ary1 => [1] >> ary2 => [2] ; Gauche gosh> (define ary1 '(1)) ary1 gosh> (define ary2 ary1) ary2 gosh> (set-car! ary2 2) # gosh> ary1 (2) gosh> ary2 (2) gosh> (define ary1 '(1)) ary1 gosh> (define ary2 (list-copy ary1)) ary2 gosh> (set-car! ary2 2) # gosh> ary1 (1) gosh> ary2 (2) !2007-04-28 Sat ; Ruby >> ary = [[1,15], [2,25], [3,35]] => [[1, 15], [2, 25], [3, 35]] >> ary.assoc(2) => [2, 25] >> ary.assoc(100) => nil ; Gauche gosh> (define (ary-assoc ary key) (if (null? ary) () (if (eq? (car (car ary)) key) (car ary) (ary-assoc (cdr ary) key)))) ary-assoc gosh> (ary-assoc '((1 15) (2 25) (3 35)) 2) (2 25) gosh> (ary-assoc '((1 15) (2 25) (3 35)) 100) () gosh> (ary-assoc '((1 . 15) (2 . 25) (3 . 35)) 2) (2 . 25) gosh> (ary-assoc '((1 . 15) (2 . 25) (3 . 35)) 100) () gosh> (assq 2 '((1 15) (2 25) (3 35))) (2 25) gosh> (assq 2 '((1 . 15) (2 . 25) (3 . 35))) (2 . 25) gosh> (assq 100 '((1 15) (2 25) (3 35))) #f gosh> (assq 100 '((1 . 15) (2 . 25) (3 . 35))) #f !2007-04-27 Fri ; Ruby >> [1, 2, 3] == [1, 2, 3] => true >> [1, 2, 3] == [1, 2, 4] => false ; Gauche gosh> (eq? '(1 2 3) '(1 2 3)) #f gosh> (define (ary-eq ary ary2) (if (null? ary) (null? ary2) (if (null? ary2) #f (if (eq? (car ary) (car ary2)) (ary-eq (cdr ary) (cdr ary2)) #f)))) ary-eq gosh> (ary-eq '(1 2 3) '(1 2 3)) #t gosh> (ary-eq '(1 2 3) '(1 2 4)) #f !2007-04-26 Thu ; Ruby >> [1, 2, 3] <=> [1, 2, 3] => 0 >> [1, 2, 4] <=> [1, 2, 3] => 1 >> [1, 2, 3] <=> [1, 2, 4] => -1 ; Gauche gosh> (define (ary-cmp ary ary2) (if (null? ary) (if (null? ary2) 0 -1) (if (null? ary2) 1 (cond ((> (car ary) (car ary2)) 1) ((< (car ary) (car ary2)) -1) (else (ary-cmp (cdr ary) (cdr ary2))))))) ary-cmp gosh> (ary-cmp '(1) '()) 1 gosh> (ary-cmp '() '()) 0 gosh> (ary-cmp '() '(1)) -1 gosh> (ary-cmp '(1 2) '(1 2)) 0 gosh> (ary-cmp '(1 2) '(1 2 3)) -1 gosh> (ary-cmp '(1 2 3) '(1 2 4)) -1 gosh> (ary-cmp '(1 2 3) '(1 2)) 1 gosh> (ary-cmp '(1 2 4) '(1 2 3)) 1 !2007-04-25 Wed ; Ruby >> ary = [1, 2, 3] => [1, 2, 3] >> ary << 4 => [1, 2, 3, 4] ; Gauche gosh> (last-pair '(1 2 3)) (3) gosh> (define x '(1 2 3)) x gosh> (set-cdr! (last-pair x) '(4)) # gosh> x (1 2 3 4) gosh> (define x '(1 2 3)) x gosh> (append! x '(4)) (1 2 3 4) gosh> x (1 2 3 4) どれが普通なのだ? !2007-04-24 Tue ; Ruby >> [1, 2, 3] | [1, 3, 5] => [1, 2, 3, 5] ; Gauche gosh> (use srfi-1) # gosh> (lset-union eq? '(1 2 3) '(1 3 5)) (5 1 2 3) !2007-04-23 Mon ; Ruby >> [1, 2, 3] & [1] => [1] ; Gauche gosh> (use srfi-1) # gosh> (lset-intersection eq? '(1 2 3) '(1)) (1) !2007-04-22 Sun ; Ruby >> [1, 2, 1, 3, 1, 4, 1, 5] - [2, 3, 4, 5] => [1, 1, 1, 1] >> [1, 2, 1, 3, 1, 4, 1, 5] - [1, 2, 3, 4, 5] => [] ; Gauche gosh> (use srfi-1) # gosh> (define z '(1 2 1 3 1 4 1 5)) z gosh> (for-each (lambda (x) (delete! x z)) '(2 3 4 5)) # gosh> z (1 1 1 1) gosh> (define z '(1 2 1 3 1 4 1 5)) z gosh> (for-each (lambda (x) (delete! x z)) '(1 2 3 4 5)) # gosh> z (1) あれ? gosh> (define z '(1 2 1 3 1 4 1 5)) z gosh> (delete! 1 z) (2 3 4 5) gosh> z (1 2 3 4 5) 壊れるかもしれないけど壊れた値が返す値という訳ではないということか… gosh> (use srfi-1) # gosh> (define (ary-diff ary ary2) (if (null? ary2) ary (ary-diff (delete (car ary2) ary) (cdr ary2)))) ary-diff gosh> (ary-diff '(1 2 1 3 1 4 1 5) '(2 3 4 5)) (1 1 1 1) gosh> (ary-diff '(1 2 1 3 1 4 1 5) '(1 2 3 4 5)) () せっかく書いてみたけど、これ↓で良かった… gosh> (use srfi-1) # gosh> (lset-difference eq? '(1 2 1 3 1 4 1 5) '(2 3 4 5)) (1 1 1 1) gosh> (lset-difference eq? '(1 2 1 3 1 4 1 5) '(1 2 3 4 5)) () !2007-04-21 Sat ; Ruby >> [1, 2, 3] * 3 => [1, 2, 3, 1, 2, 3, 1, 2, 3] ; Gauche gosh> (make-list 3 '(1 2 3)) (#0=(1 2 3) #0# #0#) gosh> (define x (make-list 3 '(1 2 3))) x gosh> x (#0=(1 2 3) #0# #0#) gosh> (list-ref x 0) (1 2 3) gosh> (list-ref x 1) (1 2 3) gosh> (list-ref x 2) (1 2 3) これで OK??? !2007-04-20 Fri ; Ruby >> [1, 2, 3] + [4, 5, 6] => [1, 2, 3, 4, 5, 6] ; Gauche gosh> (append '(1 2 3) '(4 5 6)) (1 2 3 4 5 6) gosh> (use srfi-1) # gosh> (concatenate '((1 2 3) (4 5 6))) (1 2 3 4 5 6) !2007-04-19 Thu ; Ruby >> ary = [0, 1, 2, 3, 4, 5] => [0, 1, 2, 3, 4, 5] >> ary[0..2] = ["a", "b"] => ["a", "b"] >> ary => ["a", "b", 3, 4, 5] >> ary[2..4] = nil => nil >> ary => ["a", "b"] ; Gauche gosh> (use gauche.sequence) # gosh> (define x '(0 1 2 3 4 5)) x gosh> (set! (subseq x 0 3) '("a" "b" "c")) #t gosh> x ("a" "b" "c" 3 4 5) gosh> (set! (subseq x 0 3) '("a" "b")) *** ERROR: not enough values for (setter subseq) ("a" "b") gosh> (set! (subseq x 0 3) '("a" "b" "c" "d")) #t gosh> x ("a" "b" "c" 3 4 5) 「value-seqはどんなシーケンスでも構いませんが、 (end - start) よりは長くなくてはなりません。」にひっかかっている? 「よりは長くなくてはなりません。」は分かりにくいから、 「より長くてはいけません」か「より長い必要があります」にして欲しいな。 (どっちの意味だっけ?) シーケンスフレームワークでは vector とかもあるからこういう仕様なのか??? 同じ長さの交換でなくても頑張ればできるのかな? 内容を書き換えるのではなく。新しいのを返すものを書いてみる。 エラーチェックなし。 gosh> (define (ary-set ary start end replace-ary) (use gauche.sequence) (append (subseq ary 0 start) replace-ary (subseq ary (+ end 1) (length ary)))) ary-set gosh> (define x '(0 1 2 3 4 5)) x gosh> (ary-set x 0 2 '("a" "b")) ("a" "b" 3 4 5) !2007-04-18 Wed ; Ruby >> x = [0, 1, 2] => [0, 1, 2] >> x[0] = 10 => 10 >> x => [10, 1, 2] ; Gauche gosh> (define x '(0 1 2)) x gosh> (use gauche.sequence) # gosh> ((setter ref) x 0 10) # gosh> x (10 1 2) gosh> (define x '(0 1 2)) x gosh> (set! (ref x 0) 10) # gosh> x (10 1 2) !2007-04-17 Tue ; Ruby >> [0, 1, 2][0, 2] => [0, 1] >> [0, 1, 2][0, 3] => [0, 1, 2] >> [0, 1, 2][0, 1] => [0] >> [0, 1, 2][0, 0] => [] >> [0, 1, 2][1, 2] => [1, 2] ; Gauche subseq を使うか、もしくはこんなのはどうだろうか? gosh> (use srfi-1) # gosh> (take (drop '(0 1 2) 0) 2) (0 1) gosh> (take (drop '(0 1 2) 0) 3) (0 1 2) gosh> (take (drop '(0 1 2) 0) 1) (0) gosh> (take (drop '(0 1 2) 0) 0) () gosh> (take (drop '(0 1 2) 1) 2) (1 2) util.list にエラーに寛容な take*, drop* もあるようだ もちろん、もっと純粋に list 処理を書くこともできる !2007-04-16 Mon ; Ruby >> [0, 1, 2][0..1] => [0, 1] >> [0, 1, 2][0..2] => [0, 1, 2] >> [0, 1, 2][0..0] => [0] >> [0, 1, 2][1..2] => [1, 2] >> [0, 1, 2][0..2] => [0, 1, 2] >> [0, 1, 2][0...2] => [0, 1] >> [0, 1, 2][0...3] => [0, 1, 2] >> [0, 1, 2][0...1] => [0] >> [0, 1, 2][1...3] => [1, 2] ; Gauche gosh> (use gauche.sequence) # gosh> (subseq '(0 1 2) 0 2) (0 1) gosh> (subseq '(0 1 2) 0 3) (0 1 2) gosh> (subseq '(0 1 2) 0 1) (0) gosh> (subseq '(0 1 2) 1 3) (1 2) !2007-04-15 Sun ; Ruby >> [1, 2, 3][0] => 1 >> [1, 2, 3][1] => 2 >> [1, 2, 3][4] => nil >> [1, 2, 3][-1] => 3 ; Gauche gosh> (list-ref '(1 2 3) 0) 1 gosh> (list-ref '(1 2 3) 1) 2 gosh> (list-ref '(1 2 3) 4) *** ERROR: argument out of range: 4 Stack Trace: _______________________________________ 0 (list-ref '(1 2 3) 4) At line 3 of "(stdin)" 1 (list-ref '(1 2 3) 4) At line 3 of "(stdin)" gosh> (list-ref '(1 2 3) -1) *** ERROR: argument out of range: -1 Stack Trace: _______________________________________ 0 (list-ref '(1 2 3) -1) At line 4 of "(stdin)" 1 (list-ref '(1 2 3) -1) At line 4 of "(stdin)" gosh> (list-ref '(1 2 3) 4 #f) #f ある意味、fetch(nth) に近いか? !2007-04-14 Sat ; Ruby >> Array.new(5) {|i| i } => [0, 1, 2, 3, 4] ; Gauche gosh> (use srfi-1) # gosh> (iota 5) (0 1 2 3 4) !2007-04-13 Fri ; Ruby >> Array.new(5) => [nil, nil, nil, nil, nil] >> Array.new(5, 1) => [1, 1, 1, 1, 1] ; Gauche gosh> (make-list 5 1) (1 1 1 1 1) gosh> (make-list 5) (#f #f #f #f #f) gosh> (make-list 5 "foo") (#0="foo" #0# #0# #0# #0#) ふにゃ?同じオブジェクトという意味なのか??? gosh> (define x (make-list 5 "foo")) x gosh> (set-car! x "bar") # gosh> x ("bar" #0="foo" #0# #0# #0#) !2007-04-12 Thu ; Ruby >> [1, 2, 3] => [1, 2, 3] >> ["a", "b", "c"] => ["a", "b", "c"] >> [1, 2, 3, "a", "b", "c"] => [1, 2, 3, "a", "b", "c"] ; Gauche gosh> '(1 2 3) (1 2 3) gosh> '("a" "b" "c") ("a" "b" "c") gosh> '(1 2 3 "a" "b" "c") (1 2 3 "a" "b" "c") !2007-04-11 Wed ; Ruby >> 1.upto(3) {|n| p n} 1 2 3 => 1 ; Gauche gosh> (use gauche.collection) # gosh> (use srfi-42) # gosh> (define (integer-upto n max proc) (for-each proc (list-ec (:range x n (+ max 1)) x))) integer-upto gosh> (integer-upto 1 3 print) 1 2 3 # !2007-04-10 Tue うーむ、tr ってどう実装したら良いんだろう? 正規表現を使わない場合にはやれば実装できると思うのだが、 正規表現を使う場合の実装方法がまったく思いつかない。 「[a-c]」を文字列に展開してくれるような関数ないのかな? ; Ruby >> "abc".upcase => "ABC" ; Gauche gosh> (use srfi-13) # gosh> (string-upcase "abc") "ABC" !2007-04-09 Mon ; Ruby >> " 10".to_i => 10 >> "010".to_i => 10 >> "-010".to_i => -10 ; Gauche gosh> (string->integer " 10") *** ERROR: unbound variable: string->integer Stack Trace: _______________________________________ 0 (string->integer " 10") At line 1 of "(stdin)" 1 (string->integer " 10") At line 1 of "(stdin)" gosh> (x->integer " 10") 0 gosh> (x->integer "10") 10 gosh> (x->integer "010") 10 gosh> (x->integer "-010") -10 gosh> (x->integer "10.2") 10 gosh> (x->integer "1e2") 100 gosh> (x->integer "1xxx") 0 !2007-04-08 Sun ; Ruby >> "10".to_f => 10.0 >> "10e2".to_f => 1000.0 >> "1e-2".to_f => 0.01 >> ".1".to_f => 0.1 >> "nan".to_f => 0.0 ; Gauche gosh> (string->number "10") 10 gosh> (string->number "10e2") 1000.0 gosh> (string->number "1e-2") 0.01 gosh> (string->number ".1") 0.1 gosh> (string->number "nan") #f gosh> (+ (string->number "10") 0.0) 10.0 gosh> (integer? (+ (string->number "10") 0.0)) #t gosh> (real? (+ (string->number "10") 0.0)) #t gosh> (integer? 1.2) #f gosh> (integer? 1.0) #t 正統的な float の生成方法は? !2007-04-07 Sat ; Ruby >> "abcDEF".swapcase => "ABCdef" ; Gauche gosh> (use srfi-13) # gosh> (define (string-swapcase str) (string-map (lambda (x) (if (char-upper-case? x) (char-downcase x) (char-upcase x))) str)) string-swapcase gosh> (string-swapcase "abcDEF") "ABCdef" !2007-04-06 Fri ; Ruby >> "abc".sub(/a/, "A") => "Abc" >> "abc".sub(/ab/, "AB") => "ABc" >> "abc abc".sub(/ab/, "AB") => "ABc abc" ; Gauche gosh> (regexp-replace #/a/ "abc" "A") "Abc" gosh> (regexp-replace #/ab/ "abc" "AB") "ABc" gosh> (regexp-replace #/ab/ "abc abc" "AB") "ABc abc" !2007-04-05 Thu ; Ruby >> " abc\n".rstrip => " abc" >> " abc \t\r\n".rstrip => " abc" >> " abc".rstrip => " abc" >> "abc\n".rstrip => "abc" >> "abc ".rstrip => "abc" ; Gauche gosh> (use srfi-13) # gosh> (string-trim-right " abc\n") " abc" gosh> (string-trim-right " abc \t\r\n") " abc" gosh> (string-trim-right " abc") " abc" gosh> (string-trim-right "abc\n") "abc" gosh> (string-trim-right "abc ") "abc" !2007-04-04 Wed ; Ruby >> " abc\n".lstrip => "abc\n" >> "\t abc\n".lstrip => "abc\n" >> "abc\n".lstrip => "abc\n" >> "\nabc".lstrip => "abc" >> " abc".lstrip => "abc" >> "abc".lstrip => "abc" ; Gauche gosh> (use srfi-13) # gosh> (string-trim " abc\n") "abc\n" gosh> (string-trim "\t abc\n") "abc\n" gosh> (string-trim "abc\n") "abc\n" gosh> (string-trim "\nabc") "abc" gosh> (string-trim " abc") "abc" gosh> (string-trim "abc") "abc" !2007-04-03 Tue ; Ruby >> " abc \r\n".strip => "abc" >> "abc\n".strip => "abc" >> " abc".strip => "abc" >> "abc".strip => "abc" >> "\tabc\n".strip => "abc" >> " abc\r\n".strip => "abc" ; Gauche gosh> (use srfi-13) # gosh> (string-trim-both " abc \r\n") "abc" gosh> (string-trim-both "abc\n") "abc" gosh> (string-trim-both " abc") "abc" gosh> (string-trim-both "abc") "abc" gosh> (string-trim-both "\tabc\n") "abc" gosh> (string-trim-both " abc\r\n") "abc" !2007-04-02 Mon ; Ruby >> "112233445566778899".squeeze => "123456789" >> "112233445566778899".squeeze("2-8") => "11234567899" >> "112233445566778899".squeeze("2378") => "11234455667899" ; Gauche gosh> (regexp-replace-all #/(.)\1+/ "112233445566778899" "\\1") "123456789" gosh> (regexp-replace-all #/([2-8])\1+/ "112233445566778899" "\\1") "11234567899" gosh> (regexp-replace-all #/([2378])\1+/ "112233445566778899" "\\1") "11234455667899" どうもこんな感じでいけそうだ。けど、関数化が良く分からないが… (ようは文字列→正規表現の方法が分かっていない) !2007-04-01 Sun ; Ruby >> "a b c".split => ["a", "b", "c"] >> "a b c".split => ["a", "b", "c"] >> " a b c ".split => ["a", "b", "c"] >> "a:b:c".split(":") => ["a", "b", "c"] >> ":a:b:c:".split(":") => ["", "a", "b", "c"] >> "a::b::c".split(":") => ["a", "", "b", "", "c"] >> "a::b::c".split(/:/) => ["a", "", "b", "", "c"] >> "a::b::c".split(/:+/) => ["a", "b", "c"] >> "a::b::c".split("::") => ["a", "b", "c"] ; Gauche gosh> (string-split "a b c" #\ ) ("a" "b" "c") gosh> (string-split "a b c" #\ ) ("a" "" "b" "" "c") gosh> (string-split " a b c " #\ ) ("" "a" "" "b" "" "c" "") gosh> (string-split "a:b:c" #\:) ("a" "b" "c") gosh> (string-split ":a:b:c:" #\:) ("" "a" "b" "c" "") gosh> (string-split "a::b::c" #\:) ("a" "" "b" "" "c") gosh> (string-split "a::b::c" #/:/) ("a" "" "b" "" "c") gosh> (string-split "a::b::c" #/:+/) ("a" "b" "c") gosh> (string-split "a::b::c" "::") ("a" "b" "c") !2007-03-31 Sat ; Ruby >> "foobar".scan(/./) => ["f", "o", "o", "b", "a", "r"] >> "foobarbazfoobarbaz".scan(/ba./) => ["bar", "baz", "bar", "baz"] >> "foobar".scan(/(.)/) => [["f"], ["o"], ["o"], ["b"], ["a"], ["r"]] >> "foobarbazfoobarbaz".scan(/(ba)(.)/) => [["ba", "r"], ["ba", "z"], ["ba", "r"], ["ba", "z"]] >> "foobarbazfoobarbaz".scan(/ba./) {|s| p s} "bar" "baz" "bar" "baz" => "foobarbazfoobarbaz" >> "foobarbazfoobarbaz".scan(/(ba)(.)/) {|s| p s} ["ba", "r"] ["ba", "z"] ["ba", "r"] ["ba", "z"] => "foobarbazfoobarbaz" ; Gauche gosh> (use srfi-13) # gosh> (define (my-string-scan str pattern) (let ((m (pattern str))) (if m (cons (m 0) (my-string-scan (substring/shared str (rxmatch-end m)) pattern)) '()))) my-string-scan gosh> (my-string-scan "foobar" #/./) ("f" "o" "o" "b" "a" "r") gosh> (my-string-scan "foobarbazfoobarbaz" #/ba./) ("bar" "baz" "bar" "baz") gosh> (my-string-scan "foobar" #/(.)/) ("f" "o" "o" "b" "a" "r") gosh> (define (my-string-scan str pattern) (define (make-submatch-list m n) (if (< n (rxmatch-num-matches m)) (cons (m n) (make-submatch-list m (+ n 1))) '())) (let ((m (pattern str))) (if m (cons (if (> (rxmatch-num-matches m) 1) (make-submatch-list m 1) (m 0)) (my-string-scan (substring/shared str (rxmatch-end m)) pattern)) '()))) my-string-scan gosh> (my-string-scan "foobar" #/./) ("f" "o" "o" "b" "a" "r") gosh> (my-string-scan "foobarbazfoobarbaz" #/ba./) ("bar" "baz" "bar" "baz") gosh> (my-string-scan "foobar" #/(.)/) (("f") ("o") ("o") ("b") ("a") ("r")) gosh> (my-string-scan "foobarbazfoobarbaz" #/(ba)(.)/) (("ba" "r") ("ba" "z") ("ba" "r") ("ba" "z")) gosh> (define (my-string-scan str pattern proc) (define (make-submatch-list m n) (if (< n (rxmatch-num-matches m)) (cons (m n) (make-submatch-list m (+ n 1))) '())) (let ((m (pattern str))) (if m (begin (if (> (rxmatch-num-matches m) 1) (proc (make-submatch-list m 1)) (proc (m 0))) (my-string-scan (substring/shared str (rxmatch-end m)) pattern proc)) #f))) my-string-scan gosh> (my-string-scan "foobarbazfoobarbaz" #/ba./ display) barbazbarbaz#f gosh> (my-string-scan "foobarbazfoobarbaz" #/ba./ print) bar baz bar baz #f gosh> (my-string-scan "foobarbazfoobarbaz" #/(ba)(.)/ print) (ba r) (ba z) (ba r) (ba z) #f 本当は省略可能にしといた方が良いが… !2007-03-30 Fri ; Ruby >> "abc abc".rindex("a") => 4 >> "abc abc".rindex("d") => nil >> "abc abc".rindex("a", 4) => 4 >> "abc abc".rindex("a", 3) => 0 ; Gauche gosh> (use srfi-13) # gosh> (string-index-right "abc abc" #\a) 4 gosh> (string-index-right "abc abc" #\d) #f gosh> (string-index-right "abc abc" "ab") *** ERROR: argument needs to be either a character, a char-set, or a procedure: "ab" gosh> (string-index-right "abc abc" #\a 3) 4 gosh> (string-index-right "abc abc" #\a 4) 4 gosh> (string-index-right "abc abc" #\a 5) #f * 検索したいものとして文字列を与えたいときにはどうしたら? * string-contains-right というものはないの? !2007-03-29 Thu String#replace とばし。 Gauche は自由自在に文字列を書き換えることは できないのではないかと思っているため。 ; Ruby >> "abc".reverse => "cba" >> "abc".reverse! => "cba" >> s = "abc"; s.reverse!; s => "cba" >> s = "abc"; s.reverse; s => "abc" ; Gauche gosh> (use srfi-13) # gosh> (string-reverse "abc") "cba" gosh> (let ((s (string-copy "abc"))) (string-reverse! s) s) "cba" !2007-03-28 Wed String#match は regexp.match でやることにしてとばし。 String#next はめんどいのでとばし。 http://d.hatena.ne.jp/rui314/20070312/p1 ; Ruby >> "10".oct => 8 >> "010".oct => 8 >> "8".oct => 0 >> "0b10".oct => 2 >> "10".oct => 8 >> "010".oct => 8 >> "0x10".oct => 16 >> "1_0_1x".oct => 65 ; Gauche gosh> (string->number "10" 8) 8 gosh> (string->number "010" 8) 8 gosh> (string->number "8" 8) #f gosh> (string->number "0b10" 8) #f gosh> (string->number "10" 8) 8 gosh> (string->number "010" 8) 8 gosh> (string->number "0x10" 8) #f gosh> (string->number "1_0_1x" 8) #f !2007-03-27 Tue ; Ruby >> "foo".length => 3 >> "foo".size => 3 ; Gauche gosh> (string-length "foo") 3 !2007-03-26 Mon ; Ruby >> "foo".intern => :foo >> :foo.to_s => "foo" ; Gauche gosh> (string->symbol "foo") foo gosh> (symbol->string 'foo) "foo" !2007-03-25 Sun ; Ruby >> "abc".insert(1, "AAA") => "aAAAbc" ; Gauche gosh> (use srfi-13) # gosh> (string-replace "abc" "AAA" 1 1) "aAAAbc" 破壊的ではないけど * マニュアルの「string-replace s1 s2 start1 end2 &optional start2 end2」は間違いっぽい !2007-03-24 Sat ; Ruby >> "abc012".index(/\d/) => 3 >> "abc".index(/\d/) => nil >> "abc012".index(/\d/, 3) => 3 >> "abc012".index(/\d/, 4) => 4 ; Gauche gosh> (rxmatch-start (#/\d/ "abc012")) 3 gosh> (rxmatch-start (#/\d/ "abc")) #f 正規表現の関数自体には文字列のどこから検索するかを指定する機能は なさそうな気がする 部分文字列を与えて、戻り値にバイアスをかけるしかない??? gosh> (use srfi-13) # gosh> (define (string-index str pattern pos) (let ((n (rxmatch-start (pattern (substring/shared str pos))))) (if (eq? n #f) n (+ n pos)))) string-index gosh> (string-index "abc012" #/\d/ 0) 3 gosh> (string-index "abc012" #/\d/ 3) 3 gosh> (string-index "abc012" #/\d/ 4) 4 * srfi-13 に string-index があるので別な名前の方が良さそう * エラー処理が甘すぎる !2007-03-23 Fri ; Ruby >> "abc".index("a") => 0 >> "abc".index("b") => 1 >> "abc".index("d") => nil >> "abc abc".index("a", 1) => 4 ; Gauche gosh> (string-scan "abc" "a") 0 gosh> (string-scan "abc" "b") 1 gosh> (string-scan "abc" "d") #f gosh> (use srfi-13) # gosh> (string-contains "abc" "a") 0 gosh> (string-contains "abc" "b") 1 gosh> (string-contains "abc" "d") #f gosh> (string-contains "abc abc" "a" 1) 4 !2007-03-22 Thu ; Ruby >> "abc".include?("a") => true >> "abc".include?("A") => false >> "abc".include?("ab") => true >> "abc".include?(97) => true ; Gauche gosh> (string-scan "abc" "a") 0 gosh> (not (eq? (string-scan "abc" "a") #f)) #t gosh> (not (eq? (string-scan "abc" "A") #f)) #f gosh> (not (eq? (string-scan "abc" "ab") #f)) #t gosh> (use srfi-13) # gosh> (string-index "abc" "a") *** ERROR: argument needs to be either a character, a char-set, or a procedure: "a" Stack Trace: _______________________________________ gosh> (string-index "abc" #\a) 0 gosh> (string-index "abc" #\A) #f gosh> (string-contains "abc" "a") 0 gosh> (string-contains "abc" "A") #f gosh> (not (eq? (string-contains "abc" "a") #f)) #t gosh> (not (eq? (string-contains "abc" "A") #f)) #f gosh> (not (eq? (string-contains "abc" "ab") #f)) #t !2007-03-21 Wed ; Ruby >> "10".hex => 16 >> "-10".hex => -16 >> "ff".hex => 255 >> "0x10".hex => 16 >> "-0x10".hex => -16 >> "xyz".hex => 0 >> "10z".hex => 16 >> "1_0".hex => 16 ; Gauche gosh> (string->number "10" 16) 16 gosh> (string->number "-10" 16) -16 gosh> (string->number "ff" 16) 255 gosh> (string->number "0x10" 16) #f gosh> (string->number "-0x10" 16) #f gosh> (string->number "xyz" 16) #f gosh> (string->number "10z" 16) #f gosh> (string->number "1_0" 16) #f !2007-03-20 Tue ; Ruby >> 'abcabc'.gsub(/b/, '(\&)') => "a(b)ca(b)c" >> 'abcabc'.gsub(/b/) {|s| s.upcase } => "aBcaBc" ; Gauche gosh> (regexp-replace-all #/b/ "abcabc" "(\\0)") "a(b)ca(b)c" gosh> (use srfi-13) # gosh> (regexp-replace-all #/b/ "abcabc" (lambda (m) (string-upcase (rxmatch-substring m 0)))) "aBcaBc" !2007-03-19 Mon ; Ruby >> "abc".gsub(/a/, "A") => "Abc" >> "abc".gsub(/ab/, "AB") => "ABc" >> "abc abc".gsub(/ab/, "AB") => "ABc ABc" ; Gauche gosh> (regexp-replace-all #/a/ "abc" "A") "Abc" gosh> (regexp-replace-all #/ab/ "abc" "AB") "ABc" gosh> (regexp-replace-all #/ab/ "abc abc" "AB") "ABc ABc" !2007-03-18 Sun ; Ruby >> "".empty? => true ; Gauche gosh> (use srfi-13) # gosh> (string-null? "") #t gosh> (string-null? "a") #f gosh> (string-null? (make-string 1)) #f gosh> (string-null? (string-copy "")) #t gosh> (string=? "" "") #t !2007-03-17 Sat ; Ruby >> "abc".each_byte {|x| p x} 97 98 99 => "abc" >> "abc".each_byte {|x| p x.chr} "a" "b" "c" => "abc" ; Gauche gosh> (use gauche.collection) # gosh> (for-each print (string->list "abc")) a b c # gosh> (for-each print (map (lambda (x) (char->integer x)) (string->list "abc"))) 97 98 99 # gosh> (map-to char->integer "abc") (97 98 99) gosh> (for-each print (map-to char->integer "abc")) 97 98 99 # !2007-03-16 Fri String#dump 分からないので、とばし。 2007-03-11 の string-chomp を使って ; Ruby >> "abc\ndef\n".each {|x| p x } "abc\n" "def\n" => "abc\ndef\n" ; Gauche gosh> (use gauche.collection) # gosh> (for-each print (string-split (string-chomp "abc\ndef\n") #\newline)) abc def # !2007-03-15 Thu ; Ruby >> "ABC".downcase => "abc" ; Gauche gosh> (string-downcase "ABC") *** ERROR: unbound variable: string-downcase Stack Trace: _______________________________________ 0 (string-downcase "ABC") At line 1 of "(stdin)" 1 (string-downcase "ABC") At line 1 of "(stdin)" gosh> (use srfi-13) # gosh> (string-downcase "ABC") "abc" !2007-03-14 Wed ; Ruby >> "123456789".delete("2-8") => "19" >> "123456789".delete("2378") => "14569" ; Gauche gosh> (define (string-delete str pat) (define (include-pat? x) (char-set-contains? pat x)) (remove-to include-pat? (string->list str))) string-delete gosh> (string-delete "123456789" #[2-8]) "19" gosh> (string-delete "123456789" #[2378]) "14569" gosh> (string-delete "123456789" #\1) *** ERROR: char-set required, but got #\1 たまたま remove-to をみつけたのでこう書いてみたが、 他にもっと書き方はありそう。 ちゅーか、 gosh> (use srfi-13) # gosh> (string-delete "123456789" #[2-8]) "19" gosh> (string-delete "123456789" #[2378]) "14569" gosh> (string-delete "123456789" #\1) "23456789" で良かった… !2007-03-13 Tue ; Ruby >> "abc abc abc".count("a") => 3 >> "abc abc abc".count("") => 0 >> "abc abc abc".count("abc") => 9 >> "abc abc abc".count("a-c") => 9 ; Gauche gosh> (use srfi-13) # gosh> (string-count "abc abc abc" #\a) 3 gosh> (string-count "abc abc abc" #\null) 0 gosh> (string-count "abc abc abc" #[abc]) 9 gosh> (string-count "abc abc abc" #[a-c]) 9 同じ? !2007-03-12 Mon ; Ruby >> str = "abc" => "abc" >> str.id (irb):2: warning: Object#id will be deprecated; use Object#object_id => 538366510 >> str.object_id => 538366510 >> str.clone => "abc" >> str.clone.object_id => 538336170 >> str.dup => "abc" >> str.dup.object_id => 538600562 ; Gauche gosh> (define str "abc") str gosh> (define str2 (string-copy str)) str2 gosh> (eq? str str2) #f gosh> (string=? str str2) #t gosh> (eq? str (substring str 0 (string-length str))) #f gosh> (string=? str (substring str 0 (string-length str))) #t !2007-03-11 Sun ; Ruby >> "abc\ndef\n".chomp => "abc\ndef" >> "abcr\rdef\r".chomp => "abcr\rdef" >> "abcr\r\ndef\r\n".chomp => "abcr\r\ndef" >> "abcr\n\rdef\n\r".chomp => "abcr\n\rdef\n" ; Gauche gosh> (define (string-chomp str) (let* ((str-len (string-length str)) (str-len1 (- str-len 1)) (str-len2 (- str-len 2))) (if (= str-len 0) str (if (and (>= str-len 2) (string=? (substring str str-len2 str-len) "\r\n")) (substring str 0 str-len2) (if (and (>= str-len 1) (or (char=? (string-ref str str-len1) #\return) (char=? (string-ref str str-len1) #\newline))) (substring str 0 str-len1) str))))) string-chomp で、 gosh> (string-chomp "abc\ndef\n") "abc\ndef" gosh> (string-chomp "abcr\rdef\r") "abcr\rdef" gosh> (string-chomp "abcr\r\ndef\r\n") "abcr\r\ndef" gosh> (string-chomp "abcr\n\rdef\n\r") "abcr\n\rdef\n" gosh> (string-chomp "") "" gosh> (string-chomp "a") "a" gosh> (string-chomp "\n") "" gosh> (string-chomp "\r") "" gosh> (string-chomp "\r\n") "" gosh> (string-chomp "\n\r") "\n" gosh> (string-chomp "\n\n") "\n" gosh> (string-chomp "\r\r") "\r" * 2005-11-21 の python の別解は、連続していると消しすぎてしまう気が… * はじめ #\newline でなく #\n と書いてしまった… !2007-03-10 Sat ; Ruby >> "a".center(10, "*") => "****a*****" >> "a".center(11, "*") => "*****a*****" >> "ab".center(10, "*") => "****ab****" >> "ab".center(11, "*") => "****ab*****" >> "abcdef".center(6, "*") => "abcdef" >> "abcdef".center(5, "*") => "abcdef" ; Gauche gosh> (define (string-center str width . args) (let* ((str-len (string-length str)) (half-len (quotient (- width str-len) 2)) (pad (if (null? args) #\ (car args)))) (if (< str-len width) (string-append (make-string half-len pad) str (make-string (- width str-len half-len) pad)) str))) string-center gosh> (string-center "a" 10) " a " gosh> (string-center "a" 11) " a " gosh> (string-center "ab" 10) " ab " gosh> (string-center "ab" 11) " ab " gosh> (string-center "abcdef" 6) "abcdef" gosh> (string-center "abcdef" 5) "abcdef" gosh> (string-center "a" 10 #\*) "****a*****" gosh> (string-center "a" 11 #\*) "*****a*****" gosh> (string-center "ab" 10 #\*) "****ab****" gosh> (string-center "ab" 11 #\*) "****ab*****" gosh> (string-center "abcdef" 6 #\*) "abcdef" gosh> (string-center "abcdef" 5 #\*) "abcdef" !2007-03-09 Fri ; Ruby >> "a".rjust(10) => " a" >> "abc".rjust(3) => "abc" >> "abc".rjust(2) => "abc" >> "a".rjust(10, "*") => "*********a" >> "a".rjust(2, "*") => "*a" >> "abc".rjust(2, "*") => "abc" ; Gauche gosh> (define (string-rjust str width . args) (use srfi-13) (let ((str-len (string-length str))) (if (<= width str-len) str (if (null? args) (string-pad str width) (string-pad str width (car args)))))) string-rjust gosh> (string-rjust "a" 10) " a" gosh> (string-rjust "abc" 3) "abc" gosh> (string-rjust "abc" 2) "abc" gosh> (string-rjust "a" 10 #\*) "*********a" gosh> (string-rjust "abc" 2 #\*) "abc" !2007-03-08 Thu ; Ruby >> "a".ljust(10) => "a " >> "abc".ljust(3) => "abc" >> "abc".ljust(2) => "abc" >> "a".ljust(10, "*") => "a*********" >> "abc".ljust(2, "*") => "abc" ; Gauche gosh> (define (string-ljust str width . args) (use srfi-13) (let ((str-len (string-length str))) (if (<= width str-len) str (if (null? args) (string-pad-right str width) (string-pad-right str width (car args)))))) string-ljust gosh> (string-ljust "a" 10) "a " gosh> (string-ljust "abc" 3) "abc" gosh> (string-ljust "abc" 2) "abc" gosh> (string-ljust "a" 10 "*") *** ERROR: bad type of argument for char: "*" Stack Trace: _______________________________________ gosh> (string-ljust "a" 10 #\*) "a*********" gosh> (string-ljust "abc" 2 #\*) "abc" !2007-03-07 Wed ; Ruby >> "a".rjust(10) => " a" >> "abc".rjust(3) => "abc" ; Gauche gosh> (use srfi-13) # gosh> (string-pad "a" 10) " a" gosh> (string-pad "abc" 3) "abc" gosh> (string-pad "abc" 2) "bc" !2007-03-06 Tue ; Ruby >> "a".ljust(10) => "a " >> "abc".ljust(3) => "abc" >> "abc".ljust(2) => "abc" ; Gauche gosh> (use srfi-13) # gosh> (string-pad-right "a" 10) "a " gosh> (string-pad-right "abc" 3) "abc" gosh> (string-pad-right "abc" 2) "ab" うけっ切れちゃうよ !2007-03-05 Mon ; Ruby >> "a".center(10) => " a " >> "a".center(11) => " a " >> "ab".center(10) => " ab " >> "ab".center(11) => " ab " >> "abcdef".center(6) => "abcdef" ; Gauche gosh> (use srfi-13) # gosh> (define (string-center str width) (let* ((str-len (string-length str)) (half-len (quotient (- width str-len) 2))) (if (< str-len width) (string-append (make-string half-len #\ ) str (make-string (- width str-len half-len) #\ )) str))) string-center gosh> (string-center "a" 10) " a " gosh> (string-center "a" 11) " a " gosh> (string-center "ab" 10) " ab " gosh> (string-center "ab" 11) " ab " gosh> (string-center "abcdef" 6) "abcdef" !2007-03-04 Sun ; Ruby >> "a".casecmp("A") => 0 >> "a".casecmp("B") => -1 >> "b".casecmp("A") => 1 ; Gauche gosh> (define (string-casecmp x y) (cond ((string-ci=? x y) 0) ((string-ci>? x y) 1) (#t -1))) string-casecmp gosh> (string-casecmp "a" "A") 0 gosh> (string-casecmp "a" "B") -1 gosh> (string-casecmp "b" "A") 1 !2007-03-03 Sat ; Ruby >> "abc".capitalize => "Abc" >> "ABC".capitalize => "Abc" ; Gauche gosh> (string-titlecase "abc") "Abc" gosh> (string-titlecase "ABC") "Abc" !2007-03-02 Fri ; Ruby >> "A" <=> "A" => 0 >> "A" <=> "B" => -1 >> "B" <=> "A" => 1 ; Gauche gosh> (define (string-cmp x y) (cond ((string=? x y) 0) ((string>? x y) 1) (#t -1))) string-cmp gosh> (string-cmp "A" "A") 0 gosh> (string-cmp "A" "B") -1 gosh> (string-cmp "B" "A") 1 * srfi-13 の string-compare は意味が違うみたい * マニュアルの「string-compare s1 s2 proc< proc= proc> &optional start1 end1 start2 end2」は正しいのだろうか? !2007-03-01 Thu ; Ruby >> str = "abc" => "abc" >> str[0...0] = "A" => "A" >> str => "Aabc" >> str[0...1] = "B" => "B" >> str => "Babc" ; Gauche gosh> (use srfi-13) # gosh> (define str "abc") str gosh> (string-replace str "A" 0 0) "Aabc" gosh> (string-replace str "A" 0 1) "Abc" !2007-02-28 Wed self[substr]=val, self[regexp]=val あたりとばし。 ; Ruby >> str = "abc" => "abc" >> str[0..0] = "A" => "A" >> str => "Abc" >> str[0..1] = "AB" => "AB" >> str => "ABc" ; Gauche gosh> (use srfi-13) # gosh> (define str "abc") str gosh> (string-replace str "A" 0 1) "Abc" gosh> str "abc" gosh> (string-replace str "AB" 0 2) "ABc" !2007-02-27 Tue ; Ruby >> str = "abc" => "abc" >> str[0, 0] = "A" => "A" >> str => "Aabc" >> str[0, 1] = "a" => "a" >> str => "aabc" >> str[0, 2] = "A" => "A" >> str => "Abc" ; Gauche gosh> (use srfi-13) # gosh> (define str "abc") str gosh> (string-replace str "A" 0 0) "Aabc" gosh> str "abc" gosh> (string-replace str "A" 0 1) "Abc" gosh> (string-replace str "A" 0 2) "Ac" 文字列長が変わるような破壊的なのは無理なのかな? !2007-02-26 Mon ; Ruby >> str = "abc" => "abc" >> str[0] = "A" => "A" >> str => "Abc" >> str[3] = "D" IndexError: index 3 out of string from (irb):4:in `[]=' from (irb):4 ; Gauche gosh> (define str "abc") str gosh> (string-set! str 0 #\A) *** ERROR: attempted to modify immutable string: "abc" むむむ。昔からこの挙動が理解できていない。 char *p = "abc"; と char abc[] = "abc"; と同じような関係なのか??? gosh> (define str (string-copy "abc")) str gosh> (string-set! str 0 #\A) # gosh> str "Abc" うむー gosh> (class-of "abc") #> gosh> (class-of (string-copy "abc")) #> うむー gosh> (string-immutable? "abc") #t gosh> (string-immutable? (string-copy "abc")) #f make-string や string の仕様自体も何か使いにくくないか?と思ってしまうんだな〜 !2007-02-25 Sun ; Ruby >> "abc"[0...0] => "" >> "abc"[0...1] => "a" >> "abc"[1...1] => "" >> "abc"[1...2] => "b" >> "abc"[1...0] => "" ; Gauche gosh> (substring "abc" 0 0) "" gosh> (substring "abc" 0 1) "a" gosh> (substring "abc" 1 1) "" gosh> (substring "abc" 1 2) "b" !2007-02-24 Sat ; Ruby >> "abc"[0..0] => "a" >> "abc"[0..1] => "ab" >> "abc"[1..1] => "b" >> "abc"[1..2] => "bc" >> "abc"[1..0] => "" ; Gauche gosh> (substring "abc" 0 0) "" gosh> (substring "abc" 0 1) "a" gosh> (substring "abc" 0 2) "ab" gosh> (substring "abc" 1 2) "b" gosh> (substring "abc" 1 3) "bc" gosh> (substring "abc" 1 0) *** ERROR: end argument must be equal to or greater than the start argument: start=1, end=0 * 終端を含む含まないが違うのか〜 * むしろ str[n...m] に近いのか !2007-02-23 Fri ; Ruby >> "foobar"["foo"] => "foo" >> "foobar"["FOO"] => nil ; Gauche gosh> (define (string-substr-ref str substr) (if (not (string-scan str substr)) #f (string-copy substr))) string-substr-ref gosh> (string-substr-ref "foobar" "foo") "foo" gosh> (string-substr-ref "foobar" "FOO") #f !2007-02-22 Thu ; Ruby >> "abc"[0,0] => "" >> "abc"[0,1] => "a" >> "abc"[0,2] => "ab" >> "abc"[0,3] => "abc" >> "abc"[0,4] => "abc" >> "abc"[-1,1] => "c" >> "abc"[-1,2] => "c" ; Gauche gosh> (substring "abc" 0 0) "" gosh> (substring "abc" 0 1) "a" gosh> (substring "abc" 0 2) "ab" gosh> (substring "abc" 0 3) "abc" gosh> (substring "abc" 0 4) *** ERROR: end argument is out of range: 4 Stack Trace: _______________________________________ 0 (substring "abc" 0 4) At line 5 of "(stdin)" 1 (substring "abc" 0 4) At line 5 of "(stdin)" gosh> (define (string-substring-len str nth len) (if (< (+ nth len) (string-length str)) (substring str nth (+ nth len)) (substring str nth (string-length str)))) string-substring-len gosh> (string-substring-len "abc" 0 0) "" gosh> (string-substring-len "abc" 0 1) "a" gosh> (string-substring-len "abc" 0 2) "ab" gosh> (string-substring-len "abc" 0 3) "abc" gosh> (string-substring-len "abc" 0 4) "abc" gosh> (string-substring-len "abc" 1 1) "b" gosh> (string-substring-len "abc" 1 2) "bc" gosh> (string-substring-len "abc" 1 3) "bc" gosh> (string-substring-len "abc" 1 4) "bc" エラー処理的には全然足りないけど… !2007-02-21 Wed ; Ruby >> "abc"[0] => 97 >> "abc"[-1] => 99 >> "abc"[3] => nil >> "abc"[-4] => nil ; Gauche gosh> (substring "abc" 0 0) "" gosh> (substring "abc" 0 1) "a" gosh> (substring "abc" -1 1) *** ERROR: start argument needs to be positive: -1 Stack Trace: _______________________________________ 0 (substring "abc" -1 1) At line 3 of "(stdin)" 1 (substring "abc" -1 1) At line 3 of "(stdin)" gosh> (string-ref "abc" 0) #\a gosh> (string-ref "abc" -1) *** ERROR: argument out of range: -1 !2007-02-20 Tue ; Ruby >> "abd" > "abc" => true >> "abc" >= "abc" => true >> "abd" < "abc" => false >> "abc" <= "abc" => true ; Gauche gosh> (string>? "abd" "abc") #t gosh> (string>=? "abc" "abc") #t gosh> (string (string<=? "abc" "abc") #t !2007-02-19 Mon ; Ruby >> "abc" == "abc" => true >> "abc" != "abc" => false ; Gauche gosh> (string=? "abc" "abc") #t gosh> (not (string=? "abc" "abc")) #f !2007-02-18 Sun ; Ruby >> "%02d" % 1 => "01" >> "%02x" % 10 => "0a" >> "%s" % 10 => "10" >> "%f" % 1 => "1.000000" ; Gauche gosh> (format "~2,'0d" 1) "01" gosh> (format "~2,'0x" 10) "0a" gosh> (format "~S" 10) "10" gosh> (format "~f" 1) *** ERROR: too many arguments for format string: "~f" うーむ、format の使い方って良く分かっていないなあ〜 !2007-02-17 Sat ; Ruby >> "hoge" * 3 => "hogehogehoge" >> "foo" * 0 => "" ; Gauche gosh> (define (string-times str n) (if (> n 0) (string-append str (string-times str (- n 1))) "")) string-times gosh> (string-times "hoge" 3) "hogehogehoge" gosh> (string-times "foo" 0) "" gosh> (string-times "あ" 3) "あああ" gosh> (use srfi-42) # gosh> (define (string-times str n) (fold-ec "" (: i n) str (lambda (x y) (string-append x y)))) string-times gosh> (string-times "hoge" 3) "hogehogehoge" gosh> (string-times "foo" 0) "" gosh> (string-times "あ" 3) "あああ" 「srfi-13 - 文字列ライブラリ」にも特にないようだ !2007-02-16 Fri ; Ruby >> "foo" + "bar" => "foobar" ; Gauche gosh> (string-append "foo" "bar") "foobar" !2007-02-15 Thu ; Ruby >> s = "foo" => "foo" >> s = 'foo' => "foo" >> s = < "foo\n" ; Gauche gosh> (define s "foo") s gosh> s "foo" gosh> (define s 'foo') *** READ-ERROR: Read error at "(stdin)":line 3: extra close parenthesis Stack Trace: _______________________________________ gosh> (define s "foo bar baz") s gosh> s "foo\nbar\nbaz" 文字列リテラルと組み込みライブラリの文字列は同じものを意味しているのか? !2007-02-14 Wed ; Ruby >> Math.log10(1) => 0.0 >> Math.log10(10) => 1.0 >> Math.log10(100) => 2.0 ; Gauche gosh> (define (log10 x) (/ (log x) (log 10))) log10 gosh> (log10 1) 0.0 gosh> (log10 10) 1.0 gosh> (log10 100) 2.0 !2007-02-13 Tue ; Ruby >> Math.ldexp(1,1) => 2.0 >> Math.ldexp(1,2) => 4.0 >> Math.ldexp(3,2) => 12.0 >> Math.ldexp(3,3) => 24.0 ; Gauche gosh> (* 1 (expt 2 1)) 2 gosh> (* 1 (expt 2 2)) 4 gosh> (* 3 (expt 2 2)) 12 gosh> (* 3 (expt 2 3)) 24 !2007-02-12 Mon ; Ruby >> Math.hypot(1, 1) => 1.4142135623731 >> Math.hypot(1, 2) => 2.23606797749979 ; Gauche gosh> (sqrt (+ (* 1 1) (* 1 1))) 1.4142135623730951 gosh> (sqrt (+ (* 1 1) (* 2 2))) 2.23606797749979 !2007-02-11 Sun sinh, cosh, tanh, asinh, acosh, atanh とかは、とばし。 関数名自体は同じ。 Gauche に Math.atan2(y, x) はないみたい。 ; Ruby >> Math.frexp(3.14) => [0.785, 2] ; Gauche gosh> (frexp 3.14) 0.785 2 !2007-02-10 Sat ; Ruby >> Math.sqrt(1) => 1.0 >> Math.sqrt(2) => 1.4142135623731 >> Math.sqrt(3) => 1.73205080756888 ; Gauche gosh> (sqrt 1) 1.0 gosh> (sqrt 2) 1.4142135623730951 gosh> (sqrt 3) 1.7320508075688772 !2007-02-09 Fri ; Ruby >> Math.log(1) => 0.0 >> Math.log(Math::E) => 1.0 ; Gauche gosh> (log 1) 0.0 gosh> (use math.const) # gosh> (log e) 1.0 !2007-02-08 Thu ; Ruby >> Math.exp(1) => 2.71828182845905 ; Gauche gosh> (exp 1) 2.718281828459045 !2007-02-07 Wed ; Ruby >> Math.tan(0) => 0.0 >> Math.tan(Math::PI/4) => 1.0 >> Math.tan(Math::PI/2) => 1.63317787283838e+16 >> Math.atan(0) => 0.0 >> Math.atan(1) => 0.785398163397448 >> Math.atan(-1) => -0.785398163397448 ; Gauche gosh> (tan 0) 0.0 gosh> (use math.const) # gosh> (tan pi/4) 0.9999999999999999 gosh> (tan pi/2) 1.6331778728383844e16 gosh> (atan 0) 0.0 gosh> (atan 1) 0.7853981633974483 gosh> (atan -1) -0.7853981633974483 !2007-02-06 Tue ; Ruby >> Math.sin(0) => 0.0 >> Math.sin(Math::PI/2) => 1.0 >> Math.asin(0) => 0.0 >> Math.asin(1) => 1.5707963267949 ; Gauche gosh> (sin 0) 0.0 gosh> (use math.const) # gosh> (sin pi/2) 1.0 gosh> (asin 0) 0.0 gosh> (asin 1) 1.5707963267948966 !2007-02-05 Mon ; Ruby >> Math.cos(0) => 1.0 >> Math.cos(Math::PI/2) => 6.12303176911189e-17 >> Math.acos(1) => 0.0 >> Math.acos(0) => 1.5707963267949 >> Math.acos(2) Errno::EDOM: Numerical argument out of domain - acos ; Gauche gosh> (cos 0) 1.0 gosh> (use math.const) # gosh> (cos pi/2) 6.123031769111886e-17 gosh> (acos 1) 0.0 gosh> (acos 0) 1.5707963267948966 gosh> (acos 2) 0.0+1.3169578969248166i !2007-02-04 Sun ; Ruby >> Math::PI => 3.14159265358979 ; Gauche gosh> (use math.const) # gosh> pi 3.141592653589793 gosh> pi/2 1.5707963267948966 gosh> pi/4 0.7853981633974483 gosh> pi/180 0.017453292519943295 gosh> 1/pi 0.3183098861837907 gosh> 180/pi 57.29577951308232 !2007-02-03 Sat ; Ruby >> Math::E => 2.71828182845905 ; Gauche gosh> (use math.const) # gosh> e 2.718281828459045 !2007-02-02 Fri ; Ruby >> 0/0 ZeroDivisionError: divided by 0 from (irb):1:in `/' from (irb):1 >> 0/0.0 => NaN >> 0.0/0 => NaN >> 0.0/0.0 => NaN >> (0/0.0).nan? => true >> 1.nan? NoMethodError: undefined method `nan?' for 1:Fixnum from (irb):6 >> 1.2.nan? => false http://karetta.jp/article/blog/oneline/008039 によると eqv? で比較しろということなんだけど… ; Gauche gosh> (/ 0 0) # gosh> (/ 0 0.0) # gosh> (/ 0.0 0) # gosh> (/ 0.0 0.0) # gosh> (number? (/ 0 0)) #t gosh> (inexact? (/ 0 0)) #t gosh> (eqv? (/ 0 0) (/ 0 0)) #t gosh> (/ 1.0 0) #i1/0 gosh> (eqv? (/ 1.0 0) (/ 0 0)) #t !2007-02-01 Thu ; Ruby >> 1.0.infinite? => nil >> 1.0/0 => Infinity >> (1.0/0).infinite? => 1 >> -1.0/0 => -Infinity >> (-1.0/0).infinite? => -1 >> (0.0/0.0).infinite? => nil >> (-0.0/0.0).infinite? => nil ; Gauche gosh> (eqv? (/ 1.0 0) (/ 0 0)) #t gosh> (= (/ 1.0 0) (/ 0 0)) #f ? gosh> (/ 1.0 0) #i1/0 gosh> (/ 0 0) # うーん、ややこしい。 とりあえず、 (define (infinite? x) (cond ((= x (/ 1 0)) 1) ((= x (/ -1 0)) -1) (#t #f))) ではダメ… gosh> (define (infinite? x) (cond ((eqv? x (/ 0 0)) #f) ((= x (/ 1 0)) 1) ((= x (/ -1 0)) -1) (#t #f))) infinite? gosh> (infinite? 1) #f gosh> (infinite? (/ 1.0 0)) #f gosh> (infinite? (/ -1.0 0)) #f !2007-01-31 Wed ; Ruby >> 1.finite? NoMethodError: undefined method `finite?' for 1:Fixnum from (irb):1 >> 1.0.finite? => true >> 1.0/0 => Infinity >> (1.0/0).finite? => false >> -1.0/0 => -Infinity >> (-1.0/0).finite? => false >> Math.log(-1) Errno::EDOM: Numerical argument out of domain - log from (irb):7:in `log' from (irb):7 >> Math.sqrt(-1) Errno::EDOM: Numerical argument out of domain - sqrt from (irb):8:in `sqrt' from (irb):8 うーむ、上の二つは昔は NaN だったのになあ〜 >> 0/0 ZeroDivisionError: divided by 0 from (irb):9:in `/' from (irb):9 >> 0.0/0.0 => NaN >> 0.0/0 => NaN >> 0/0.0 => NaN >> (0.0/0.0).finite? => false >> (0.0/0).finite? => false >> (0/0.0).finite? => false 良く分からないので調べてみたら、 http://karetta.jp/article/blog/oneline/008037 がひっかかった ; Gauche gosh> (/ 1.0 0) #i1/0 gosh> (= (/ 1 0) (/ 1 0)) #t gosh> (= (/ 1.0 0) (/ 1 0)) #t gosh> (/ -1.0 0) #i-1/0 gosh> (= (/ -1.0 0) (/ 1 0)) #f う、(/ 1 0) と比較するだけじゃダメなのでは? gosh> (log -1) 0.0+3.141592653589793i gosh> (sqrt -1) 0.0+1.0i gosh> (/ 0 0) # gosh> (/ 0.0 0.0) # gosh> (/ 0.0 0) # gosh> (/ 0 0.0) # (= 1 (/ 0 0)) #t あれ? 調べてみたら http://karetta.jp/article/blog/oneline/008039 がひっかかった gosh> (eqv? 1 (/ 0 0)) #f gosh> (define (finite? x) (not (or (= x (/ 1 0)) (= x (/ -1 0)) (eqv? x (/ 0 0))))) finite? gosh> (finite? 1) #t gosh> (finite? (/ 1.0 0)) #f gosh> (finite? (/ -1.0 0)) #f gosh> (finite? (/ 0 0)) #f 多少不安が残るな〜 !2007-01-30 Tue ; Ruby >> :foo.to_i.id2name => "foo" ; Gauche そもそも :foo.to_i に相当するものがあるのか? gosh> (symbol->string 'foo) "foo" はできるけど。。。 !2007-01-29 Mon ; Ruby >> 1.upto(3) {|n| p n} 1 2 3 => 1 ; Gauche gosh> (use gauche.collection) # gosh> (use srfi-42) # gosh> (define (integer-upto n max proc) (for-each proc (list-ec (:range x n (+ max 1)) x))) integer-upto gosh> (integer-upto 1 3 print) 1 2 3 # !2007-01-28 Sun ; Ruby >> 10.to_s => "10" >> 1.2.to_s => "1.2" >> 10.to_s(2) => "1010" >> 10.to_s(8) => "12" >> 10.to_s(16) => "a" >> 35.to_s(36) => "z" ; Gauche gosh> (number->string 10) "10" gosh> (number->string 1.2) "1.2" gosh> (number->string 10 2) "1010" gosh> (number->string 10 8) "12" gosh> (number->string 10 16) "a" gosh> (number->string 35 36) "z" gosh> (x->string 10) "10" gosh> (x->string 1.2) "1.2" gosh> (x->string 10 2) *** ERROR: no applicable method for #string (5)> with arguments (10 2) !2007-01-27 Sat ; Ruby >> 1.to_f => 1.0 ; Gauche gosh> 1 1 gosh> (+ 1 0.0) 1.0 gosh> (exact->inexact 1) 1.0 良く分からない。姑息な手段を考えてみたが…。 !2007-01-26 Fri ; Ruby >> 1.size => 4 ; Gauche あるのか? !2007-01-25 Thu ; Ruby >> 3.times {|n| p n} 0 1 2 => 3 ; Gauche gosh> (use gauche.collection) # gosh> (use srfi-42) # gosh> (define (integer-times n proc) (for-each proc (list-ec (:range x 0 n) x))) integer-times gosh> (integer-times 3 print) 0 1 2 # こんな大げさでなく(外部ライブラリ使わなくても) もっと簡単に書けそうな気もするのだが、、、 gosh> (define (integer-times n proc) (define (integer-times-iter i n proc) (if (< i n) (begin (proc i) (integer-times-iter (+ i 1) n proc)))) (integer-times-iter 0 n proc)) integer-times gosh> (integer-times 3 print) 0 1 2 # * 長くなってしまった… * progn ないのか (^_^; !2007-01-24 Wed ; Ruby >> 1.succ => 2 >> 1.next => 2 ; Gauche gosh> (define (integer-succ x) (+ x 1)) integer-succ gosh> (integer-succ 1) 2 !2007-01-23 Tue ; Ruby >> 3.downto(1) {|n| p n} 3 2 1 => 3 ; Gauche gosh> (use gauche.collection) # gosh> (use srfi-42) # gosh> (define (integer-downto n min proc) (for-each proc (list-ec (:range x n (- min 1) -1) x))) integer-downto gosh> (integer-downto 3 1 print) 3 2 1 # !2007-01-22 Mon ; Ruby >> 65.chr => "A" ; Gauche gosh> (integer->char 65) #\A gosh> (string (integer->char 65)) "A" gosh> (make-byte-string 1 65) #*"A" make-byte-string は、なんか違いそう !2007-01-21 Sun ; Ruby >> 8 >> 3 => 1 >> 1 >> -3 => 8 >> -1 >> 3 => -1 >> -2 >> 3 => -1 >> -1 >> 32 => -1 >> -1 >> 33 => -1 ; Gauche gosh> (ash 8 -3) 1 gosh> (ash 1 3) 8 gosh> (ash -1 -3) -1 gosh> (ash -2 -3) -1 gosh> (ash -1 -32) -1 gosh> (ash -1 -33) -1 !2007-01-20 Sat ; Ruby >> 1 << 3 => 8 >> 8 << -3 => 1 >> -1 << 1 => -2 >> -1 << -1 => -1 >> -2 << -1 => -1 >> 1 << 32 => 4294967296 >> 1 << 33 => 8589934592 ; Gauche gosh> (ash 1 3) 8 gosh> (ash 8 -3) 1 gosh> (ash -1 1) -2 gosh> (ash -1 -1) -1 gosh> (ash -2 -1) -1 gosh> (ash 1 32) 4294967296 gosh> (ash 1 33) 8589934592 !2007-01-19 Fri ; Ruby >> 0xc | 0x3 => 15 >> 0xc & 0x3 => 0 >> 0xf & 0x3 => 3 >> 0xc ^ 0x3 => 15 >> 0xf ^ 0x3 => 12 ; Gauche gosh> (logior #xc #x3) 15 gosh> (logand #xc #x3) 0 gosh> (logand #xf #x3) 3 gosh> (logxor #xc #x3) 15 gosh> (logxor #xf #x3) 12 logior だから logiand かとかと思っちゃったよ… !2007-01-18 Thu ; Ruby >> ~1 => -2 >> ~3 => -4 >> "%b" % ~1 => "..10" >> "%b" % ~3 => "..100" >> ~(-2) => 1 >> ~(-4) => 3 ; Gauche gosh> (lognot 1) -2 gosh> (lognot 3) -4 gosh> (lognot -2) 1 gosh> (lognot -4) 3 !2007-01-17 Wed ; Ruby >> 2 > 1 => true >> 2.2 > 1 => true >> 1 >= 1 => true >> 1 <= 1 => true >> 1 < 1 => false ; Gauche gosh> (> 2 1) #t gosh> (> 2.2 1) #t gosh> (>= 1 1) #t gosh> (<= 1 1) #t gosh> (< 1 1) #f !2007-01-16 Tue ; Ruby >> 1 == 1 => true >> 1 == 1.0 => true >> 1 == 2 => false >> 1 != 2 => true >> 1 == 1.2 => false >> 1.2 == 1 => false ; Gauche gosh> (= 1 1) #t gosh> (= 1 1.0) #t gosh> (= 1 2) #f gosh> (not (= 1 2)) #t gosh> (= 1 1.2) #f gosh> (= 1.2 1) #f あれ?「!=」みたいないの??? !2007-01-15 Mon ; Ruby >> 2 <=> 1 => 1 >> 1 <=> 2 => -1 >> 1 <=> 1 => 0 >> 2.2 <=> 1.2 => 1 ; Gauche gosh> (define (cmp x y) (cond ((> x y) 1) ((< x y) -1) (#t 0))) cmp gosh> (cmp 2 1) 1 gosh> (cmp 1 2) -1 gosh> (cmp 1 1) 0 gosh> (cmp 2.2 1.2) 1 !2007-01-14 Sun ; Ruby >> 2 ** 3 => 8 >> 2.2 ** 3 => 10.648 >> 2 ** 3.2 => 9.18958683997628 ; Gauche gosh> (expt 2 3) 8 gosh> (expt 2.2 3) 10.648000000000003 gosh> (expt 2 3.2) 9.18958683997628 冪ってないんだっけ?と思ったら、あった。pow* じゃないのか !2007-01-13 Sat ; Ruby >> 2 * 3 => 6 >> 2 / 3 => 0 >> 10 / 3 => 3 >> -10 / 3 => -4 >> 2 * 3.0 => 6.0 >> 10 / 3.0 => 3.33333333333333 >> -10 / 3.0 => -3.33333333333333 ; Gauche gosh> (* 2 3) 6 gosh> (/ 2 3) 2/3 gosh> (/ 10 3) 10/3 gosh> (/ -10 3) -10/3 gosh> (* 2 3.0) 6.0 gosh> (/ 10 3.0) 3.3333333333333335 gosh> (/ -10 3.0) -3.3333333333333335 !2007-01-12 Fri ; Ruby >> 1 + 1 => 2 >> 1 - 1 => 0 >> 1.2 + 1 => 2.2 >> 1 + 1.2 => 2.2 >> 1.2 + 1.2 => 2.4 >> 1.0 + 1.0 => 2.0 ; Gauche gosh> (+ 1 1) 2 gosh> (- 1 1) 0 gosh> (+ 1.2 1) 2.2 gosh> (+ 1 1.2) 2.2 gosh> (+ 1.2 1.2) 2.4 gosh> (+ 1.0 1.0) 2.0 !2007-01-11 Thu ; Ruby >> 0xe[0] => 0 >> 0xe[1] => 1 >> 0xe[2] => 1 >> 0xe[3] => 1 ; Gauche gosh> (logbit? 0 #xe) #f gosh> (logbit? 1 #xe) #t gosh> (logbit? 2 #xe) #t gosh> (logbit? 3 #xe) #t !2007-01-10 Wed ; Ruby >> +1 => 1 >> -1 => -1 >> +1.2 => 1.2 >> -1.2 => -1.2 ; Gauche gosh> (+ 1) 1 gosh> (- 1) -1 gosh> (+ 1.2) 1.2 gosh> (- 1.2) -1.2 !2007-01-09 Tue ; Ruby >> 1.1.step(1.5, 0.1) {|n| p n} 1.1 1.2 1.3 1.4 1.5 => 1.1 ; Gauche gosh> (use gauche.collection) # gosh> (use srfi-42) # gosh> (define (real-step n limit step proc) (for-each proc (list-ec (:real-range x n (+ limit step) step) x))) real-step gosh> (real-step 1.1 1.5 0.1 print) 1.1 1.2000000000000002 1.3 1.4000000000000001 1.5 # !2007-01-08 Mon ; Ruby >> 1.step(5, 1) {|n| p n} 1 2 3 4 5 => 1 >> 1.step(5, 2) {|n| p n} 1 3 5 => 1 ; Gauche gosh> (use gauche.collection) # gosh> (use srfi-42) # gosh> (define (integer-step n limit step proc) (for-each proc (list-ec (:range x n (+ limit 1) step) x))) integer-step gosh> (integer-step 1 5 1 print) 1 2 3 4 5 # gosh> (integer-step 1 5 2 print) 1 3 5 # !2007-01-07 Sun ; Ruby >> 1.2.to_i => 1 >> 1.9.to_i => 1 >> 1.to_i => 1 ; Gauche gosh> (x->integer 1.2) 1 gosh> (x->integer 1.9) 2 ダメじゃん gosh> (x->integer 1) 1 gosh> (truncate 1.2) 1.0 gosh> (x->integer (truncate 1.9)) 1 これで良いのか??? !2007-01-06 Sat ; Ruby >> 0.nonzero? => nil >> 1.nonzero? => 1 >> 2.nonzero? => 2 >> 1.2.nonzero? => 1.2 >> 0.zero? => true >> 1.zero? => false >> 0.0.zero? => true ; Gauche gosh> (zero? 0) #t gosh> (zero? 0.0) #t gosh> (zero? 0.0+0.0i) #t gosh> (zero? 1) #f !2007-01-05 Fri ; Ruby >> 1.integer? => true >> 1.0.integer? => false >> true.integer? NoMethodError: undefined method `integer?' for true:TrueClass ; Gauche gosh> (number? 1) #t gosh> (number? 1.0) #t gosh> (number? #t) #f gosh> (integer? 1) #t gosh> (integer? 1.0) #t gosh> (integer? 1.2) #f gosh> (integer? #t) #f !2007-01-04 Thu ; Ruby まんま >> numbers=[[13,4], [13,-4], [-13,4],[-13,-4],[-13,-13], ?> [11.5,4], [11.5,-4], [-11.5,4], [-11.5,-4]] => [[13, 4], [13, -4], [-13, 4], [-13, -4], [-13, -13], [11.5, 4], [11.5, -4], [-11.5, 4], [-11.5, -4]] >> methods=%w[divmod / div quo % modulo remainder] => ["divmod", "/", "div", "quo", "%", "modulo", "remainder"] >> fmt = "%12s |" + " %12s" * methods.size + "\n" => "%12s | %12s %12s %12s %12s %12s %12s %12s\n" >> numbers.each do |a,b| ?> printf(fmt, [a,b].inspect, *methods.collect {|m| a.send(m, b).inspect}) >> end [13, 4] | [3, 1] 3 3 3.25 1 1 1 [13, -4] | [-4, -3] -4 -4 -3.25 -3 -3 1 [-13, 4] | [-4, 3] -4 -4 -3.25 3 3 -1 [-13, -4] | [3, -1] 3 3 3.25 -1 -1 -1 [-13, -13] | [1, 0] 1 1 1.0 0 0 0 [11.5, 4] | [2.0, 3.5] 2.875 2 2.875 3.5 3.5 3.5 [11.5, -4] | [-3.0, -0.5] -2.875 -2 -2.875 -0.5 -0.5 3.5 [-11.5, 4] | [-3.0, 0.5] -2.875 -2 -2.875 0.5 0.5 -3.5 [-11.5, -4] | [2.0, -3.5] 2.875 2 2.875 -3.5 -3.5 -3.5 => [[13, 4], [13, -4], [-13, 4], [-13, -4], [-13, -13], [11.5, 4], [11.5, -4], [-11.5, 4], [-11.5, -4]] ; Gauche gosh> (quotient 10.0 3) 3.0 gosh> (quotient 10.2 3) *** ERROR: integer required, but got 10.2 Stack Trace: _______________________________________ 0 (quotient 10.2 3) At line 2 of "(stdin)" 1 (quotient 10.2 3) At line 2 of "(stdin)" gosh> (remainder 10.2 3) *** ERROR: integer required, but got 10.2 Stack Trace: _______________________________________ 0 (remainder 10.2 3) At line 3 of "(stdin)" 1 (remainder 10.2 3) At line 3 of "(stdin)" gosh> (modulo 10.2 3) *** ERROR: integer required, but got 10.2 Stack Trace: _______________________________________ 0 (modulo 10.2 3) At line 4 of "(stdin)" 1 (modulo 10.2 3) At line 4 of "(stdin)" gosh> (define numbers '((13 4) (13 -4) (-13 4) (-13 -4) (-13 -13) (11.5 4) (11.5 -4) (-11.5 4) (-11.5 -4))) numbers gosh> (define integers '((13 4) (13 -4) (-13 4) (-13 -4) (-13 -13))) integers gosh> (for-each (lambda (x) (display (format #f "~8s" (/ (car x) (cadr x))))) numbers) 13/4 -13/4 -13/4 13/4 1 2.875 -2.875 -2.875 2.875 # gosh> (for-each (lambda (x) (display (format #f "~8s" (fmod (car x) (cadr x))))) numbers) 1.0 1.0 -1.0 -1.0 0.0 3.5 3.5 -3.5 -3.5 # gosh> (for-each (lambda (x) (display (format #f "~4s~8s" (values-ref (quotient&remainder (car x) (cadr x)) 0) (values-ref (quotient&remainder (car x) (cadr x)) 1)))) integers) 3 1 -3 1 -3 -1 3 -1 1 0 # gosh> (for-each (lambda (x) (display (format #f "~8s" (quotient (car x) (cadr x))))) integers) 3 -3 -3 3 1 # gosh> (for-each (lambda (x) (display (format #f "~8s" (remainder (car x) (cadr x))))) integers) 1 1 -1 -1 0 # gosh> (for-each (lambda (x) (display (format #f "~8s" (modulo (car x) (cadr x))))) integers) 1 -3 3 -1 0 # * 微妙に違うな〜 * quotient, remainder, quotient&remainder, modulo は整数しかダメらしい !2007-01-03 Wed ; Ruby >> 0.6.round => 1 >> 0.5.round => 1 >> 0.4.round => 0 >> -0.4.round => 0 >> -0.5.round => -1 >> -0.6.round => -1 ; Gauche gosh> (round 0.6) 1.0 gosh> (round 0.5) 0.0 gosh> (round 0.4) 0.0 gosh> (round -0.4) 0.0 gosh> (round -0.5) 0.0 gosh> (round -0.6) -1.0 微妙に違う〜 !2007-01-02 Tue ; Ruby >> 1.9.ceil => 2 >> 1.1.ceil => 2 >> -1.1.ceil => -1 >> -1.9.ceil => -1 >> 1.9.floor => 1 >> 1.1.floor => 1 >> -1.1.floor => -2 >> -1.9.floor => -2 >> 1.9.round => 2 >> 1.1.round => 1 >> -1.1.round => -1 >> -1.9.round => -2 >> 1.9.truncate => 1 >> 1.1.truncate => 1 >> -1.1.truncate => -1 >> -1.9.truncate => -1 ; Gauche gosh> (ceiling 1.9) 2.0 gosh> (ceiling 1.1) 2.0 gosh> (ceiling -1.1) -1.0 gosh> (ceiling -1.9) -1.0 gosh> (floor 1.9) 1.0 gosh> (floor 1.1) 1.0 gosh> (floor -1.1) -2.0 gosh> (floor -1.9) -2.0 gosh> (round 1.9) 2.0 gosh> (round 1.1) 1.0 gosh> (round -1.1) -1.0 gosh> (round -1.9) -2.0 gosh> (truncate 1.9) 1.0 gosh> (truncate 1.1) 1.0 gosh> (truncate -1.1) -1.0 gosh> (truncate -1.9) -1.0 !2007-01-01 Mon ; Ruby >> 1.9.ceil => 2 >> 1.ceil => 1 ; Gauche gosh> (ceiling 1.9) 2.0 gosh> (ceiling 1) 1 整数返していない気が‥ !2006-12-31 Sun ; Ruby >> -1.abs => 1 >> -1.2.abs => 1.2 >> - 1.2.abs => -1.2 ; Gauche gosh> (abs -1) 1 gosh> (abs -1.2) 1.2 !2006-12-30 Sat ; Ruby >> 1 == 1 => true >> 1 == "1" => false >> "1" == 1 => false >> 1 == 1.0 => true ; Gauche gosh> (= 1 1) #t gosh> (= 1 "1") *** ERROR: real number required: "1" Stack Trace: _______________________________________ 0 (= 1 "1") At line 2 of "(stdin)" 1 (= 1 "1") At line 2 of "(stdin)" gosh> (= "1" 1) *** ERROR: real number required: "1" Stack Trace: _______________________________________ 0 (= "1" 1) At line 3 of "(stdin)" 1 (= "1" 1) At line 3 of "(stdin)" gosh> (= 1 1.0) #t !2006-12-29 Fri ; Ruby >> -1 => -1 >> -1.0 => -1.0 >> - 1 => -1 >> - 1.0 => -1.0 ; Gauche gosh> (- 1) -1 gosh> (-1) *** ERROR: invalid application: (-1) Stack Trace: _______________________________________ 0 (-1) At line 2 of "(stdin)" 1 (-1) At line 2 of "(stdin)" gosh> (- 1.0) -1.0 !2006-12-28 Thu ; Ruby >> 1 + 1 => 2 >> 1 - 1 => 0 >> 2 * 3 => 6 >> 2 / 3 => 0 >> 2 / 3.0 => 0.666666666666667 >> 2.0 / 3 => 0.666666666666667 >> - 10 / 3 => -4 >> 1.2 + 1.3 => 2.5 ; Gauche gosh> (+ 1 1) 2 gosh> (- 1 1) 0 gosh> (* 2 3) 6 gosh> (/ 2 3) 2/3 gosh> (+ (/ 2 3)) 2/3 gosh> (+ (/ 2 3) 1) 5/3 gosh> (/ 2 3.0) 0.6666666666666666 gosh> (/ 2.0 3) 0.6666666666666666 gosh> (/ -10 3) -10/3 gosh> (/ -10 3.0) -3.3333333333333335 gosh> (+ 1.2 1.3) 2.5 !2006-12-27 Wed ; Ruby >> true == true => true >> true == false => false >> true == 1 => false >> true == 0 => false >> 1 & true TypeError: can't convert true into Integer from (irb):5:in `&' from (irb):5 >> true & 1 => true >> 1 && true => true >> true && 1 => 1 ; Gauche gosh> (= #t 1) *** ERROR: real number required: #t Stack Trace: _______________________________________ 0 (= #t 1) At line 1 of "(stdin)" 1 (= #t 1) At line 1 of "(stdin)" gosh> (eq? #t 1) #f gosh> (eq? #t 0) #f gosh> (and 1 #t) #t gosh> (and #t 1) 1 gosh> (= #t #t) *** ERROR: real number required: #t Stack Trace: _______________________________________ 0 (= #t #t) At line 6 of "(stdin)" 1 (= #t #t) At line 6 of "(stdin)" !2006-12-26 Tue ; Ruby >> not 1 => false >> not 0 => false >> not nil => true >> not false => true >> not "" (irb):5: warning: string literal in condition => false ; Gauche gosh> (boolean #f) #f gosh> (boolean #t) #t gosh> (boolean 1) #t gosh> (boolean 0) #t gosh> (boolean '()) #t gosh> (boolean "") #t gosh> (not 1) #f gosh> (not 0) #f gosh> (not '()) #f gosh> (not "") #f 「Ruby では false または nil だけが偽で、 それ以外は 0 や空文字列も含め全て真です。」 Scheme も同じような感じ? !2006-12-25 Mon ; Ruby >> !true => false >> not true => false >> true && true => true >> true & true => true >> true and true => true >> true || true => true >> true | true => true >> true or true => true >> true ^ true => false >> true ^ false => true ; Gauche gosh> (not #t) #f gosh> (not #f) #t gosh> (and #t #t) #t gosh> (and #t #t #t) #t gosh> (or #t #t) #t gosh> (or #t #t #t) #t xor はない??? !2006-12-24 Sun ; Ruby >> true.class => TrueClass >> false.class => FalseClass >> nil.class => NilClass >> true.instance_of?(TrueClass) => true >> true.is_a?(TrueClass) => true >> false.instance_of?(FalseClass) => true >> false.is_a?(FalseClass) => true ; Gauche gosh> #t #t gosh> #f #f gosh> (class-of #t) #> gosh> (class-of #f) #> gosh> (is-a? #t ) #t gosh> (is-a? #f ) #t gosh> (boolean? #t) #t gosh> (boolean? #f) #t !2006-12-23 Sat ほぼ、まんま gosh> (call-with-output-file "ruby-lang.html" (lambda (out) (http-get "www.ruby-lang.org" "/ja/index.html" :sink out :flusher (lambda _ #t)))) "200" (("date" "Thu, 04 Jan 2007 08:08:41 GMT") ("server" "Apache/2.0.54 (Debian GNU/Linux) mod_ssl/2.0.54 OpenSSL/0.9.7e") ("transfer-encoding" "chunked") ("content-type" "text/html;charset=utf-8")) #t http-post はとばし !2006-12-22 Fri gosh> (use rfc.http) # gosh> (http-head "www.ruby-lang.org" "/") "200" (("date" "Thu, 04 Jan 2007 08:07:07 GMT") ("server" "Apache/2.0.54 (Debian GNU/Linux) mod_ssl/2.0.54 OpenSSL/0.9.7e") ("content-type" "text/html;charset=utf-8")) #f !2006-12-21 Thu gosh> (use rfc.http) # gosh> (http-get "www.ruby-lang.org" "/index.html") "404" (("date" "Thu, 04 Jan 2007 08:02:51 GMT") ("server" "Apache/2.0.54 (Debian GNU/Linux) mod_ssl/2.0.54 OpenSSL/0.9.7e") ("transfer-encoding" "chunked") ("content-type" "text/html;charset=utf-8")) " (http-get "www.ruby-lang.org" "/ja/index.html") "200" (("date" "Thu, 04 Jan 2007 08:03:22 GMT") ("server" "Apache/2.0.54 (Debian GNU/Linux) mod_ssl/2.0.54 OpenSSL/0.9.7e") ("transfer-encoding" "chunked") ("content-type" "text/html;charset=utf-8")) #*" (http-get "www.ruby-lang.org" "/") "200" (("date" "Thu, 04 Jan 2007 08:05:17 GMT") ("server" "Apache/2.0.54 (Debian GNU/Linux) mod_ssl/2.0.54 OpenSSL/0.9.7e") ("transfer-encoding" "chunked") ("content-type" "text/html;charset=utf-8")) " (use text.diff) # gosh> (diff-report "a\nb\nc\nd\n" "b\ne\nd\nf\n") - a b - c + e d + f # !2006-12-19 Tue まんま gosh> (use text.diff) # gosh> (diff "a\nb\nc\nd\n" "b\ne\nd\nf\n") (((- 0 "a")) ((- 2 "c") (+ 1 "e")) ((+ 3 "f"))) !2006-12-18 Mon gosh> (use util.trie) # gosh> (define t (make-trie)) t gosh> (trie-put! t "foo" 3) # gosh> (trie-put! t "fooo" 4) # gosh> (trie-put! t "foooo" 5) # gosh> (trie-put! t "bar" 4) # gosh> (trie-map t (lambda (k v) v)) (3 4 5 4) gosh> (trie-for-each t (lambda (k v) (display v))) 4543# !2006-12-17 Sun gosh> (use util.trie) # gosh> (define t (make-trie)) t gosh> (trie-put! t "foo" 3) # gosh> (trie-put! t "fooo" 4) # gosh> (trie-put! t "foooo" 5) # gosh> (trie-put! t "bar" 4) # gosh> (trie-fold t (lambda (k v s) (+ 1 s)) 0) 4 gosh> (trie-fold t (lambda (k v s) (+ v s)) 0) 16 !2006-12-16 Sat gosh> (use util.trie) # gosh> (define t (make-trie)) t gosh> (trie-put! t "foo" 3) # gosh> (trie-put! t "fooo" 4) # gosh> (trie-put! t "foooo" 5) # gosh> (trie-put! t "bar" 4) # gosh> (trie-common-prefix-map t "f" (lambda (k v) v)) (3 4 5) gosh> (trie-common-prefix-for-each t "f" (lambda (k v) v)) # gosh> (trie-common-prefix-for-each t "f" (lambda (k v) (display v))) 543# !2006-12-15 Fri gosh> (use util.trie) # gosh> (define t (make-trie)) t gosh> (trie-put! t "foo" 3) # gosh> (trie-put! t "fooo" 4) # gosh> (trie-put! t "foooo" 5) # gosh> (trie-put! t "bar" 4) # gosh> (trie-common-prefix-fold t "f" (lambda (k v s) (+ 1 s)) 0) 3 gosh> (trie-common-prefix-fold t "f" (lambda (k v s) (+ v s)) 0) 12 !2006-12-14 Thu gosh> (use util.trie) # gosh> (define t (make-trie)) t gosh> (trie-put! t "foo" 3) # gosh> (trie-put! t '(#\f #\o #\o) 5) # gosh> (trie-num-entries t) 2 gosh> (trie-common-prefix t "f") (("foo" . 3) ((#\f #\o #\o) . 5)) !2006-12-13 Wed gosh> (use util.trie) # gosh> (define t (make-trie)) t gosh> (trie-put! t "foo" 3) # gosh> (trie-put! t "bar" 4) # gosh> (trie-put! t "baz" 5) # gosh> (trie-common-prefix-values t "b") (4 5) !2006-12-12 Tue gosh> (use util.trie) # gosh> (define t (make-trie)) t gosh> (trie-put! t "foo" 3) # gosh> (trie-put! t "bar" 4) # gosh> (trie-put! t "baz" 5) # gosh> (trie-common-prefix-keys t "b") ("bar" "baz") !2006-12-11 Mon gosh> (use util.trie) # gosh> (define t (make-trie)) t gosh> (trie-put! t "foo" 3) # gosh> (trie-put! t "bar" 4) # gosh> (trie-put! t "baz" 5) # gosh> (trie-common-prefix t "b") (("bar" . 4) ("baz" . 5)) gosh> (trie-common-prefix t "B") () !2006-12-10 Sun gosh> (use util.trie) # gosh> (define t (make-trie)) t gosh> (trie-put! t "foo" 3) # gosh> (trie-put! t "bar" 4) # gosh> (define ht (trie->hash-table t 'eq?)) ht gosh> (hash-table-num-entries ht) 2 gosh> (hash-table-get ht "foo") *** ERROR: hash table doesn't have an entry for key "foo" Stack Trace: _______________________________________ 0 (hash-table-get ht "foo") At line 7 of "(stdin)" 1 (hash-table-get ht "foo") At line 7 of "(stdin)" gosh> (hash-table-keys ht) ("bar" "foo") gosh> (define ht (trie->hash-table t 'string=?)) ht gosh> (hash-table-get ht "foo") 3 !2006-12-09 Sat gosh> (use util.trie) # gosh> (define t (make-trie)) t gosh> (trie-keys t) () gosh> (trie-values t) () gosh> (trie-put! t "foo" 3) # gosh> (trie-put! t "bar" 4) # gosh> (trie-keys t) ("foo" "bar") gosh> (trie-values t) (3 4) !2006-12-08 Fri gosh> (use util.trie) # gosh> (define t (make-trie)) t gosh> (trie->list t) () gosh> (trie-put! t "foo" 3) # gosh> (trie-put! t "bar" 4) # gosh> (trie->list t) (("foo" . 3) ("bar" . 4)) !2006-12-07 Thu gosh> (use util.trie) # gosh> (define t (make-trie)) t gosh> (trie-delete! t "foo") # gosh> (trie-put! t "foo" 3) # gosh> (trie-get t "foo") 3 gosh> (trie-delete! t "foo") # gosh> (trie-get t "foo") *** ERROR: Trie does not have an entry for a key: "foo" !2006-12-06 Wed gosh> (use util.trie) # gosh> (define t (make-trie)) t gosh> (trie-put! t "foo" 3) # gosh> (trie-update! t "foo" (lambda (x) (+ x 1))) # gosh> (trie-get t "foo") 4 gosh> (trie-update! t "bar" (lambda (x) (+ x 1)) 5) # gosh> (trie-get t "bar") 6 !2006-12-05 Tue gosh> (use util.trie) # gosh> (define t (make-trie)) t gosh> (trie-put! t "foo" 3) # gosh> (trie-get t "foo") 3 gosh> (trie-get t "bar") *** ERROR: Trie does not have an entry for a key: "bar" Stack Trace: _______________________________________ gosh> (trie-get t "bar" 10) 10 !2006-12-04 Mon gosh> (use util.trie) # gosh> (define t (make-trie)) t gosh> (trie-exists? t "foo") #f gosh> (trie-put! t "foo" 3) # gosh> (trie-exists? t "foo") #t !2006-12-03 Sun gosh> (use util.trie) # gosh> (define t (make-trie)) t gosh> (trie-num-entries t) 0 gosh> (trie-put! t "pho" 3) # gosh> (trie-num-entries t) 1 !2006-12-02 Sat gosh> (use util.trie) # gosh> (trie? (make-trie)) #t gosh> (trie? #t) #f !2006-12-01 Fri まあ、まんま gosh> (use util.trie) # gosh> (define t (trie-with-keys '() "foo" "bar")) t gosh> (trie-get t "foo") "foo" gosh> (trie-get t "bar") "bar" !2006-11-30 Thu まあ、まんま gosh> (use util.trie) # gosh> (define t (trie '() '("foo" . a) '("bar" . b))) t gosh> (trie-get t "foo") a gosh> (trie-get t "bar") b gosh> (trie-get t "baz") *** ERROR: Trie does not have an entry for a key: "baz" !2006-11-29 Wed まんま gosh> (use util.trie) # gosh> (use util.list) # gosh> (define t (make-trie list (cut assoc-ref <> <> #f char-ci=?) (lambda (t k v) (if v (assoc-set! t k v char-ci=?) (alist-delete! k t char-ci=?))) (lambda (t f s) (fold f s t)))) t gosh> (trie-put! t "pho" 3) # gosh> (trie-get t "pho") 3 gosh> (trie-get t "PHO") 3 gosh> (trie-put! t "PHO" 5) # gosh> (trie-get t "pho") 5 !2006-11-28 Tue まんま gosh> (use util.trie) # gosh> (define t (make-trie (lambda () (make-hash-table 'eqv?)) (lambda (tab k) (hash-table-get tab k #f)) (lambda (tab k v) (if v (hash-table-put! tab k v) (hash-table-delete! tab k)) tab) hash-table-fold)) t gosh> (trie-put! t "pho" 3) # gosh> (trie-get t "pho") 3 !2006-11-27 Mon gosh> (use util.trie) # gosh> (define t (make-trie)) t gosh> (trie-put! t '(#\p #\h #\o) 8) # gosh> (trie-put! t "pho" 3) # gosh> (trie-get t "pho") 3 gosh> (trie-get t "phone") *** ERROR: Trie does not have an entry for a key: "phone" Stack Trace: _______________________________________ gosh> (trie-get t '(#\p #\h #\o)) 8 !2006-11-26 Sun 0.8.8 にバージョンアップ ほぼ、まんま gosh> (use util.trie) # gosh> #> gosh> (make-trie) #< 0x8148020> gosh> (define t (make-trie)) t gosh> (trie-put! t "pho" 3) # gosh> (trie-put! t "phone" 5) # gosh> (trie-put! t "phrase" 6) # gosh> (trie-get t "phone") 5 gosh> (trie-put! t "phone" 10) # gosh> (trie-get t "phone") 10 !2006-11-25 Sat gosh> (use gauche.process) # gosh> (process-output->string-list "ls .emacs*") (".emacs" ".emacs-color.el" ".emacs-faces.el" ".emacs-fontset.el" ".emacs.el" ".emacs.el~" ".emacs.my.el" ".emacs.my.el~" "" ".emacs.d:" "auto-save-list") !2006-11-24 Fri gosh> (use gauche.process) # gosh> (process-output->string "uname -smp") "Linux i686 unknown" gosh> (process-output->string "ls .emacs*") ".emacs .emacs-color.el .emacs-faces.el .emacs-fontset.el .emacs.el .emacs.el~ .emacs.my.el .emacs.my.el~ .emacs.d: auto-save-list" !2006-11-23 Thu gosh> (use gauche.process) # gosh> (call-with-process-io "ls -l .emacs" (lambda (in out) (display in out))) # !2006-11-22 Wed gosh> (use gauche.process) # gosh> (with-output-to-process "ls -l .emacs" (lambda () ())) () !2006-11-21 Tue gosh> (use gauche.process) # gosh> (call-with-output-process "ls -l .emacs" (lambda (out) (display out))) ## !2006-11-20 Mon gosh> (use gauche.process) # gosh> (open-output-process-port "ls -l .emacs") # # !2006-11-19 Sun ほぼ、まんま gosh> (use gauche.process) # gosh> (with-input-from-process "ls -l .emacs" read-line) "-rw-r--r-- 1 nori users 863 Mar 27 2005 .emacs" !2006-11-18 Sat ほぼ、まんま gosh> (use gauche.process) # gosh> (call-with-input-process "ls -l .emacs" (lambda (p) (read-line p))) "-rw-r--r-- 1 nori users 863 Mar 27 2005 .emacs" !2006-11-17 Fri まんま gosh> (use gauche.process) # gosh> (open-input-process-port "date 2>&1 1>/dev/null") # # !2006-11-16 Thu まんま gosh> (use gauche.process) # gosh> (open-input-process-port "date 2>&1") # # !2006-11-15 Wed ほぼ、まんま gosh> (use gauche.process) # gosh> (receive (port process) (open-input-process-port '(ls -l ".emacs")) (begin0 (read-line port) (process-wait process))) "-rw-r--r-- 1 nori users 863 Mar 27 2005 .emacs" !2006-11-14 Tue ほぼ、まんま gosh> (use gauche.process) # gosh> (receive (port process) (open-input-process-port "ls -l .emacs") (begin0 (read-line port) (process-wait process))) "-rw-r--r-- 1 nori users 863 Mar 27 2005 .emacs" !2006-11-13 Mon gosh> (use gauche.process) # gosh> (let ((process (run-process "echo" "-n"))) (process-continue process)) # !2006-11-12 Sun gosh> (use gauche.process) # gosh> (let ((process (run-process "echo" "-n"))) (process-stop process)) # !2006-11-11 Sat gosh> (use gauche.process) # gosh> (let ((process (run-process "echo" "-n"))) (process-kill process)) # gosh> (let ((process (run-process "date"))) (process-continue process)) # gosh> 2006年 11月 27日 月曜日 20:30:28 JST (let ((process (run-process "date"))) (process-kill process)) # !2006-11-10 Fri gosh> (use gauche.process) # gosh> (let ((process (run-process "echo" "-n"))) (process-send-signal process SIGKILL)) # !2006-11-09 Thu gosh> (use gauche.process) # gosh> (process-exit-status (run-process "echo" "-n")) #f gosh> (let ((process (run-process "echo" "-n"))) (process-wait process) (process-exit-status process)) 0 gosh> (let ((process (run-process "echo" "-n"))) (process-exit-status process)) #f !2006-11-08 Wed gosh> (use gauche.process) # gosh> (process-wait-any) # !2006-11-07 Tue gosh> (use gauche.process) # gosh> (process-wait (run-process "echo" "-n")) #t 何をするものか不明 !2006-11-06 Mon gosh> (use gauche.process) # gosh> (process-list) (# # #) !2006-11-05 Sun gosh> (use gauche.process) # gosh> (process-alive? (run-process "echo" "-n")) #t gosh> (let ((process (run-process "echo" "-n"))) (process-alive? process)) #t gosh> (process-alive? (run-process "echo" "-n" :wait #t)) #f !2006-11-04 Sat まんま gosh> (use gauche.process) # gosh> (let* ((process (run-process "date" :output :pipe)) (line (read-line (process-output process)))) (process-wait process) line) "2006年 11月 27日 月曜日 20:21:24 JST" !2006-11-03 Fri gosh> (use gauche.process) # gosh> (process-command (run-process "echo" "-n")) "echo" !2006-11-02 Thu gosh> (use gauche.process) # gosh> (process-pid (run-process "echo" "-n")) 27642 !2006-11-01 Wed 勘違いしていた〜。引数は別に与えないとダメだったようだ… gosh> (use gauche.process) # gosh> (run-process "ls .emacs") # exec failed: ls .emacs: No such file or directory gosh> (run-process "ls" ".emacs") # gosh> .emacs !2006-10-31 Tue gosh> (use gauche.process) # gosh> (process? (run-process "ls hoge")) #t gosh> exec failed: ls hoge: No such file or directory (is-a? (run-process "ls hoge") ) #t gosh> exec failed: ls hoge: No such file or directory !2006-10-30 Mon gosh> (use gauche.process) # gosh> (run-process "ls hoge") # exec failed: ls hoge: No such file or directory !2006-10-29 Sun gosh> (use gauche.process) # gosh> #> !2006-10-28 Sat gosh> (use text.tree) # gosh> (tree->string '(foo bar)) "foobar" gosh> (tree->string '(foo (bar baz) hoge)) "foobarbazhoge" !2006-10-27 Fri gosh> (use text.tree) # gosh> write-tree # gosh> (define write-tree (lambda (x) (display (length x)))) write-tree gosh> (write-tree '(foo bar)) 2# gosh> (write-tree '(foo (bar baz))) 2# !2006-10-26 Thu gosh> (use text.tree) # gosh> (write-tree '(foo bar)) foobar#t gosh> (write-tree '(foo '(bar baz))) fooquotebarbaz#t gosh> (write-tree '(foo (bar baz))) foobarbaz#t gosh> (write-tree '(foo . bar)) foobar# !2006-10-25 Wed まんま gosh> (use text.csv) # gosh> (call-with-output-string (lambda (out) ((make-csv-writer #\,) out '("abc" "def" "123" "what's up?" "he said, \"nothing new.\"")))) "abc,def,123,\"what's up?\",\"he said, \"\"nothing new.\"\"\"\n" gosh> (call-with-output-string (lambda (out) ((make-csv-writer #\, "\r\n") out '("abc" "def" "123" "what's up?" "he said, \"nothing new.\"")))) "abc,def,123,\"what's up?\",\"he said, \"\"nothing new.\"\"\"\r\n" !2006-10-24 Tue まんま gosh> (use text.csv) # gosh> (call-with-input-string "abc , def ,, ghi " (make-csv-reader #\,)) ("abc" "def" "" "ghi") !2006-10-23 Mon まんま gosh> (use srfi-55) # gosh> (require-extension (srfi 1 13 14)) #t gosh> (delete-duplicates '(1 2 3 1 11 1)) (1 2 3 11) !2006-10-22 Sun gosh> (use srfi-37) # gosh> (define x (option '(#\o) #t #f (lambda (option name arg output files) (values arg files)))) x gosh> (option-names x) (#\o) gosh> (option-required-arg? x) #t gosh> (option-optional-arg? x) #f gosh> (option-processor x) # !2006-10-21 Sat gosh> (use srfi-37) # gosh> (option? (option '(#\o) #t #f (lambda (option name arg output files) (values arg files)))) #t gosh> (option? 1) #f !2006-10-20 Fri まんま (use srfi-37) (define options (list (option '(#\d "debug") #f #t (lambda (option name arg debug batch paths files) (values (or arg "2") batch paths files))) (option '(#\b "batch") #f #f (lambda (option name arg debug batch paths files) (values debug #t paths files))) (option '(#\I "include") #t #f (lambda (option name arg debug batch paths files) (values debug batch (cons arg paths) files))))) (define (main args) (receive (debug-level batch-mode include-paths files) (args-fold (cdr args) options (lambda (option name arg . seeds) ; unrecognized (error "Unrecognized option:" name)) (lambda (operand debug batch paths files) ; operand (values debug batch paths (cons operand files))) 0 ; default value of debug level #f ; default value of batch mode '() ; initial value of include paths '() ; initial value of files ) (print "debug level = " debug-level) (print "batch mode = " batch-mode) (print "include paths = " (reverse include-paths)) (print "files = " (reverse files)) 0)) で、 $ gosh foo.scm debug level = 0 batch mode = #f include paths = () files = () $ gosh foo.scm -d debug level = 2 batch mode = #f include paths = () files = () $ gosh foo.scm -d bar debug level = 2 batch mode = #f include paths = () files = (bar) $ gosh foo.scm -b debug level = 0 batch mode = #t include paths = () files = () $ gosh foo.scm -b bar debug level = 0 batch mode = #t include paths = () files = (bar) $ gosh foo.scm -I debug level = 0 batch mode = #f include paths = (#f) files = () $ gosh foo.scm -I bar debug level = 0 batch mode = #f include paths = (bar) files = () $ gosh foo.scm -I bar baz debug level = 0 batch mode = #f include paths = (bar) files = (baz) !2006-10-19 Thu まつがい プログラム引数 args を左から右へ処理ます。 まんま(簡易版) option の require-arg? optional-arg? あたりを変えてみる (use srfi-37) (define options (list (option '(#\o) #f #t (lambda (option name arg output files) (values arg files))))) (define (main args) (receive (output files) (args-fold (cdr args) options (lambda (option name arg . seeds) ; unrecognized (error "Unrecognized option:" name)) (lambda (operand output files) ; operand (values output (cons operand files))) "" '()) (print "output = " output) (print "files = " (reverse files)) 0)) で、 $ gosh foo1.scm output = files = () $ gosh foo1.scm -o output = #f files = () $ gosh foo1.scm -o bar output = #f files = (bar) (use srfi-37) (define options (list (option '(#\o) #t #f (lambda (option name arg output files) (values arg files))))) (define (main args) (receive (output files) (args-fold (cdr args) options (lambda (option name arg . seeds) ; unrecognized (error "Unrecognized option:" name)) (lambda (operand output files) ; operand (values output (cons operand files))) "" '()) (print "output = " output) (print "files = " (reverse files)) 0)) で、 $ gosh foo1.scm output = files = () $ gosh foo1.scm -o output = #f files = () $ gosh foo1.scm -o bar output = bar files = () $ gosh foo1.scm -o bar baz output = bar files = (baz) 余り良く分からないや !2006-10-18 Wed まんま(簡易版)。値を表示 (use srfi-37) (define options (list (option '(#\d "debug") #f #t (lambda (option name arg debug files) (values (or arg "2") files))))) (define (main args) (receive (debug-level files) (args-fold (cdr args) options (lambda (option name arg . seeds) ; unrecognized (error "Unrecognized option:" name)) (lambda (operand debug files) ; operand (values debug (cons operand files))) 0 '()) (print "debug level = " debug-level) (print "files = " (reverse files)) 0)) で、 $ gosh foo.scm debug level = 0 files = () $ gosh foo.scm -d debug level = 2 files = () $ gosh foo.scm foo debug level = 0 files = (foo) $ gosh foo.scm foo bar debug level = 0 files = (foo bar) $ gosh foo.scm foo bar -d debug level = 2 files = (foo bar) $ gosh foo.scm foo bar --debug debug level = 2 files = (foo bar) !2006-10-17 Tue まんま(簡易版) (use srfi-37) (define options (list (option '(#\d "debug") #f #t (lambda (option name arg debug files) (values (or arg "2") files))))) (define (main args) (args-fold (cdr args) options (lambda (option name arg . seeds) ; unrecognized (error "Unrecognized option:" name)) (lambda (operand debug files) ; operand (values debug (cons operand files))) 0 '())) で、 $ gosh foo.scm $ gosh foo.scm -d $ gosh foo.scm -x *** ERROR: Unrecognized option: #\x !2006-10-16 Mon まんま gosh> (let ((x 1) (y 2)) (let () (+ x y))) 3 gosh> (let ((x 1) (y 2)) (let ((y x) (x y)) (- x y))) 1 gosh> (let () (define x 1) (* x x)) 1 gosh> (let loop ((x 1) (sum 0)) (if (> x 10) sum (loop (+ x 1) (+ sum x)))) 55 gosh> (let (loop (x 1) (sum 0)) (if (> x 10) sum (loop (+ x 1) (+ sum x)))) *** ERROR: Compile Error: syntax-error: malformed let: (let (loop (x 1) (sum 0)) (if (> x 10) sum (loop (+ x 1) (+ sum x)))) "(stdin)":12:(let (loop (x 1) (sum 0)) (if (> x 1 ... Stack Trace: _______________________________________ gosh> (let (loop) (procedure? loop)) *** ERROR: Compile Error: syntax-error: malformed let: (let (loop) (procedure? loop)) "(stdin)":14:(let (loop) (procedure? loop)) Stack Trace: _______________________________________ gosh> (let ((x 0) (y 1) . (z 2 3 4)) (list x y z)) *** ERROR: Compile Error: syntax-error: malformed let: (let ((x 0) (y 1) z 2 3 4) (list x y z)) "(stdin)":16:(let ((x 0) (y 1) z 2 3 4) (list x y z)) Stack Trace: _______________________________________ gosh> (let loop ((x 0) (y 1) . (z 2 3 4)) (if (list? x) (list x y z) (loop z x y))) *** ERROR: Compile Error: syntax-error: malformed let: (let loop ((x 0) (y 1) z 2 3 4) (if (list? x) (list x y z) (loop z x y))) "(stdin)":17:(let loop ((x 0) (y 1) z 2 3 4) (if ... Stack Trace: _______________________________________ gosh> (use srfi-5) # gosh> (let (loop (x 1) (sum 0)) (if (> x 10) sum (loop (+ x 1) (+ sum x)))) 55 gosh> (let (loop) (procedure? loop)) #t gosh> (let ((x 0) (y 1) . (z 2 3 4)) (list x y z)) (0 1 (2 3 4)) gosh> (let loop ((x 0) (y 1) . (z 2 3 4)) (if (list? x) (list x y z) (loop z x y))) ((2 3 4) 0 (1)) !2006-10-15 Sun まんま gosh> (use srfi-9) # gosh> (define-record-type pare (kons x y) pare? (x kar set-kar!) (y kdr)) # gosh> (pare? (kons 2 3)) #t gosh> (pare? (cons 2 3)) #f gosh> (kar (kons 2 3)) 2 gosh> (kdr (kons 2 3)) 3 gosh> (let ((x (kons 2 3))) (set-kar! x -1) (kar x)) -1 !2006-10-14 Sat gosh> (use srfi-42) # gosh> (list-ec (:until (:list i '(1 2 3 4 5 6 7 8 9)) (> i 5)) i) (1 2 3 4 5 6) 「:while」の真似 !2006-10-13 Fri カンニング gosh> (use srfi-42) # gosh> (list-ec (:while (:list i '(1 2 3 4 5 6 7 8 9)) (< i 5)) i) (1 2 3 4) !2006-10-12 Thu カンニング gosh> (use srfi-42) # gosh> (list-ec (:parallel (:range i 1 10) (:list x '(a b c))) (list i x)) ((1 a) (2 b) (3 c)) gosh> (list-ec (:parallel (:range i 1 10)) i) (1 2 3 4 5 6 7 8 9) zip に似たようなことをするため??? !2006-10-11 Wed 「:port」「:dispatched」「:do」とばし カンニング gosh> (use srfi-42) # gosh> (list-ec (:let x 1) x) (1) gosh> (list-ec (:let x 1) (:let y (+ x 1)) y) (2) !2006-10-10 Tue gosh> (use srfi-42) # gosh> (list-ec (:char-range x #\a #\c) x) (#\a #\b #\c) !2006-10-09 Mon gosh> (use srfi-42) # gosh> (list-ec (:real-range x 4) x) (0 1 2 3) gosh> (list-ec (:real-range x 4.0) x) (0.0 1.0 2.0 3.0) gosh> (list-ec (:range x 4.0) x) *** ERROR: arguments of :range are not exact integer "(use :real-range?)" 0 4.0 1 gosh> (list-ec (:real-range x 1.0 4) x) (1.0 2.0 3.0) gosh> (list-ec (:real-range x 1 4.0) x) (1.0 2.0 3.0) gosh> (list-ec (:real-range x 1.0 4.0) x) (1.0 2.0 3.0) gosh> (list-ec (:real-range x 1.0 10.0 2) x) (1.0 3.0 5.0 7.0 9.0) gosh> (list-ec (:real-range x 1 2 0.2) x) (1.0 1.2 1.4 1.6 1.8) !2006-10-08 Sun gosh> (use srfi-42) # gosh> (list-ec (:range x 4) x) (0 1 2 3) gosh> (list-ec (:range x 1 4) x) (1 2 3) gosh> (list-ec (:range x 1 10 2) x) (1 3 5 7 9) !2006-10-07 Sat 何すか? :integers カンニング gosh> (use srfi-42) # gosh> (list-ec (:parallel (:integers x) (:do ((i 10)) (< x i) ((- i 1)))) (list x i)) ((0 10) (1 9) (2 8) (3 7) (4 6)) これしかなかったよ。意味分からないなあ… !2006-10-06 Fri gosh> (use srfi-42) # gosh> (list-ec (:string x (string)) x) () gosh> (list-ec (:string x (string "foo")) x) *** ERROR: character required, but got "foo" Stack Trace: _______________________________________ 0 (reverse (fold-ec '() (:string x (string "foo")) x cons)) [unknown location] 1 (reverse (fold-ec '() (:string x (string "foo")) x cons)) [unknown location] 2 (string "foo") [unknown location] 3 result gosh> (list-ec (:string x (string #\a)) x) (#\a) gosh> (list-ec (:string x (string #\a) (string #\b)) x) (#\a #\b) !2006-10-05 Thu またまたカンニング gosh> (use srfi-42) # gosh> (list-ec (:vector x (vector)) x) () gosh> (list-ec (:vector x (vector 1)) x) (1) gosh> (list-ec (:vector x (vector 1) (vector 2)) x) (1 2) gosh> (vector-ec (:vector x (vector)) x) #() gosh> (vector-ec (:vector x (vector 1)) x) #(1) gosh> (vector-ec (:vector x (vector 1) (vector 2)) x) #(1 2) !2006-10-04 Wed Control qualifiers って何? if, not, and, or, begin, nested とばし。 またまたカンニング gosh> (use srfi-42) # gosh> (list-ec (:list x '()) x) () gosh> (list-ec (:list x '(1)) x) (1) gosh> (list-ec (:list x '(1 2 3)) x) (1 2 3) gosh> (list-ec (:list x '(1) '(2)) x) (1 2) gosh> (list-ec (:list x '(1) '(2) '(3)) x) (1 2 3) !2006-10-03 Tue gosh> (use srfi-42) # カンニング(例は違うけど) gosh> (fold3-ec 0 (:range i 3) i (lambda (x) x) (lambda (x result) (+ result x))) 3 gosh> (fold3-ec 0 (:range i 3) i (lambda (x) (* x x)) (lambda (x result) (+ result x))) 3 gosh> (fold3-ec 0 (:range i 3) i (lambda (x) (+ x 1)) (lambda (x result) (+ result x))) 4 gosh> (fold3-ec 0 (:range i 3) i (lambda (x) x) (lambda (x result) (+ result (* x x)))) 5 一つ目の f は初期値に、二つ目の f はそれぞれの値に適用のようだ !2006-10-02 Mon カンニング(例は違うけど) gosh> (use srfi-42) # gosh> (fold-ec 0 (: i 5) i +) 10 !2006-10-01 Sun gosh> (use srfi-42) # gosh> (last-ec 10 (: i 5) i) 4 gosh> (last-ec 10 (:range 0 0) i) 10 !2006-09-30 Sat gosh> (use srfi-42) # gosh> (first-ec 10 (: i 5) i) 0 gosh> (first-ec 10 (:range 0 0) i) 10 !2006-09-29 Fri gosh> (use srfi-42) # gosh> (every?-ec (: i 5) (< i 5)) #t gosh> (every?-ec (: i 5) (even? i)) #f !2006-09-28 Thu gosh> (use srfi-42) # gosh> (any?-ec (: i 5) (> i 3)) #t gosh> (any?-ec (: i 5) (> i 10)) #f カンニング gosh> (any?-ec (:range i 2 2) (even? i)) #f range で増分値を変えることはできないのかな??? これで良い??? gosh> (any?-ec (:range i 2 10 2) (even? i)) #t gosh> (any?-ec (:range i 1 10 2) (even? i)) #f !2006-09-27 Wed gosh> (use srfi-42) # gosh> (max-ec (: i 5) i) 4 !2006-09-26 Tue gosh> (use srfi-42) # gosh> (min-ec (: i 5) i) 0 gosh> (min-ec (: i 5) (- 10 i)) 6 !2006-09-25 Mon gosh> (use srfi-42) # gosh> (product-ec (: x 1 5) x) 24 !2006-09-24 Sun gosh> (use srfi-42) # gosh> (sum-ec (: i 5) (* i i)) 30 gosh> (sum-ec (: i 5) i) 10 gosh> (sum-ec (: i 10) i) 45 !2006-09-23 Sat カンニング gosh> (use srfi-42) # gosh> (vector-of-length-ec 1 1) #(1) gosh> (vector-of-length-ec 2 (:range i 2) i) #(0 1) gosh> (vector-of-length-ec 3 (:range i 2) i) *** ERROR: vector is too long for the comprehension !2006-09-22 Fri gosh> (use srfi-42) # gosh> (vector-ec (: i 5) (* i i)) #(0 1 4 9 16) !2006-09-21 Thu gosh> (use srfi-42) # gosh> (string-ec (: x #\a #\c) x) "abc" gosh> (string-append-ec (:range i 2) "foo") "foofoo" !2006-09-20 Wed カンニング gosh> (use srfi-42) # gosh> (append-ec '(a b)) (a b) gosh> (append-ec (:range i 2) '(a b)) (a b a b) !2006-09-19 Tue gosh> (use srfi-42) # gosh> (do-ec (: i 5) (* i i)) # gosh> (do-ec (: i 5) (display i)) 01234# !2006-09-18 Mon まんま gosh> (use srfi-42) # gosh> (list-ec (: i 5) (* i i)) (0 1 4 9 16) gosh> (list-ec (: x 2 5) (: y 1 x) (list x y)) ((2 1) (3 1) (3 2) (4 1) (4 2) (4 3)) gosh> (vector-ec (: i 5) i) #(0 1 2 3 4) gosh> (string-ec (: i 5) (integer->char (+ i 65))) "ABCDE" gosh> (sum-ec (: i 1 10) i) 45 gosh> (product-ec (: i 1 10) i) 362880 !2006-09-17 Sun gosh> (use text.parse) # gosh> (skip-until #[a-z])012a #\a gosh> (skip-until #[0-9])012a #\0 gosh> *** ERROR: unbound variable: |12a| Stack Trace: _______________________________________ 0 |12a| 1 |12a| gosh> (skip-until #[0-9])abc0 #\0 あれ?以前に text.parse やっていたみたい。 → 終了… !2006-09-16 Sat gosh> (use text.parse) # gosh> (assert-curr-char #[a-z] "foo") *** ERROR: "(stdin)":line 19: wrong character c foo. #[a-z] expected. Stack Trace: _______________________________________ gosh> (assert-curr-char #[a-z] "f") *** ERROR: "(stdin)":line 20: wrong character c f. #[a-z] expected. Stack Trace: _______________________________________ gosh> (use srfi-14) # gosh> (assert-curr-char char-set:lower-case "f") *** ERROR: "(stdin)":line 22: wrong character c f. #[a-z] expected. Stack Trace: _______________________________________ gosh> (assert-curr-char char-set:lower-case "hoge")a #\a gosh> (assert-curr-char char-set:lower-case "hoge")A *** ERROR: "(stdin)":line 26: wrong character c hoge. #[a-z] expected. Stack Trace: _______________________________________ !2006-09-15 Fri gosh> (use text.parse) # gosh> (peek-next-char) a #\a gosh> *** ERROR: unbound variable: a Stack Trace: _______________________________________ 0 a 1 a gosh> (peek-next-char) #\newline インタラクティブにやって、うまく試せる方法はあるのか? !2006-09-14 Thu gosh> (use text.parse) # gosh> (find-string-from-port? "foo" (current-input-port)) foo 4 gosh> (find-string-from-port? "foo" (current-input-port)) bar foo 8 gosh> (find-string-from-port? "foo" (current-input-port)) bar baz #f gosh> (find-string-from-port? "foo" (current-input-port) 10) bar baz hoge #f gosh> *** ERROR: unbound variable: oge !2006-09-13 Wed gosh> (use text.html-lite) # gosh> (html:a "http://www.foo.org/") ("<" a () ">" ("http://www.foo.org/") "") gosh> (use text.tree) # まんま gosh> (tree->string (html:a :href "http://foo/bar" "foobar")) "foobar" gosh> (tree->string (html:table :width "100%" :cellpading 0 "content here")) "content here" gosh> (tree->string (html:table :border #t)) "
" gosh> (tree->string (html:table :border #f)) "
" なぜかドキュメントの最後に英語が残っているようだ !2006-09-12 Tue gosh> (use text.html-lite) # gosh> (html-doctype :type :xhtml-1.1) "\n" !2006-09-11 Mon gosh> (use text.html-lite) # gosh> (html-escape) ~ ~ < < > > gosh> (html-escape-string "<>?") "<>?" !2006-09-10 Sun まんま gosh> (use text.html-lite) # gosh> (html:table (html:tr (html:th "Item No") (html:th "Quantity")) (html:tr (html:td 1) (html:td 120)) (html:tr (html:td 2) (html:td 30)) (html:tr (html:td 3) (html:td 215))) (#0="<" table () #1=">" ((#0# tr () #1# ((#0# th () #1# ("Item No") #2="") (#0# th () #1# ("Quantity") #2# th #3#)) #2# tr #3#) (#0# tr () #1# ((#0# td () #1# (1) #2# td #3#) (#0# td () #1# (120) #2# td #3#)) #2# tr #3#) (#0# tr () #1# ((#0# td () #1# (2) #2# td #3#) (#0# td () #1# (30) #2# td #3#)) #2# tr #3#) (#0# tr () #1# ((#0# td () #1# (3) #2# td #3#) (#0# td () #1# (215) #2# td #3#)) #2# tr #3#)) #2# table #3#) gosh> (use text.tree) # gosh> (tree->string (html:table (html:tr (html:th "Item No") (html:th "Quantity")) (html:tr (html:td 1) (html:td 120)) (html:tr (html:td 2) (html:td 30)) (html:tr (html:td 3) (html:td 215)))) "
Item NoQuantity
1120
230
3215" !2006-09-09 Sat gosh> (use util.queue) # gosh> (define q (list->queue '(1 2 3 4 5))) q gosh> (remove-from-queue! (lambda (x) (even? x)) q) #t gosh> q ((1 3 . #0=(5)) . #0#) !2006-09-08 Fri gosh> (use util.queue) # gosh> (find-in-queue (lambda (x) (= x 1)) (list->queue '(1 2 3))) 1 gosh> (find-in-queue (lambda (x) (= x 5)) (list->queue '(1 2 3))) #f !2006-09-07 Thu gosh> (use util.queue) # gosh> (list->queue '(1 2 3)) ((1 2 . #0=(3)) . #0#) !2006-09-06 Wed gosh> (use util.queue) # gosh> (define q (make-queue)) q gosh> (enqueue! q 1) (#0=(1) . #0#) gosh> (enqueue! q 2) ((1 . #0=(2)) . #0#) gosh> (queue-front q) 1 gosh> q ((1 . #0=(2)) . #0#) gosh> (queue-rear q) 2 gosh> q ((1 . #0=(2)) . #0#) !2006-09-05 Tue gosh> (use util.queue) # gosh> (define q (make-queue)) q gosh> (enqueue! q 1) (#0=(1) . #0#) gosh> (enqueue! q 2) ((1 . #0=(2)) . #0#) gosh> (dequeue! q) 1 gosh> (dequeue! q) 2 gosh> (dequeue! q) *** ERROR: queue is empty (()) !2006-09-04 Mon gosh> (use util.queue) # gosh> (define q (make-queue)) q gosh> (queue-push! q 1) (#0=(1) . #0#) gosh> (queue-push-unique! q eq? 1) (#0=(1) . #0#) gosh> (queue-push-unique! q eq? 2) ((2 . #0=(1)) . #0#) !2006-09-03 Sun gosh> (use util.queue) # gosh> (define q (make-queue)) q gosh> (enqueue! q 1) (#0=(1) . #0#) gosh> (enqueue-unique! q eq? 1) (#0=(1) . #0#) gosh> q (#0=(1) . #0#) gosh> (enqueue-unique! q eq? 2) ((1 . #0=(2)) . #0#) !2006-09-02 Sat gosh> (use util.queue) # gosh> (define q (make-queue)) q gosh> (enqueue! q 1) (#0=(1) . #0#) gosh> (enqueue! q 2) ((1 . #0=(2)) . #0#) gosh> (queue-push! q 0) ((0 1 . #0=(2)) . #0#) gosh> (dequeue-all! q) (0 1 2) !2006-09-01 Fri gosh> (use util.queue) # gosh> (define q1 (make-queue)) q1 gosh> (queue-push! q1 1) (#0=(1) . #0#) gosh> (define q2 (copy-queue q1)) q2 gosh> (queue-push! q2 10) ((10 . #0=(1)) . #0#) gosh> q1 (#0=(1) . #0#) gosh> q2 ((10 . #0=(1)) . #0#) !2006-08-31 Thu gosh> (use util.queue) # gosh> (queue-length (make-queue)) 0 gosh> (define q (make-queue)) q gosh> (queue-push! q 1) (#0=(1) . #0#) gosh> (queue-length q) 1 !2006-08-30 Wed gosh> (use util.queue) # gosh> (queue-empty? (make-queue)) #t gosh> (define q (make-queue)) q gosh> (queue-push! q 1) (#0=(1) . #0#) gosh> (queue-empty? q) #f !2006-08-29 Tue gosh> (use util.queue) # gosh> (queue? (make-queue)) #t gosh> (queue? #t) #f !2006-08-28 Mon gosh> (use util.queue) # gosh> (make-queue) (()) !2006-08-27 Sun gosh> (use file.util) # gosh> (file->sexp-list "foo.csv") (1 ,2 10 ,20) !2006-08-26 Sat gosh> (use file.util) # gosh> (file->string-list "foo.csv") ("1,2" "10,20") !2006-08-25 Fri gosh> (use file.util) # gosh> (file->list read "foo.csv") (1 ,2 10 ,20) !2006-08-24 Thu gosh> (use file.util) # gosh> (file->string "foo.csv") "1,2,3\r\n4,5\r\n" !2006-08-23 Wed gosh> (use file.util) # gosh> (move-file "foo" "bar") #t gosh> (move-file "foo" "bar") *** ERROR: source file does not exist "foo" !2006-08-22 Tue gosh> (use file.util) # gosh> (copy-file "foo" "bar") #t gosh> (copy-file "foo" "bar") *** ERROR: couldn't open output file: "bar" gosh> (copy-file "foo" "bar" :if-exists :supersede) #t gosh> (copy-file "foo" "bar" :if-exists :backup) #t bar.orig ができていた gosh> (copy-file "foo" "bar" :if-exists #f) #f gosh> (copy-file "tmp" "hogehoge") *** SYSTEM-ERROR: read failed on #: Is a directory キーワード引数の指定の仕方で悩んでしまった… !2006-08-21 Mon gosh> (use file.util) # gosh> (touch-file "hogehoge") gosh> (touch-file "/hogehoge") *** ERROR: couldn't open output file: "/hogehoge" !2006-08-20 Sun gosh> (use file.util) # gosh> (file-ctime=? "tmp" "tmp") #t gosh> (file-atime=? "tmp" "tmp") #t !2006-08-19 Sat gosh> (use file.util) # gosh> (file-mtime=? "tmp" "tmp") #t gosh> (file-mtime=? "AdobeFnt.lst" "/dev/null") #t gosh> (file-mtime=? "tmp" ".emacs") #f gosh> (file-mtime (file-mtime<=? "tmp" "tmp") #t gosh> (file-mtime>? "tmp" "tmp") #f gosh> (file-mtime>=? "tmp" "tmp") #t gosh> (file-mtime>? "/tmp" (- (sys-time) 86400)) #t gosh> (file-mtime>? "tmp" (- (sys-time) 86400)) #f !2006-08-18 Fri gosh> (use file.util) # gosh> (file-eq? "AdobeFnt.lst" "/dev/null") #f gosh> (file-eqv? "AdobeFnt.lst" "/dev/null") #t gosh> (file-equal? "AdobeFnt.lst" "/dev/null") #t !2006-08-17 Thu gosh> (use file.util) # gosh> (file-is-symlink? "tmp") #f gosh> (file-is-symlink? "hoge") #f gosh> (file-is-symlink? "AdobeFnt.lst") #t !2006-08-16 Wed gosh> (use file.util) # gosh> (file-is-readable? "tmp") #t gosh> (file-is-readable? "hoge") #f gosh> (file-is-writable? "/") #f gosh> (file-is-executable? "tmp") #t gosh> (file-is-executable? ".emacs") #f !2006-08-15 Tue gosh> (use file.util) # gosh> (file-atime "tmp") 1156138252 gosh> (file-atime "tmp") 1156146716 gosh> (file-mtime "tmp") 1154578497 gosh> (file-ctime "tmp") 1154578497 !2006-08-14 Mon gosh> (use file.util) # gosh> (file-size "tmp") 4096 !2006-08-13 Sun gosh> (use file.util) # gosh> (file-uid "tmp") 1000 gosh> (file-gid "tmp") 100 !2006-08-12 Sat gosh> (use file.util) # gosh> (file-ino "tmp") 16385 gosh> (file-dev "tmp") 2072 gosh> (file-rdev "tmp") 0 gosh> (file-nlink "tmp") 13 !2006-08-11 Fri gosh> (use file.util) # gosh> (file-perm "tmp") 493 gosh> (file-mode "tmp") 16877 ? !2006-08-10 Thu gosh> (use file.util) # gosh> (file-type "tmp") directory gosh> (file-type "hoge") #f !2006-08-09 Wed まんま gosh> (use file.util) # gosh> (find-file-in-paths "ls") "/bin/ls" gosh> (find-file-in-paths "python") "/usr/bin/python" gosh> (find-file-in-paths "ruby" :paths `(,(expand-path "~/.myapp") "/usr/local/share/myapp" "/usr/share/myapp") :pred file-is-readable?) #f gosh> (find-file-in-paths "ruby" :paths `(,(expand-path "~/.myapp") "/usr/local/ruby-1.8.3/bin" "/usr/share/myapp") :pred file-is-readable?) "/usr/local/ruby-1.8.3/bin/ruby" !2006-08-08 Tue まんま gosh> (use file.util) # gosh> (path-swap-extension "/foo/bar.c" "o") "/foo/bar.o" gosh> (path-swap-extension "/foo/bar.c" #f) "/foo/bar" !2006-08-07 Mon まんま gosh> (use file.util) # gosh> (path-extension "/foo/bar.c") "c" gosh> (path-sans-extension "/foo/bar.c") "/foo/bar" gosh> (path-extension "/foo/bar") #f gosh> (path-sans-extension "/foo/bar") "/foo/bar" !2006-08-06 Sun まんま gosh> (use file.util) # gosh> (decompose-path "/foo/bar/baz.scm") "/foo/bar" "baz" "scm" gosh> (decompose-path "/foo/bar/baz") "/foo/bar" "baz" #f gosh> (decompose-path "baz.scm") "." "baz" "scm" gosh> (decompose-path "/baz.scm") "" "baz" "scm" gosh> (decompose-path "/foo/bar/baz.") "/foo/bar" "baz" "" gosh> (decompose-path "/foo/bar/.baz") "/foo/bar" ".baz" #f gosh> (decompose-path "/foo/bar.baz/") "/foo/bar.baz" #f #f !2006-08-05 Sat gosh> (use file.util) # gosh> (simplify-path "./tmp/../") "" gosh> (simplify-path "..//root/") "../root/" gosh> (simplify-path "./tmp/../../") "../" gosh> (simplify-path "././././") "" !2006-08-04 Fri bar -> foo とする gosh> (use file.util) # gosh> (resolve-path "bar") "foo" (remove-directory* "foo") gosh> (remove-directory* "foo") *** SYSTEM-ERROR: couldn't open directory "foo": Not a directory ファイルは消せなかったか。foo を消す gosh> (resolve-path "bar") *** ERROR: path doesn't exist "bar" !2006-08-03 Thu gosh> (use file.util) # gosh> (expand-path "~") "/home/nnakamur/" gosh> (expand-path ".") "." gosh> (expand-path "~root") "/root/" gosh> (expand-path "~hoge") *** ERROR: couldn't get home directory of user "hoge". gosh> (expand-path "~~") *** ERROR: couldn't get home directory of user "~". !2006-08-02 Wed gosh> (use file.util) # gosh> (relative-path? "tmp") #t gosh> (relative-path? "/tmp") #f !2006-08-01 Tue gosh> (use file.util) # gosh> (absolute-path? "/tmp") #t gosh> (absolute-path? "tmp") #f gosh> (absolute-path? " /tmp") #f !2006-07-31 Mon gosh> (use file.util) # gosh> (build-path "tmp" "hoge") "tmp/hoge" gosh> (build-path "tmp/" "hoge") "tmp/hoge" gosh> (build-path "tmp/" "/hoge") *** ERROR: can't append absolute path after other path "/hoge" !2006-07-30 Sun gosh> (use file.util) # gosh> (make-directory* "tmp/hoge/hoge/hoge") #t gosh> (remove-directory* "tmp/hoge/hoge/hoge") #t gosh> (remove-directory* "tmp/hoge") #t !2006-07-29 Sat gosh> (use file.util) # gosh> (make-directory* "tmp") # gosh> (make-directory* "tmp/hoge/hoge/hoge") #t !2006-07-28 Fri まんま gosh> (use file.util) # gosh> (use srfi-13) # gosh> (directory-fold "tmp" (lambda (entry result) (if (string-suffix? "~" entry) (cons entry result) result)) '()) ("tmp/ ... "tmp/hogehoge/00memo.txt~") !2006-07-27 Thu gosh> (use file.util) # gosh> (directory-list2 "/tmp") ("." ".." ".ICE-unix" ".X11-unix" ".font-unix" ".iroha_unix" ".ki2-unix" "gconfd-nnakamur" "gconfd-root" "hajimeyo_source" "orbit-nnakamur" "orbit-root" "ssh-wVpayIc598" "win32serial") (".X0-lock" ".X64-lock" "ivrlg1044797b" "ivrlh1044797b") !2006-07-26 Wed gosh> (use file.util) # gosh> (directory-list "/tmp") ("." ".." ".ICE-unix" ".X0-lock" ".X11-unix" ".X64-lock" ".font-unix" ".iroha_unix" ".ki2-unix" "gconfd-nnakamur" "gconfd-root" "hajimeyo_source" "ivrlg1044797b" "ivrlh1044797b" "orbit-nnakamur" "orbit-root" "ssh-wVpayIc598" "win32serial") gosh> (directory-list "/tmp" :children? #t) (".ICE-unix" ".X0-lock" ".X11-unix" ".X64-lock" ".font-unix" ".iroha_unix" ".ki2-unix" "gconfd-nnakamur" "gconfd-root" "hajimeyo_source" "ivrlg1044797b" "ivrlh1044797b" "orbit-nnakamur" "orbit-root" "ssh-wVpayIc598" "win32serial") gosh> (directory-list "/tmp" :add-path? #t) ("/tmp/." "/tmp/.." "/tmp/.ICE-unix" "/tmp/.X0-lock" "/tmp/.X11-unix" "/tmp/.X64-lock" "/tmp/.font-unix" "/tmp/.iroha_unix" "/tmp/.ki2-unix" "/tmp/gconfd-nnakamur" "/tmp/gconfd-root" "/tmp/hajimeyo_source" "/tmp/ivrlg1044797b" "/tmp/ivrlh1044797b" "/tmp/orbit-nnakamur" "/tmp/orbit-root" "/tmp/ssh-wVpayIc598" "/tmp/win32serial") gosh> (use srfi-13) # gosh> (directory-list "/tmp" :filter (lambda (e) (not (string-prefix? "." e)))) ("gconfd-nnakamur" "gconfd-root" "hajimeyo_source" "ivrlg1044797b" "ivrlh1044797b" "orbit-nnakamur" "orbit-root" "ssh-wVpayIc598" "win32serial") !2006-07-25 Tue gosh> (use file.util) # gosh> (temporary-directory) "/tmp" !2006-07-24 Mon gosh> (use file.util) # gosh> (home-directory) "/home/nnakamur" gosh> (home-directory "root") "/root" !2006-07-23 Sun gosh> (use file.util) # gosh> (current-directory) "/home/nnakamur" gosh> (current-directory "tmp") #t gosh> (current-directory) "/home/nnakamur/tmp" !2006-07-22 Sat gosh> (use text.parse) # gosh> (read-string 1)a "a" gosh> (read-string 3)abc "abc" gosh> (read-string 3)abcd "abc" gosh> # gosh> (read-string 3)abcde "abc" gosh> *** ERROR: unbound variable: de !2006-07-21 Fri gosh> (use text.parse) # gosh> (next-token-of #[a-z]) "" gosh> (next-token-of #[a-z])a "a" gosh> (next-token-of #[a-z])Aa "" gosh> *** ERROR: unbound variable: Aa Stack Trace: _______________________________________ 0 Aa 1 Aa gosh> (next-token-of #[a-z])A "" gosh> *** ERROR: unbound variable: A !2006-07-20 Thu gosh> (use text.parse) # gosh> (next-token #[\x00-\x7f] #[a-z])abcdf *** ERROR: "(stdin)":line 35: unexpected EOF Stack Trace: _______________________________________ gosh> (next-token #[\x00-\x7f] #[a-z]) abc *** ERROR: "(stdin)":line 37: unexpected EOF gosh> (next-token #[\x00-\x20] #[a-z]) abc "" gosh> *** ERROR: unbound variable: abc !2006-07-19 Wed gosh> (use text.parse) # gosh> (skip-while #[a-z])abcdefg #\newline gosh> (skip-while #[\x00-\x7f])a a # gosh> (skip-while #[\s]) a #\a gosh> *** ERROR: unbound variable: a 対話環境で実行すると、問題の切り分けが難しい !2006-07-18 Tue gosh> (use text.parse) # gosh> (skip-until #[\x00-\x7f])abcdef #\a gosh> *** ERROR: unbound variable: bcdef Stack Trace: _______________________________________ 0 bcdef 1 bcdef gosh> (skip-until #[a-z])abcdef #\a gosh> *** ERROR: unbound variable: bcdef Stack Trace: _______________________________________ 0 bcdef 1 bcdef gosh> (skip-until #[\x00-\x7f])a #\a gosh> (skip-until #[a-z])a #\a gosh> (skip-until 10)a bcdefggh #f gosh> (skip-until 10)abcdefghijklmn #f gosh> *** ERROR: unbound variable: klmn Stack Trace: _______________________________________ 0 klmn 1 klmn !2006-07-17 Mon gosh> (use text.parse) # gosh> (assert-curr-char #[a-z\x00-\x7f] "hoge") #\newline gosh> (assert-curr-char #[a-z] "hoge") *** ERROR: "(stdin)":line 13: wrong character c hoge. #[a-z] expected. !2006-07-16 Sun gosh> (use text.parse) # gosh> (peek-next-char) foo #\f gosh> *** ERROR: unbound variable: foo Stack Trace: _______________________________________ 0 foo 1 foo gosh> (peek-next-char) #\newline !2006-07-15 Sat gosh> (use text.parse) # gosh> (find-string-from-port? "foo" (current-input-port)) bar #f gosh> (find-string-from-port? "foo" (current-input-port)) foo 5 !2006-07-14 Fri gosh> (use rfc.uri) # gosh> (uri-encode-string ": ~ +") "%3a%20~%20%2b" !2006-07-13 Thu gosh> (use rfc.uri) # gosh> (uri-encode) : ~ + %0a%3a%20~%20%2b%0a# !2006-07-12 Wed gosh> (use rfc.uri) # gosh> (uri-decode-string "%3A +") ": +" !2006-07-11 Tue gosh> (use rfc.uri) # gosh> (uri-decode) %3A%3A :: + + gosh> (uri-decode :cgi-decode #t) + !2006-07-10 Mon まんま gosh> (use rfc.uri) # gosh> (uri-compose :scheme "http" :host "foo.com" :port 80 :path "/index.html" :fragment "top") "http://foo.com:80/index.html#top" gosh> (uri-compose :scheme "http" :host "foo.net" :path* "/cgi-bin/query.cgi?keyword=foo") "http://foo.net/cgi-bin/query.cgi?keyword=foo" gosh> (uri-compose :scheme "mailto" :specific "a@foo.org") "mailto:a@foo.org" gosh> (receive (authority path query fragment) (uri-decompose-hierarchical "//foo.jp/index.html#whatsnew") (uri-compose :authority authority :path path :query query :fragment fragment)) "//foo.jp/index.html#whatsnew" !2006-07-09 Sun まんま gosh> (use rfc.uri) # gosh> (uri-decompose-authority "yyy.jp:8080") #f "yyy.jp" "8080" gosh> (uri-decompose-authority "mylogin@yyy.jp") "mylogin" "yyy.jp" #f !2006-07-08 Sat まんま gosh> (use rfc.uri) # gosh> (uri-decompose-hierarchical "//www.foo.com/about/company.html") "www.foo.com" "/about/company.html" #f #f gosh> (uri-decompose-hierarchical "//zzz.org/search?key=%3fhelp") "zzz.org" "/search" "key=%3fhelp" #f gosh> (uri-decompose-hierarchical "//jjj.jp/index.html#whatsnew") "jjj.jp" "/index.html" #f "whatsnew" gosh> (uri-decompose-hierarchical "my@address") #f "my@address" #f #f !2006-07-07 Fri まんま gosh> (use rfc.uri) # gosh> (uri-scheme&specific "mailto:sclaus@north.pole") "mailto" "sclaus@north.pole" gosh> (uri-scheme&specific "/icons/new.gif") #f "/icons/new.gif" !2006-07-06 Thu gosh> (use rfc.uri) # gosh> (uri-parse "mailto:foo@example.com") "mailto" #f #f #f "foo@example.com" #f #f gosh> (uri-parse "ftp://anonymous@ftp.example.com/pub/foo") "ftp" "anonymous" "ftp.example.com" #f "/pub/foo" #f #f gosh> (uri-parse "http://www.example.com:8080/") "http" #f "www.example.com" 8080 "/" #f #f gosh> (uri-parse "http://www.example.com/index.html") "http" #f "www.example.com" #f "/index.html" #f #f gosh> (uri-parse "http://www.example.com/search?key=xyz&lang=en") "http" #f "www.example.com" #f "/search" "key=xyz&lang=en" #f gosh> (uri-parse "http://www.example.com/document.html#section4") "http" #f "www.example.com" #f "/document.html" #f "section4" !2006-07-05 Wed gosh> (use text.tr) # gosh> (with-input-from-file "foo" (lambda () (let loop ((line (read-line))) (unless (eof-object? line) (tr "A-Za-z" "a-zA-Z"))))) abcdefg # gosh> (with-input-from-file "foo" (lambda () (let ((ptr (build-transliterator "A-Za-z" "a-zA-Z"))) (let loop ((line (read-line))) (unless (eof-object? line) (ptr)))))) abcdefg # どういう動作をするんだっけ? !2006-07-04 Tue gosh> (use text.tr) # gosh> (string-tr "foo" "A-Za-z" "a-zA-Z") "FOO" !2006-07-03 Mon まんま gosh> (use text.tr) # gosh> (tr "A-Za-z" "a-zA-Z") a A b B # gosh> (tr "ぁ-んァ-ン" "ァ-ンぁ-ん") あ ア ん ン # gosh> (tr "\x00-\x19\x7f" "?*") ???# !2006-07-02 Sun まんま gosh> (use util.combinations) # gosh> (cartesian-product '((a b c) (0 1))) ((a . #0=(0)) (a . #1=(1)) (b . #0#) (b . #1#) (c . #0#) (c . #1#)) gosh> (cartesian-product-right '((a b c) (0 1))) ((a . #0=(0)) (b . #0#) (c . #0#) (a . #1=(1)) (b . #1#) (c . #1#)) 良い? !2006-07-01 Sat まんま gosh> (use util.combinations) # gosh> (power-set-binary '(a b c)) (() #0=(c) #1=(b) #2=(b . #0#) (a) (a . #0#) (a . #1#) (a . #2#)) 良い? !2006-06-30 Fri gosh> (use util.combinations) # gosh> (power-set-for-each (lambda (x) (display x)) '(a b c)) ()(a)(b)(c)(a b)(a c)(b c)(a b c)() gosh> (power-set*-for-each (lambda (x) (display x)) '(a a b)) ()(a)(b)(a a)(a b)(a a b)() !2006-06-29 Thu まんま gosh> (use util.combinations) # gosh> (power-set '(a b c)) (() (a) (b) (c) (a b) (a c) (b c) (a b c)) gosh> (power-set* '(a a b)) (() (a) (b) (a a) (a b) (a a b)) マニュアルでは、power-set* の最後の括弧ひとつ足りず !2006-06-28 Wed gosh> (use util.combinations) # gosh> (combinations-for-each (lambda (x) (display x)) '(a b c) 2) (a b)(a c)(b c)# gosh> (combinations*-for-each (lambda (x) (display x)) '(a a b) 2) (a a)(a b)#t !2006-06-27 Tue まんま gosh> (use util.combinations) # gosh> (combinations '(a b c) 2) ((a b) (a c) (b c)) gosh> (combinations '(a a b) 2) ((a a) (a b) (a b)) gosh> (combinations* '(a a b) 2) ((a a) (a b)) !2006-06-26 Mon gosh> (use util.combinations) # gosh> (permutations-for-each (lambda (x) (display x)) '(a b c)) (a b c)(a c b)(b a c)(b c a)(c a b)(c b a)#t gosh> (permutations*-for-each (lambda (x) (display x)) '(a a b)) (a a b)(a b a)(b a a)#t !2006-06-25 Sun まんま gosh> (use util.combinations) # gosh> (permutations '(a b c)) ((a b . #0=(c)) (a c b) (b a . #0#) (b c a) (c a b) (c b a)) gosh> (permutations '(a a b)) ((a a . #0=(b)) (a b a) (a a . #0#) (a b a) (b a a) (b a a)) gosh> (permutations* '(a a b)) ((a a b) (a b a) (b a a)) なんか変??? !2006-06-24 Sat gosh> (use util.list) # gosh> (define x '((a . 1) (b . 2) (c . 3))) x gosh> (assoc-set! x 'd 4) ((d . 4) (a . 1) (b . 2) (c . 3)) gosh> x ((a . 1) (b . 2) (c . 3)) なぜ、! がついているの? と、思ったが、x が指しているのは、(a . 1) 以降だからか? !2006-06-23 Fri gosh> (use util.list) # gosh> (rassoc-ref '((a . 1) (b . 2) (c . 3)) 1) a gosh> (rassoc-ref '((a . 1) (b . 2) (c . 3)) 10) #f !2006-06-22 Thu gosh> (use util.list) # gosh> (assoc-ref '((a . 1) (b . 2) (c . 3)) 'a) 1 gosh> (assoc-ref '((a . 1) (b . 2) (c . 3)) 'd) #f !2006-06-21 Wed gosh> (use util.list) # gosh> (rassoc 1 '((a . 1) (b . 2) (c . 3))) (a . 1) gosh> (rassoc 4 '((a . 1) (b . 2) (c . 3))) #f gosh> (rassq 1 '((a . 1) (b . 2) (c . 3))) (a . 1) gosh> (rassv 1 '((a . 1) (b . 2) (c . 3))) (a . 1) そもそも rassoc ないのか! !2006-06-20 Tue gosh> (use util.list) # gosh> (hash-table->alist (alist->hash-table '((a . 1) (b . 2) (c . 3)))) ((c . 3) (a . 1) (b . 2)) !2006-06-19 Mon gosh> (use util.list) # gosh> (alist->hash-table '((a . 1) (b . 2) (c . 3))) # gosh> (hash-table-keys (alist->hash-table '((a . 1) (b . 2) (c . 3)))) (b a c) 何が嬉しいんだっけ? 他に alist から作る方法がないのかな? それはそれで変なの。 !2006-06-18 Sun まんま gosh> (use util.list) # gosh> (let ((alist '((x 3) (y -1) (z 6)))) (cond-list ((assoc 'x alist) 'have-x) ((assoc 'w alist) 'have-w) ((assoc 'z alist) => cadr))) (have-x 6) !2006-06-17 Sat まんま gosh> (use util.list) # gosh> (intersperse '+ '(1 2 3)) (1 + 2 + 3) gosh> (intersperse '+ '(1)) (1) gosh> (intersperse '+ '()) () くっつかない join みたいなもの??? !2006-06-16 Fri まんま gosh> (use util.list) # gosh> (slices '(a b c d e f g) 3) ((a b c) (d e f) (g)) gosh> (slices '(a b c d e f g) 3 #t 'z) ((a b c) (d e f) (g z z)) !2006-06-15 Thu まんま gosh> (use util.list) # gosh> (split-at* '(a b c d) 6 #t 'z) (a b c d z z) () !2006-06-14 Wed gosh> (use util.list) # gosh> (drop-right* '(a b c d) 3) (a) gosh> (drop-right* '(a b c d) 6) () !2006-06-13 Tue gosh> (use util.list) # gosh> (take-right* '(a b c d) 3) (b c d) gosh> (take-right* '(a b c d) 6) (a b c d) gosh> (take-right* '(a b c d) 6 #t) (#f #f a b c d) gosh> (take-right* '(a b c d) 6 #t 'z) (z z a b c d) gosh> (take-right* '(a b c d) 6 'z) (#f #f a b c d) !2006-06-12 Mon まんま gosh> (use util.list) # gosh> (drop* '(a b c d) 3) (d) gosh> (drop* '(a b c d) 5) () gosh> (use srfi-1) # gosh> (drop '(a b c d) 3) (d) gosh> (drop '(a b c d) 5) *** ERROR: argument out of range: 5 Stack Trace: _______________________________________ 0 (drop '(a b c d) 5) At line 15 of "(stdin)" 1 (drop '(a b c d) 5) At line 15 of "(stdin)" !2006-06-11 Sun まんま gosh> (use util.list) # gosh> (take* '(a b c d) 3) (a b c) gosh> (take* '(a b c d) 6) (a b c d) gosh> (take* '(a b c d) 6 #t) (a b c d #f #f) gosh> (take* '(a b c d) 6 #t 'z) (a b c d z z) gosh> (use srfi-1) # gosh> (take '(a b c d) 3) (a b c) gosh> (take '(a b c d) 6) *** ERROR: pair required, but got () Stack Trace: _______________________________________ gosh> (take '(a b c d) 6 #t) *** ERROR: wrong number of arguments for # (required 2, got 3) Stack Trace: _______________________________________ 0 (take '(a b c d) 6 #t) At line 9 of "(stdin)" 1 (take '(a b c d) 6 #t) At line 9 of "(stdin)" gosh> (take '(a b c d) 6 #t 'z) *** ERROR: wrong number of arguments for # (required 2, got 4) Stack Trace: _______________________________________ 0 (take '(a b c d) 6 #t 'z) At line 10 of "(stdin)" 1 (take '(a b c d) 6 #t 'z) At line 10 of "(stdin)" !2006-06-10 Sat gosh> (use math.const) # gosh> e 2.718281828459045 !2006-06-09 Fri gosh> pi *** ERROR: unbound variable: pi Stack Trace: _______________________________________ 0 pi 1 pi gosh> (use math.const) # gosh> pi 3.141592653589793 gosh> pi/2 1.5707963267948966 gosh> pi/4 0.7853981633974483 gosh> pi/180 0.017453292519943295 gosh> 1/pi 0.3183098861837907 gosh> 180/pi 57.29577951308232 こんなトークンありなの? gosh> 180 / pi 180 gosh> # gosh> 3.141592653589793 !2006-06-08 Thu gosh> (use srfi-14) # gosh> char-set:full #[\x00-\x7f-] !2006-06-07 Wed gosh> (use srfi-14) # gosh> char-set:empty #[] !2006-06-06 Tue gosh> (use srfi-14) # gosh> char-set:ascii #[\x00-\x7f] !2006-06-05 Mon gosh> (use srfi-14) # gosh> char-set:symbol #[$+<->^`|~] !2006-06-04 Sun gosh> (use srfi-14) # gosh> char-set:whitespace #[\x09-\x0d ] !2006-06-03 Sat gosh> (use srfi-14) # gosh> char-set:punctuation #[!-/:-@[-`{-~] !2006-06-02 Fri gosh> (use srfi-14) # gosh> char-set:printing #[ -~] !2006-06-01 Thu gosh> (use srfi-14) # gosh> char-set:lower-case #[a-z] gosh> char-set:upper-case #[A-Z] gosh> char-set:title-case #[A-Z] !2006-05-31 Wed gosh> (use srfi-14) # gosh> char-set:graphic #[!-~] !2006-05-30 Tue gosh> (use srfi-14) # gosh> char-set:digit #[0-9] gosh> char-set:hex-digit #[0-9A-Fa-f] !2006-05-29 Mon gosh> (use srfi-14) # gosh> char-set:iso-control #[\x00-\x1f\x7f] !2006-05-28 Sun gosh> (use srfi-14) # gosh> char-set:blank #[\x09 ] !2006-05-27 Sat gosh> (use srfi-14) # gosh> char-set:letter #[A-Za-z] !2006-05-26 Fri gosh> (use srfi-14) # gosh> (char-set-diff+intersection #[a-c] #[a-f]) #[] #[a-c] gosh> (char-set-diff+intersection #[a-c] #[c-f]) #[ab] #[c] gosh> (char-set-diff+intersection #[a-c] #[f-z]) #[a-c] #[] !2006-05-25 Thu gosh> (use srfi-14) # gosh> (char-set-xor #[a-c] #[c-f]) #[abd-f] !2006-05-24 Wed gosh> (use srfi-14) # gosh> (char-set-difference #[a-c] #[a-f]) #[] gosh> (char-set-difference #[a-c] #[f-z]) #[a-c] gosh> (char-set-difference #[a-c] #[b-f]) #[a] !2006-05-23 Tue gosh> (use srfi-14) # gosh> (char-set-intersection #[a-c] #[a-f]) #[a-c] gosh> (char-set-intersection #[a-c] #[c-f]) #[c] !2006-05-22 Mon gosh> (use srfi-14) # gosh> (char-set-union #[a-c] #[a-c] #[a-f]) #[a-f] !2006-05-21 Sun gosh> (use srfi-14) # gosh> (char-set-complement #[a-c]) #[\x00-`d-\x7f-] gosh> (char-set-complement #[\x00-`d-\x7f-]) #[a-c-] !2006-05-20 Sat gosh> (use srfi-14) # gosh> (char-set-delete #[a-c] #\d #\e #\f) #[a-c] gosh> (char-set-delete #[a-c] #\a) #[bc] gosh> (char-set-delete #[a-c] #\a #\b #\c) #[] !2006-05-19 Fri gosh> (use srfi-14) # gosh> (char-set-adjoin #[a-c] #\d #\e #\f) #[a-f] gosh> (char-set-adjoin #[a-c] #\a #\a #\a) #[a-c] gosh> (define x #[a-c]) x gosh> x #[a-c] gosh> (char-set-adjoin! x #\d #\e #\f) #[a-f] gosh> x #[a-f] !2006-05-18 Thu gosh> (use srfi-14) # gosh> (char-set-any (lambda (x) (char>? x #\c)) #[a-c]) #f gosh> (char-set-any (lambda (x) (char (use srfi-14) # gosh> (char-set-every (lambda (x) (char>? x #\c)) #[a-c]) #f gosh> (char-set-every (lambda (x) (char (use srfi-14) # gosh> (char-set->string (string->char-set "abc")) "cba" gosh> (char-set->string #[a-z]) "zyxwvutsrqponmlkjihgfedcba" !2006-05-15 Mon gosh> (use srfi-14) # gosh> (char-set->list (string->char-set "abc")) (#\c #\b #\a) !2006-05-14 Sun gosh> (use srfi-14) # gosh> (char-set-count (lambda (x) (char=? x #\a)) (string->char-set "abc")) 1 gosh> (char-set-count (lambda (x) (charchar-set "a-z")) 2 gosh> (string->char-set "a-z") #[-az] gosh> (char-set-count (lambda (x) (char (char-set-count (lambda (x) (char (use srfi-14) # gosh> (char-set-size (string->char-set "abc")) 3 !2006-05-12 Fri gosh> (use srfi-14) # gosh> (char-set-map (lambda (x) (char-upcase x)) (string->char-set "abc")) #[A-C] !2006-05-11 Thu gosh> (use srfi-14) # gosh> (char-set-for-each (lambda (x) (display x)) (string->char-set "abc")) abc# gosh> (char-set-for-each (lambda (x) (display (format "~S\n" x))) (string->char-set "abc")) #\a #\b #\c # !2006-05-10 Wed またまた カンニング… gosh> (use srfi-14) # gosh> (char-set-unfold null? car cdr '(#\a #\e #\i #\o #\u #\u #\u) char-set:digit) #[0-9aeiou] !2006-05-09 Tue カンニング… gosh> (use srfi-14) # gosh> (char-set-fold (lambda (c i) (+ i 1)) 0 (char-set #\e #\i #\o #\u #\e #\e)) 4 !2006-05-08 Mon gosh> (use srfi-14) # gosh> (define x (char-set-cursor (string->char-set "abc"))) x gosh> (end-of-char-set? x) #f gosh> (char-set-cursor-next (string->char-set "abc") x) (98 (97 . 99)) gosh> x (97 (97 . 99)) gosh> (end-of-char-set? x) #f gosh> (char-set-cursor-next (string->char-set "abc") x) (98 (97 . 99)) gosh> x (97 (97 . 99)) gosh> (end-of-char-set? x) #f gosh> (char-set-cursor (string->char-set "abc")) (97 (97 . 99)) gosh> (end-of-char-set? '(99 (97 . 99))) #f gosh> (end-of-char-set? '(98 (97 . 99))) #f gosh> (end-of-char-set? '(100 (97 . 99))) #f ? !2006-05-07 Sun gosh> (use srfi-14) # gosh> (char-set-cursor-next (string->char-set "abc") (char-set-cursor (string->char-set "abc"))) (98 (97 . 99)) 現在状態をどうやって保持するんだ? !2006-05-06 Sat gosh> (use srfi-14) # gosh> (char-set-ref (string->char-set "abc") (char-set-cursor (string->char-set "abc"))) !2006-05-05 Fri gosh> (use srfi-14) # gosh> (char-set-cursor (string->char-set "abc")) (97 (97 . 99)) ふにゃ? !2006-05-04 Thu gosh> (use srfi-14) # gosh> (char-set-hash (string->char-set "abc")) 196 gosh> (hash "abc") 96354 !2006-05-03 Wed gosh> (use srfi-14) # gosh> (char-set<= (string->char-set "abc") (string->char-set "abc")) #t gosh> (char-set<= (string->char-set "abc") (string->char-set "def")) #f gosh> (char-set<= (string->char-set "abc") (string->char-set "defg")) #f gosh> (char-set<= (string->char-set "def") (string->char-set "abc")) #f gosh> (char-set<= (string->char-set "abc") (string->char-set "abcd")) #t gosh> (char-set<= (string->char-set "abcd") (string->char-set "abc")) #f gosh> (char-set<= (string->char-set "def") (string->char-set "abcd")) #f いまいち良く分からない… !2006-05-02 Tue gosh> (use srfi-14) # gosh> (char-set= (string->char-set "abc") (string->char-set "abc")) #t gosh> (char-set= (string->char-set "abc") (string->char-set "def")) #f !2006-05-01 Mon gosh> (use srfi-14) # gosh> (->char-set (string->char-set "abc")) #[a-c] !2006-04-30 Sun gosh> (use srfi-14) # gosh> (integer-range->char-set 97 100) #[a-c] !2006-04-29 Sat gosh> (use srfi-14) # gosh> (ucs-range->char-set #\a #\c) *** ERROR: real number required: #\a gosh> (ucs-range->char-set 0 9) #[\x00-\x08] gosh> (ucs-range->char-set 97 99) #[ab] gosh> (ucs-range->char-set 97 100) #[a-c] !2006-04-28 Fri gosh> (use srfi-14) # gosh> (char-set-filter (lambda (c) (eq? c #\a)) (string->char-set "abc")) #[a] gosh> (define x (string->char-set "abc")) x gosh> (char-set-filter! (lambda (c) (eq? c #\a)) x) *** ERROR: wrong number of arguments for # (required 3, got 2) gosh> (define y (string->char-set "def")) y gosh> (char-set-filter! (lambda (c) (eq? c #\a)) x y) #[ad-f] gosh> x #[a-c] gosh> y #[ad-f] !2006-04-27 Thu gosh> (use srfi-14) # gosh> (string->char-set "abc") #[a-c] gosh> (string->char-set "cba") #[a-c] gosh> (string->char-set "def" (string->char-set "abc")) #[a-f] gosh> (define x (string->char-set "abc")) x gosh> x #[a-c] gosh> (string->char-set! "def" x) #[a-f] gosh> x #[a-f] !2006-04-26 Wed gosh> (use srfi-14) # gosh> (list->char-set '(#\a #\b #\c)) #[a-c] gosh> (list->char-set '(#\d #\e #\f) (list->char-set '(#\a #\b #\c))) #[a-f] gosh> (define x (list->char-set '(#\a #\b #\c))) x gosh> (list->char-set! '(#\d #\e #\f) x) #[a-f] gosh> x #[a-f] !2006-04-25 Tue gosh> (use srfi-43) # gosh> (reverse-list->vector '(1 2 3)) #(3 2 1) gosh> (reverse-list->vector '(1 2 3) 0 1) #(1) gosh> (reverse-list->vector '(1 2 3) 1) #(3 2) !2006-04-24 Mon gosh> (use srfi-43) # gosh> (reverse-vector->list #(1 2 3)) (3 2 1) gosh> (reverse-vector->list #(1 2 3) 0 1) (1) gosh> (reverse-vector->list #(1 2 3) 1 1) () gosh> (reverse-vector->list #(1 2 3) 1 2) (2) !2006-04-23 Sun gosh> (use srfi-43) # gosh> (define x #(1 2 3)) x gosh> (define y #(4 5 6)) y gosh> (vector-reverse-copy! x 0 y) # gosh> x #(6 5 4) !2006-04-22 Sat gosh> (use srfi-43) # gosh> (define x #(1 2 3)) x gosh> (define y #(4 5 6)) y gosh> (vector-copy! x 0 y) # gosh> x #(4 5 6) gosh> y #(4 5 6) gosh> (define x #(1 2 3)) x gosh> (vector-copy! x 1 y) *** ERROR: index out of range: 3 Stack Trace: _______________________________________ gosh> (define x #(1 2 3 4)) x gosh> (vector-copy! x 1 y) # gosh> x #(1 4 5 6) gosh> (define x #(1 2 3)) x gosh> (vector-copy! x 1 y 1 3) # gosh> x #(1 5 6) !2006-04-21 Fri gosh> (use srfi-43) # gosh> (define x #(1 2 3)) x gosh> (vector-reverse! x) # gosh> x #(3 2 1) gosh> (define x #(1 2 3)) x gosh> (vector-reverse! x 1 2) # gosh> x #(1 2 3) gosh> (vector-reverse! x 0 2) # gosh> x #(2 1 3) gosh> (define x #(1 2 3)) x gosh> (vector-reverse! x 0 3) # gosh> x #(3 2 1) end が、なぜこうなるんだっけ? !2006-04-20 Thu gosh> (use srfi-43) # gosh> (define x #(1 2 3)) x gosh> (vector-swap! x 0 1) # gosh> x #(2 1 3) 使い方が不明だったので検索してしまったが、 分かってしまえば単純だった… !2006-04-19 Wed gosh> (use srfi-43) # gosh> (vector-every (lambda (x) (> x 0)) #(1 2 3 4)) #t gosh> (vector-every (lambda (x) (> x 1)) #(1 2 3 4)) #f !2006-04-18 Tue gosh> (use srfi-43) # gosh> (vector-any (lambda (x) (> x 1)) #(1 2 3 4)) #t gosh> (vector-any (lambda (x) (> x 5)) #(1 2 3 4)) #f !2006-04-17 Mon gosh> (use srfi-43) # gosh> (vector-binary-search #(1 2 3) 2 eq?) *** ERROR: Erroneous value (# #t) (while calling (# for #)) Stack Trace: 使い方が分からない… !2006-04-16 Sun gosh> (use srfi-43) # gosh> (vector-skip (lambda (x) (> x 1)) #(1 2 3 4)) 0 gosh> (vector-skip (lambda (x) (> x 0)) #(1 2 3 4)) #f gosh> (vector-skip (lambda (x) (> x 1)) #(2 3 1 4)) 2 gosh> (vector-skip-right (lambda (x) (> x 1)) #(1 2 3 4)) 0 gosh> (vector-skip-right (lambda (x) (> x 0)) #(1 2 3 4)) #f gosh> (vector-skip-right (lambda (x) (> x 1)) #(2 3 1 4)) 2 何をするもの? 偽のものの index を出す? !2006-04-15 Sat gosh> (use srfi-43) # gosh> (vector-index (lambda (x) (> x 1)) #(1 2 3 4)) 1 gosh> (vector-index-right (lambda (x) (> x 1)) #(1 2 3 4)) 3 !2006-04-14 Fri gosh> (use srfi-43) # gosh> (vector-count (lambda (i x) (> x 1)) #(1 2 3 4)) 3 !2006-04-13 Thu gosh> (use srfi-43) # gosh> (vector-for-each (lambda (i x) (display (format "~d ~d\n" i x))) #(1 2 3)) 0 1 1 2 2 3 # gosh> (vector-for-each (lambda (i x y) (display (format "~d ~d ~d\n" i x y))) #(1 2 3) #(4 5 6)) 0 1 4 1 2 5 2 3 6 # gosh> (vector-for-each (lambda (i x y) (display (format "~d ~d ~d\n" i x y))) #(1 2 3) #(4 5 6 7)) 0 1 4 1 2 5 2 3 6 # gosh> (vector-for-each (lambda (i x y) (display (format "~d ~d ~d\n" i x y))) #(1 2 3 4) #(5 6 7)) 0 1 5 1 2 6 2 3 7 # !2006-04-12 Wed gosh> (use srfi-43) # gosh> (define x #(1 2 3)) x gosh> (vector-map (lambda (i x) (* x x)) x) #(1 4 9) gosh> x #(1 2 3) gosh> (vector-map! (lambda (i x) (* x x)) x) # gosh> x #(1 4 9) !2006-04-11 Tue gosh> (use srfi-43) # gosh> (vector-map (lambda (x y) (format "~S ~S" x y)) #(1 2 3)) #("0 1" "1 2" "2 3") gosh> (vector-map (lambda (i x) (cons i (* x x))) #(1 2 3)) #((0 . 1) (1 . 4) (2 . 9)) gosh> (vector-map (lambda (i x) (* x x)) #(1 2 3)) #(1 4 9) !2006-04-10 Mon gosh> (use srfi-43) # gosh> (vector-fold-right cons* '() #(a b c) #(1 2 3 4 5)) *** ERROR: unbound variable: cons* gosh> (use srfi-1) # gosh> (vector-fold-right cons* '() #(a b c) #(1 2 3 4 5)) (0 (1 (2 () c . 3) b . 2) a . 1) gosh> (vector-fold-right cons* '() #(a b c)) (0 (1 (2 () . c) . b) . a) gosh> (vector-fold-right + 0 #(3 1 4 1 5 9)) 38 gosh> (vector-fold-right (lambda (x y z) (format "~S ~S ~S" x y z)) '() #(a b c)) "0 \"1 \\\"2 () c\\\" b\" a" fold-right 自体まったく分かっていないし… !2006-04-09 Sun gosh> (use srfi-43) # gosh> (vector-fold + 0 #(3 1 4 1 5 9)) 38 gosh> (fold + 0 '(3 1 4 1 5 9)) 23 * ? * (0 + 3) + (1 + 1) + (2 + 4) + (3 + 1) + (4 + 5) + (5 + 9) かな? !2006-04-08 Sat gosh> (use srfi-43) # gosh> (vector= = #(1 2 3) #(1 2 3)) #t gosh> (vector= eq? #(1 2 3) #(1 2 3)) #t gosh> (vector= = #(1 2 3) #(4 5 6)) #f !2006-04-07 Fri gosh> (use srfi-43) # gosh> (vector-empty? #()) #t gosh> (vector-empty? #(1 2 3)) #f !2006-04-06 Thu gosh> (use srfi-43) # gosh> (vector-concatenate '(#(1 2 3) #(4 5 6))) #(1 2 3 4 5 6) マニュアルは、「vector-concatenete」だワン! !2006-04-05 Wed gosh> (use srfi-43) # gosh> (vector-append #(1 2 3)) #(1 2 3) gosh> (vector-append #(1 2 3) #(4 5 6)) #(1 2 3 4 5 6) !2006-04-04 Tue gosh> (use srfi-43) # gosh> (vector-reverse-copy #(1 2 3)) #(3 2 1) !2006-04-03 Mon gosh> (use srfi-43) # gosh> (vector-unfold-right (lambda (x) (> x 10)) 10) #(#f #f #f #f #f #f #f #f #f #f) !2006-04-02 Sun gosh> (use srfi-43) # gosh> (vector-unfold (lambda (x) (> x 10)) 10) #(#f #f #f #f #f #f #f #f #f #f) gosh> (vector-unfold (lambda (x) (> x 10)) 10 1) *** ERROR: wrong number of arguments for # (required 1, got 2) * 良い(ちゃんとした)使い方が分からない… * マニュアルの 「seed」 っていうのは、なんだろう? * Gauche-0.8.5 では使えなかったので、Gauche-0.8.6 を入れた !2006-04-01 Sat まんま gosh> (use srfi-11) # gosh> (let ((a 1) (b 2) (c 3) (d 4)) (let*-values (((a b) (values c d)) ((c d) (values a b))) (list a b c d))) (3 4 3 4) !2006-03-31 Fri まんま gosh> (use srfi-11) # gosh> (let-values (((a b) (values 1 2)) ((c d) (values 3 4))) (list a b c d)) (1 2 3 4) gosh> (let ((a 1) (b 2) (c 3) (d 4)) (let-values (((a b) (values c d)) ((c d) (values a b))) (list a b c d))) (3 4 1 2) gosh> (let-values (((x . y) (values 1 2 3 4))) y) (2 3 4) gosh> (let-values ((x (values 1 2 3 4))) x) (1 2 3 4) values を使う時は便利そうだね !2006-03-30 Thu gosh> (use srfi-19) # gosh> (string->date "Wed Mar 29 00:00:00+0000 2006") *** ERROR: wrong number of arguments for #date> (required 2, got 1) Stack Trace: _______________________________________ 0 (string->date "Wed Mar 29 00:00:00+0000 2006") At line 32 of "(stdin)" 1 (string->date "Wed Mar 29 00:00:00+0000 2006") At line 32 of "(stdin)" gosh> (string->date "2006 03 29 00:00:00" "~Y ~m ~d ~H:~M:~S") # template-string がないとダメなのはちょっと面倒だなあ〜 !2006-03-29 Wed gosh> (use srfi-19) # gosh> (date->string (make-date 0 0 0 0 29 3 2006 9)) "Wed Mar 29 00:00:00+0000 2006" gosh> (date->string (make-date 0 0 0 0 29 3 2006 9) "%Y") "%Y" gosh> (date->string (make-date 0 0 0 0 29 3 2006 9) "~Y") "2006" gosh> (date->string (make-date 0 1 2 3 29 3 2006 9) "~Y ~m ~d ~H:~M:~S") "2006 03 29 03:02:01" !2006-03-28 Tue gosh> (use srfi-19) # gosh> (time-utc->date (date->time-utc (make-date 0 0 0 0 28 3 2006 9))) # gosh> (time-utc->julian-day (date->time-utc (make-date 0 0 0 0 28 3 2006 9))) 2453822.4998958334 gosh> (time-utc->modified-julian-day (date->time-utc (make-date 0 0 0 0 28 3 2006 9))) 53821.99989583343 gosh> (time-utc->time-monotonic (date->time-utc (make-date 0 0 0 0 28 3 2006 9))) # gosh> (time-utc->time-tai (date->time-utc (make-date 0 0 0 0 28 3 2006 9))) # time-utc->time-monotonic!, time-utc->time-tai! とばし。 !2006-03-27 Mon gosh> (use srfi-19) # gosh> (time-tai->date (date->time-tai (make-date 0 0 0 0 27 3 2006 9))) # gosh> (time-tai->julian-day (date->time-tai (make-date 0 0 0 0 27 3 2006 9))) 2453821.4998958334 gosh> (time-tai->modified-julian-day (date->time-tai (make-date 0 0 0 0 27 3 2006 9))) 53820.99989583343 gosh> (time-tai->time-monotonic (date->time-tai (make-date 0 0 0 0 27 3 2006 9))) # gosh> (time-tai->time-utc (date->time-tai (make-date 0 0 0 0 27 3 2006 9))) # time-tai->time-monotonic!, time-tai->time-utc! とばし。 !2006-03-26 Sun gosh> (use srfi-19) # gosh> (time-monotonic->date (make-date 0 0 0 0 26 3 2006 9)) *** ERROR: no applicable method for # with arguments (#) gosh> (time-monotonic->date (current-time 'time-monotonic)) # gosh> (time-monotonic->date (date->time-monotonic (make-date 0 0 0 0 26 3 2006 9))) # gosh> (time-monotonic->julian-day (date->time-monotonic (make-date 0 0 0 0 26 3 2006 9))) 2453820.4998958334 gosh> (time-monotonic->modified-julian-day (date->time-monotonic (make-date 0 0 0 0 26 3 2006 9))) 53819.99989583343 gosh> (time-monotonic->time-tai (date->time-monotonic (make-date 0 0 0 0 26 3 2006 9))) # gosh> (time-monotonic->time-tai! (date->time-monotonic (make-date 0 0 0 0 26 3 2006 9))) # gosh> (time-monotonic->time-utc (date->time-monotonic (make-date 0 0 0 0 26 3 2006 9))) # なぜ time-monotonic->time-utc! があるんだ? !2006-03-25 Sat gosh> (use srfi-19) # gosh> (modified-julian-day->date (date->modified-julian-day (make-date 0 0 0 0 25 3 2006 9))) # gosh> (modified-julian-day->time-monotonic (date->modified-julian-day (make-date 0 0 0 0 25 3 2006 9))) # gosh> (modified-julian-day->time-tai (date->modified-julian-day (make-date 0 0 0 0 25 3 2006 9))) # gosh> (modified-julian-day->time-utc (date->modified-julian-day (make-date 0 0 0 0 25 3 2006 9))) # !2006-03-24 Fri gosh> (use srfi-19) # gosh> (julian-day->date (date->julian-day (make-date 0 0 0 0 23 3 2006 9))) # gosh> (julian-day->date (date->julian-day (make-date 0 0 0 0 24 3 2006 9))) # gosh> (julian-day->time-monotonic (date->julian-day (make-date 0 0 0 0 24 3 2006 9))) # gosh> (julian-day->time-tai (date->julian-day (make-date 0 0 0 0 24 3 2006 9))) # gosh> (julian-day->time-utc (date->julian-day (make-date 0 0 0 0 24 3 2006 9))) # !2006-03-23 Thu gosh> (use srfi-19) # gosh> (date->julian-day (make-date 0 0 0 0 23 3 2006 9)) 2453817.4998958334 gosh> (date->modified-julian-day (make-date 0 0 0 0 23 3 2006 9)) 53816.99989583343 gosh> (date->time-monotonic (make-date 0 0 0 0 23 3 2006 9)) # gosh> (date->time-tai (make-date 0 0 0 0 23 3 2006 9)) # gosh> (date->time-utc (make-date 0 0 0 0 23 3 2006 9)) # !2006-03-22 Wed gosh> (use srfi-19) # gosh> (date-year-day (make-date 0 0 0 0 22 3 2006 9)) 81 gosh> (date-week-day (make-date 0 0 0 0 22 3 2006 9)) 3 gosh> (date-week-number (make-date 0 0 0 0 22 3 2006 9) 0) 11 gosh> (date-week-number (make-date 0 0 0 0 22 3 2006 9) 1) 11 gosh> (date-week-number (make-date 0 0 0 0 22 3 2006 9) 8) 11 gosh> (date-week-number (make-date 0 0 0 0 22 3 2006 9) 10) 11 date-week-number の第2引数は何を与えれば? !2006-03-21 Tue gosh> (use srfi-19) # gosh> (date-nanosecond (make-date 0 0 0 0 21 3 2006 9)) 0 gosh> (date-second (make-date 0 0 0 0 21 3 2006 9)) 0 gosh> (date-minute (make-date 0 0 0 0 21 3 2006 9)) 0 gosh> (date-hour (make-date 0 0 0 0 21 3 2006 9)) 0 gosh> (date-day (make-date 0 0 0 0 21 3 2006 9)) 21 gosh> (date-month (make-date 0 0 0 0 21 3 2006 9)) 3 gosh> (date-year (make-date 0 0 0 0 21 3 2006 9)) 2006 gosh> (date-zone-offset (make-date 0 0 0 0 21 3 2006 9)) 9 !2006-03-20 Mon gosh> (use srfi-19) # gosh> (date? (make-date 0 0 0 0 20 3 2006 9)) #t gosh> (date? #t) #f !2006-03-19 Sun subtract-duration とばし。 gosh> (use srfi-19) # gosh> (make-date 0 0 0 0 19 3 2006 9) # gosh> (slot-ref x 'nanosecond) 0 gosh> (slot-ref x 'day) 19 gosh> (slot-ref x 'month) 3 gosh> (slot-ref x 'year) 2006 !2006-03-18 Sat gosh> (use srfi-19) # gosh> (make-time 'time-duration 0 1) # gosh> (define x (current-time)) x gosh> x # gosh> (add-duration x (make-time 'time-duration 0 1)) # gosh> (add-duration! x (make-time 'time-duration 0 1)) # gosh> x # time-duration の作り方が分からなくて調べてしまった…。 !2006-03-17 Fri gosh> (use srfi-19) # gosh> (time-difference (current-time) (current-time)) # gosh> (time-difference! (current-time) (current-time)) # !2006-03-16 Thu gosh> (use srfi-19) # gosh> (time=? (current-time) (current-time)) #f gosh> (time (time<=? (current-time) (current-time)) #t gosh> (time>? (current-time) (current-time)) #f !2006-03-15 Wed gosh> (use srfi-19) # gosh> (define x (current-time)) x gosh> (define y (copy-time x)) y gosh> (time-type x) time-utc gosh> (set-time-type! x time-tai) # gosh> (time-type x) time-tai gosh> (time-type y) time-utc !2006-03-14 Tue gosh> (use srfi-19) # gosh> (define x (current-time)) x gosh> (time-second x) 1143460489 gosh> (set-time-second! x 1) # gosh> (time-second x) 1 !2006-03-13 Mon gosh> (use srfi-19) # gosh> (define x (current-time)) x gosh> x # gosh> (set-time-type! x time-tai) # gosh> x # !2006-03-12 Sun gosh> (use srfi-19) # gosh> (make-time time-utc 1 2) # gosh> (sys-ctime (make-time time-utc 1 2)) "Thu Jan 1 09:00:02 1970\n" !2006-03-11 Sat gosh> (use srfi-19) # gosh> (time-resolution) 10000000 !2006-03-10 Fri gosh> (use srfi-19) # gosh> (current-modified-julian-day) 53821.491761284415 !2006-03-09 Thu gosh> (use srfi-19) # gosh> (current-julian-day) 2453821.9916751175 !2006-03-08 Wed gosh> (use srfi-19) # gosh> (current-date) # !2006-03-07 Tue gosh> (current-time) # gosh> (sys-ctime (current-time)) "Mon Mar 27 20:44:58 2006\n" gosh> (use srfi-19) # gosh> (current-time) # gosh> (sys-ctime (current-time)) "Mon Mar 27 20:45:16 2006\n" gosh> (sys-ctime (current-time time-process)) "Thu Jan 1 09:00:00 1970\n" !2006-03-06 Mon gosh> (use srfi-19) # gosh> time-utc time-utc gosh> time-tai time-tai gosh> time-monotonic time-monotonic gosh> (eq? time-tai time-monotonic) #f gosh> time-duration time-duration gosh> time-process time-process gosh> time-thread time-thread gosh> (eq? time-process time-thread) #f !2006-03-05 Sun gosh> (use srfi-27) # gosh> (random-source-make-reals default-random-source) # gosh> ((random-source-make-reals default-random-source)) 0.8147236863931789 !2006-03-04 Sat gosh> (use srfi-27) # gosh> (random-source-make-integers default-random-source) # gosh> ((random-source-make-integers default-random-source) 3) 2 !2006-03-03 Fri gosh> (use srfi-27) # gosh> (random-source-pseudo-randomize! default-random-source 0 0) # gosh> (random-real) 0.6353574441341173 !2006-03-02 Thu $ gosh gosh> (use srfi-27) # gosh> (random-real) 0.8147236863931789 $ gosh gosh> (use srfi-27) # gosh> (random-real) 0.8147236863931789 $ gosh gosh> (use srfi-27) # gosh> (random-source-randomize! default-random-source) # gosh> (random-real) 0.018906687391946675 !2006-03-01 Wed gosh> (use srfi-27) # gosh> (random-source-state-ref default-random-source) #u32(0 0 ... 0 625) gosh> (random-real) 0.8147236863931789 gosh> (random-source-state-ref default-random-source) #u32(2601187879 3919438689 ... 3518038711 2) !2006-02-28 Tue gosh> (use srfi-27) # gosh> (random-source? #t) #f gosh> (random-source? (make-random-source)) #t gosh> (random-source? default-random-source) #t !2006-02-27 Mon gosh> (use srfi-27) # gosh> (make-random-source) #< 0x826c000> gosh> (make-random-source) #< 0x826d000> !2006-02-26 Sun $ gosh gosh> (use srfi-27) # gosh> (random-real) 0.8147236863931789 gosh> default-random-source #< 0x8256000> $ gosh gosh> (use srfi-27) # gosh> default-random-source #< 0x8256000> gosh> (random-real) 0.8147236863931789 gosh> !2006-02-25 Sat gosh> (use srfi-27) # gosh> (random-real) 0.5472205972559617 gosh> (random-real) 0.18838197400332624 !2006-02-24 Fri 「低レベルな文字列に関する手続き」ばっさり とばし。 gosh> (use srfi-27) # gosh> (random-integer 5) 4 gosh> (random-integer 5) 0 gosh> (random-integer 5) 4 gosh> (random-integer 5) 4 gosh> (random-integer 5) 0 gosh> (random-integer 5) 4 gosh> (random-integer 5) 4 gosh> (random-integer 5) 1 gosh> (random-integer 5) 3 gosh> (random-integer 5) 1 gosh> (random-integer 5) 0 !2006-02-23 Thu gosh> (use srfi-13) # gosh> (string-delete "foo" #\o) "f" gosh> (string-delete "This is a pen." (lambda (c) (char-lower-case? c))) "T ." !2006-02-22 Wed gosh> (use srfi-13) # gosh> (string-filter "foo" #\o) "oo" gosh> (string-filter "foo" #[a-z]) "foo" gosh> (string-filter "This is a pen." (lambda (c) (char-lower-case? c))) "hisisapen" やっと、char/char-set/pred の意味が分かった… !2006-02-21 Tue gosh> (use srfi-13) # gosh> (string-tokenize "foo bar baz") ("foo" "bar" "baz") gosh> (string-tokenize "foo-bar-baz") ("foo-bar-baz") gosh> (string-tokenize "(+ 1 2 3 )") ("(+" "1" "2" "3" ")") gosh> (string-tokenize "foo1 bar2 baz3") ("foo1" "bar2" "baz3") gosh> (string-tokenize "foo1 bar2 baz3" #[a-z]) ("foo" "bar" "baz") gosh> (string-tokenize "foo1 bar2 baz3" #[a-z0-9]) ("foo1" "bar2" "baz3") !2006-02-20 Mon gosh> (use srfi-13) # gosh> (string-replace "foo" "hoge" 0 1) "hogeoo" gosh> (string-replace "foo" "hoge" 0 5) *** ERROR: end argument must be equal to or greater than the start argument: start=5, end=3 gosh> (string-replace "foo" "hoge" 0 -1) *** ERROR: start argument needs to be positive: -1 string-replace s1 s2 start1 end2 &optional start2 end2 の最初の end2 は、end1 の間違い? !2006-02-19 Sun 良く分からないので、またカンニング。 まんま。 gosh> (use srfi-13) # gosh> (let ((s (make-string 10 #\Z))) (string-xcopy! s 2 "abcdef" 2) s) "ZZcdefabZZ" 最初の 2 は s の 2 から、 次の 2 は "abcdef" の 2 からという意味らしい。 gosh> (let ((s (make-string 10 #\Z))) (string-xcopy! s 2 "abcdef" 3) s) "ZZdefabcZZ" gosh> (let ((s "")) (string-xcopy! s 2 "abcdef" 3) s) *** ERROR: attempted to modify immutable string: "" やっぱり、"" で作った文字列は immutable なんだよなあ〜 gosh> (let ((s (string-copy ""))) (string-xcopy! s 2 "abcdef" 3) s) *** ERROR: substitution string too long: "defabc" gosh> (let ((s (string-copy "0123456789"))) (string-xcopy! s 2 "abcdef" 3) s) "01defabc89" なにがなんだか。 !2006-02-18 Sat gosh> (use srfi-13) # gosh> (xsubstring "abc" 0) "abc" gosh> (xsubstring "abc" 1) "bca" gosh> (xsubstring "abc" 3) "abc" gosh> (xsubstring "abc" 4) "bca" gosh> (xsubstring "abc" -1) "cab" !2006-02-17 Fri gosh> (use srfi-13) # gosh> (string-for-each-index (lambda (i) (print i)) "foo") 0 1 2 #t !2006-02-16 Thu gosh> (use srfi-13) # gosh> (string-for-each (lambda (x) (print x)) "foo") f o o # !2006-02-15 Wed まんま gosh> (use srfi-13) # gosh> (string-unfold-right null? car cdr '(#\h #\e #\l #\l #\o)) "olleh" !2006-02-14 Tue 良く分からなかったので、カンニング…。 まんま gosh> (use srfi-13) # gosh> (string-unfold null? car cdr '(#\h #\e #\l #\l #\o)) "hello" !2006-02-13 Mon gosh> (use srfi-13) # gosh> (string-fold-right (lambda (x y) (string-append y (string x))) "" "foo") "oof" !2006-02-12 Sun gosh> (use srfi-13) # gosh> (string-fold (lambda (x y) (string-append y (string x))) "" "foo") "foo" gosh> (string-fold (lambda (x y) (string-append y (string x))) "a" "foo") "afoo" 良い例が… !2006-02-11 Sat まんま gosh> (use srfi-13) # gosh> (string-map char-upcase "wikiwiki") "WIKIWIKI" gosh> (let ((s (string-copy "wikiwiki"))) (string-map! char-upcase s 4) s) "wikiWIKI" !2006-02-10 Fri gosh> (use srfi-13) # gosh> (string-concatenate-reverse '("humuhumu" "nukunuku" "apua" "`a")) "`aapuanukunukuhumuhumu" gosh> (string-concatenate-reverse/shared '("humuhumu" "nukunuku" "apua" "`a")) "`aapuanukunukuhumuhumu" !2006-02-09 Thu gosh> (use srfi-13) # gosh> (string-concatenate/shared '("humuhumu" "nukunuku" "apua" "`a")) "humuhumunukunukuapua`a" gosh> (string-append/shared "humuhumu" "nukunuku" "apua" "`a") "humuhumunukunukuapua`a" !2006-02-08 Wed まんま gosh> (use srfi-13) # gosh> (string-concatenate '("humuhumu" "nukunuku" "apua" "`a")) "humuhumunukunukuapua`a" !2006-02-07 Tue まんま gosh> (use srfi-13) # gosh> (string-reverse "mahalo") "olaham" gosh> (string-reverse "mahalo" 3) "ola" gosh> (string-reverse "mahalo" 1 4) "aha" gosh> (let ((s (string-copy "mahalo"))) (string-reverse! s 1 5) s) "mlahao" !2006-02-06 Mon gosh> (use srfi-13) # gosh> (string-downcase "FOO BAR") "foo bar" !2006-02-05 Sun gosh> (use srfi-13) # gosh> (string-upcase "foo bar") "FOO BAR" !2006-02-04 Sat gosh> (use srfi-13) # gosh> (string-titlecase "foo bar") "Foo Bar" gosh> (string-titlecase "foo bar" 0) "Foo Bar" gosh> (string-titlecase "foo bar" 1) "Oo Bar" gosh> (string-titlecase! "foo bar") *** ERROR: attempted to modify immutable string: "foo bar" Stack Trace: _______________________________________ 0 (string-substitute! s start (string-titlecase s start end)) At line 86 of "/usr/local/share/gauche/0.8.5/lib/srfi-13/casemap.scm" 1 (string-substitute! s start (string-titlecase s start end)) At line 86 of "/usr/local/share/gauche/0.8.5/lib/srfi-13/casemap.scm" gosh> (define x "foo bar") x gosh> (string-titlecase! x) *** ERROR: attempted to modify immutable string: "foo bar" Stack Trace: _______________________________________ 0 (string-substitute! s start (string-titlecase s start end)) At line 86 of "/usr/local/share/gauche/0.8.5/lib/srfi-13/casemap.scm" 1 (string-substitute! s start (string-titlecase s start end)) At line 86 of "/usr/local/share/gauche/0.8.5/lib/srfi-13/casemap.scm" gosh> x "foo bar" あれ? immutable でない string ってなんだっけ? !2006-02-03 Fri gosh> (use srfi-13) # gosh> (string-contains "foo bar" "bar") 4 gosh> (string-contains "foo bar" "hoge") #f !2006-02-02 Thu gosh> (use srfi-13) # gosh> (string-skip "foo" #\f) 1 gosh> (string-skip "foo bar" #[a-z]) 3 gosh> (string-skip "foo bar baz" #[a-z] 4) 7 gosh> (string-count "foo" #\o) 2 gosh> (string-count "foo" #[\w]) 3 !2006-02-01 Wed gosh> (use srfi-13) # gosh> (string-index-right "foo" #\o) 2 gosh> (string-index "foo" #\o) 1 gosh> (string-index-right "Aloha oe" #\o 3) 6 rindex とかの r って reverse だと ずーと思っていたのだけど、もしかして、right だった? !2006-01-31 Tue まんま gosh> (use srfi-13) # gosh> (string-index "Aloha oe" #\a) 4 gosh> (string-index "Aloha oe" #[Aa]) 0 gosh> (string-index "Aloha oe" #[\s]) 5 gosh> (string-index "Aloha oe" char-lower-case?) 1 gosh> (string-index "Aloha oe" #\o 3) 6 !2006-01-30 Mon gosh> (use srfi-13) # gosh> (string-suffix? "foo" "barfoo") #t gosh> (string-suffix? "foo" "foobar") #f gosh> (string-suffix? "foo" "barFOO") #f gosh> (string-suffix-ci? "foo" "barFOO") #t そうそう、ci っていうのは、case ignore あたりなんだっけ? !2006-01-29 Sun gosh> (use srfi-13) # gosh> (string-prefix? "foo" "foobar") #t gosh> (string-prefix? "fooa" "foobar") #f !2006-01-28 Sat gosh> (use srfi-13) # gosh> (string-prefix-length "foo" "foobar") 3 gosh> (string-suffix-length "foo.c" "bar.c") 2 gosh> (string-prefix-length "foo" "FOOBAR") 0 gosh> (string-prefix-length-ci "foo" "FOOBAR") 3 gosh> (string-suffix-length "foo.c" "bar.C") 0 gosh> (string-suffix-length-ci "foo.c" "bar.C") 2 名前だけからは動作が想像できなかった… !2006-01-27 Fri gosh> (use srfi-13) # gosh> (string-hash "foo") 101574 gosh> (string-hash-ci "foo") 69798 gosh> (string-hash-ci "FOO") 69798 !2006-01-26 Thu gosh> (use srfi-13) # gosh> (string= "foo" "FOO") #f gosh> (string-ci= "foo" "FOO") #t !2006-01-25 Wed gosh> (use srfi-13) # gosh> (string= "foo" "foo") #t gosh> (string= "foo" "bar") #f gosh> (string<> "foo" "bar") #t gosh> (string<> "foo" "foo") #f gosh> (string< "boo" "foo") #t gosh> (string<= "foo" "foo") #t gosh> (string<= "boo" "foo") #t gosh> (string= "boo" "foo" 1 2 1 2) #t !2006-01-24 Tue gosh> (use srfi-13) # gosh> (string-compare-ci "foo" "foo" values values values) 2 gosh> (string-compare-ci "foo" "FOO" values values values) 2 !2006-01-23 Mon gosh> (use srfi-13) # gosh> (string-compare "foo" "bar" values values values) 0 gosh> (values 1) 1 gosh> (values "foo") "foo" gosh> (string-compare "foo" "foo" values values values) 2 gosh> (string-compare "foo" "fOO" values values values) 1 gosh> (string-compare "foo" "fOO" values values values 0 1 0 1) 0 gosh> (string-compare "foo" "foO" values values values 0 1 0 1) 0 何が何だか? !2006-01-22 Sun まんま gosh> (use srfi-13) # gosh> (string-trim " abc ") "abc " gosh> (string-trim-right " abc ") " abc" gosh> (string-trim-both " abc ") "abc" !2006-01-21 Sat まんま gosh> (use srfi-13) # gosh> (string-pad "abc" 10) " abc" gosh> (string-pad "abcdefg" 3) "efg" gosh> (string-pad-right "abc" 10) "abc " gosh> (string-pad "abcdefg" 10 #\+ 2 5) "+++++++cde" !2006-01-20 Fri まんま gosh> (use srfi-13) # gosh> (string-take "abcde" 2) "ab" gosh> (string-drop "abcde" 2) "cde" gosh> (string-take-right "abcde" 2) "de" gosh> (string-drop-right "abcde" 2) "abc" !2006-01-19 Thu ほぼ、まんま gosh> (use srfi-13) # gosh> (define s (string-copy "abcde")) s gosh> (string-copy! s 2 "ZZ") "abZZe" gosh> s "abZZe" gosh> (string-copy! s 2 "ZZZZ") *** ERROR: copy operation runs off the target string: "abZZe" !2006-01-18 Wed gosh> (use srfi-13) # gosh> (substring/shared "foo") "foo" gosh> (substring/shared "foo" 0 0) "" gosh> (substring/shared "foo" 0 1) "f" gosh> (substring/shared "foo" 0 5) *** ERROR: end argument is out of range: 5 !2006-01-17 Tue gosh> (use srfi-13) # gosh> (reverse-list->string '(#\a #\b #\c)) "cba" !2006-01-16 Mon まんま gosh> (use srfi-13) # gosh> (string-tabulate (lambda (i) (integer->char (+ i #x30))) 10) "0123456789" !2006-01-15 Sun gosh> (use srfi-13) # gosh> (string-any #\f "") #f gosh> (string-any #\f "foo") #t !2006-01-14 Sat gosh> (use srfi-13) # gosh> (string-every 'char "") *** ERROR: argument needs to be either a character, a char-set, or a procedure: char gosh> (string-every #\a "") #t gosh> (string-every #\a "foo") #f gosh> (string-every #\a "aaa") #t !2006-01-13 Fri gosh> (use srfi-13) # gosh> (string-null? "") #t gosh> (string-null? "foo") #f !2006-01-12 Thu gosh> (use srfi-1) # gosh> (lset-diff+intersection eq? '(a b c) '(a b c d)) () (a b c) gosh> (lset-diff+intersection eq? '(a b c) '(d e f)) (a b c) () !2006-01-11 Wed gosh> (use srfi-1) # gosh> (lset-xor eq? '(a b c) '(a b c)) () gosh> (lset-xor eq? '(a b c) '(a b c d)) (d) gosh> (lset-xor eq? '(a b c) '(d e f)) (d e f a b c) !2006-01-10 Tue gosh> (use srfi-1) # gosh> (lset-difference eq? '(a b c) '(a b c d)) () gosh> (lset-difference eq? '(a b c) '(d e f)) (a b c) gosh> (lset-difference eq? '(a b c d) '(a b c)) (d) !2006-01-09 Mon gosh> (use srfi-1) # gosh> (lset-intersection eq? '(a b c) '(a b c d)) (a b c) gosh> (lset-intersection eq? '(a b c) '(d e f)) () !2006-01-08 Sun gosh> (use srfi-1) # gosh> (lset-union eq? '(a b c) '(d e f)) (f e d a b c) !2006-01-07 Sat まんま gosh> (use srfi-1) # gosh> (lset-adjoin eq? '(a b c) 'a 'e) (e a b c) !2006-01-06 Fri まんま gosh> (use srfi-1) # gosh> (lset= eq? '(b e a) '(a e b) '(e e b a)) #t !2006-01-05 Thu gosh> (use srfi-1) # gosh> (lset<= eq? '(a b c) '(a b c d) '(a b c d e)) #t gosh> (lset<= eq? '(a b c) '(a b)) #f !2006-01-04 Wed gosh> (use srfi-1) # gosh> (define a (list (cons 'a 'b) (cons 'c 'd))) a gosh> (alist-delete 'a a) ((c . d)) gosh> a ((a . b) (c . d)) gosh> (alist-delete 'z a) ((a . b) (c . d)) gosh> (alist-delete! 'a a) ((c . d)) gosh> a ((a . b) (c . d)) マニュアルの 変更してしまうことがあります とは? !2006-01-03 Tue まんま gosh> (use srfi-1) # gosh> (define a (list (cons 'a 'b) (cons 'c 'd))) a gosh> (define b (alist-copy a)) b gosh> (set-cdr! (car a) 'z) # gosh> a ((a . z) (c . d)) gosh> b ((a . b) (c . d)) definea になっとるぞー !2006-01-02 Mon gosh> (use srfi-1) # gosh> (alist-cons 'foo 1 '()) ((foo . 1)) gosh> (alist-cons 'bar 2 '((foo . 1))) ((bar . 2) (foo . 1)) !2006-01-01 Sun gosh> (use srfi-1) # gosh> (delete-duplicates '(1 2 3 1 11 1)) (1 2 3 11) gosh> (delete-duplicates '(1 2 3 1 11 1) (lambda (x y) #t)) (1) !2005-12-31 Sat gosh> (use srfi-1) # gosh> (delete 1 '(1 2 3)) (2 3) gosh> (delete 1 '(1 2 3) (lambda (x y) #t)) () !2005-12-30 Fri gosh> (use srfi-1) # gosh> (list-index (lambda (x) (< x 0)) '(4 3 2 1 0 -1 -2 -3)) 5 !2005-12-29 Thu gosh> (use srfi-1) # gosh> (every (lambda (x) (> x 0)) '(4 3 2 1)) #t gosh> (every (lambda (x) (> x 0)) '(4 3 2 1 0)) #f !2005-12-28 Wed gosh> (use srfi-1) # gosh> (any (lambda (x) (< x 0)) '(4 3 2 1 0)) #f gosh> (any (lambda (x) (< x 0)) '(4 3 2 1 0 -1 -2 -3)) #t !2005-12-27 Tue gosh> (use srfi-1) # gosh> (break (lambda (x) (< x 0)) '(4 3 2 1 0 -1 -2 -3)) (4 3 2 1 0) (-1 -2 -3) gosh> (break (lambda (x) (> x 0)) '(4 3 2 1 0 -1 -2 -3)) () (4 3 2 1 0 -1 -2 -3) !2005-12-26 Mon gosh> (use srfi-1) # gosh> (span (lambda (x) (< x 0)) '(4 3 2 1 0 -1 -2 -3)) () (4 3 2 1 0 -1 -2 -3) gosh> (span (lambda (x) (> x 0)) '(4 3 2 1 0 -1 -2 -3)) (4 3 2 1) (0 -1 -2 -3) !2005-12-25 Sun gosh> (use srfi-1) # gosh> (drop-while (lambda (x) (> x 0)) '(4 3 2 1 0 -1 -2 -3)) (0 -1 -2 -3) !2005-12-24 Sat gosh> (use srfi-1) # gosh> (take-while (lambda (x) (< x 0)) '(4 3 2 1 0 -1 -2 -3)) () gosh> (take-while (lambda (x) (> x 0)) '(4 3 2 1 0 -1 -2 -3)) (4 3 2 1) !2005-12-23 Fri gosh> (find-tail (lambda (x) (< x 0)) '(4 3 2 1 0 -1 -2 -3)) *** ERROR: unbound variable: find-tail Stack Trace: _______________________________________ 0 (find-tail (lambda (x) (< x 0)) '(4 3 2 1 0 -1 -2 -3)) At line 1 of "(stdin)" 1 (find-tail (lambda (x) (< x 0)) '(4 3 2 1 0 -1 -2 -3)) At line 1 of "(stdin)" gosh> (use srfi-1) # gosh> (find-tail (lambda (x) (< x 0)) '(4 3 2 1 0 -1 -2 -3)) (-1 -2 -3) !2005-12-22 Thu gosh> (find (lambda (x) (< x 0)) '(4 3 2 1 0 -1 -2 -3)) -1 gosh> (use srfi-1) # gosh> (find (lambda (x) (< x 0)) '(4 3 2 1 0 -1 -2 -3)) -1 !2005-12-21 Wed まんま gosh> (use srfi-1) # gosh> (partition odd? '(3 1 4 5 9 2 6)) (3 1 5 9) (4 2 6) !2005-12-20 Tue まんま gosh> (use srfi-1) # gosh> (remove odd? '(3 1 4 5 9 2 6)) (4 2 6) !2005-12-19 Mon まんま gosh> (use srfi-1) # gosh> (filter odd? '(3 1 4 5 9 2 6)) (3 1 5 9) !2005-12-18 Sun まんま gosh> (use srfi-1) # gosh> (filter-map (lambda (x) (and (number? x) (* x x))) '(a 1 b 3 c 7)) (1 9 49) なんか違和感があると思ったら、 「少なくとも」でなく「少くとも」という送り仮名だったからか。 !2005-12-17 Sat map-in-order とばし。 gosh> (use srfi-1) # gosh> (pair-for-each (lambda (x) (print (length x))) '(1 2 3)) 3 2 1 # !2005-12-16 Fri gosh> (use srfi-1) # gosh> (define x '(1 2 3)) x gosh> (map! (lambda (x y) (+ x y)) x '(4 5 6)) (5 7 9) gosh> x (5 7 9) !2005-12-15 Thu gosh> (use srfi-1) # gosh> (append-map (lambda (x) (list (+ x 1))) '(1 2 3)) (2 3 4) gosh> (map (lambda (x) (+ x 1)) '(1 2 3)) (2 3 4) gosh> (append-map (lambda (x y) (list (+ x y))) '(1 2 3) '(4 5 6)) (5 7 9) gosh> (map (lambda (x y) (+ x y)) '(1 2 3) '(4 5 6)) (5 7 9) この例だと map でも良いことにならないか? !2005-12-14 Wed まんま (test/srfi.scm) gosh> (use srfi-1) # gosh> (unfold-right zero? (lambda (x) (* x x)) (lambda (x) (- x 1)) 10) (1 4 9 16 25 36 49 64 81 100) !2005-12-13 Tue まんま (test/srfi.scm) gosh> (use srfi-1) # gosh> (unfold (lambda (x) (> x 10)) (lambda (x) (* x x)) (lambda (x) (+ x 1)) 1) (1 4 9 16 25 36 49 64 81 100) !2005-12-12 Mon gosh> (use srfi-1) # gosh> (reduce-right cons '() '(a b c d e)) (a b c d . e) gosh> (reduce-right cons* '() '(a b c) '(1 2 3 4 5)) *** ERROR: wrong number of arguments for # (required 3, got 4) !2005-12-11 Sun gosh> (use srfi-1) # gosh> (reduce + 0 '(3 1 4 1 5 9)) 23 gosh> (reduce cons '() '(a b c d e)) (e d c b . a) gosh> (reduce cons* '() '(a b c) '(1 2 3 4 5)) *** ERROR: wrong number of arguments for # (required 3, got 4) gosh> (reduce cons* '() '(a b c) '(1 2 3)) *** ERROR: wrong number of arguments for # (required 3, got 4) !2005-12-10 Sat gosh> (use srfi-1) # gosh> (pair-fold cons '() '(a b c d e)) (#0=(e) #1=(d . #0#) #2=(c . #1#) #3=(b . #2#) (a . #3#)) ? car でなくて、cdr らしいのだが。 pair-fold-right とばし。 !2005-12-09 Fri まんま gosh> (fold-right cons '() '(a b c d e)) (a b c d e) gosh> (use srfi-1) # gosh> (fold-right cons* '() '(a b c) '(1 2 3 4 5)) (a 1 b 2 c 3) !2005-12-08 Thu まんま gosh> fold # gosh> (fold + 0 '(3 1 4 1 5 9)) 23 gosh> (fold cons '() '(a b c d e)) (e d c b a) gosh> (fold cons* '() '(a b c) '(1 2 3 4 5)) *** ERROR: unbound variable: cons* gosh> (use srfi-1) # gosh> (fold cons* '() '(a b c) '(1 2 3 4 5)) (c 3 b 2 a 1) !2005-12-07 Wed まんま gosh> (use srfi-1) # gosh> (count even? '(3 1 4 1 5 9 2 5 6)) 3 gosh> (count < '(1 2 4 8) '(2 4 6 8 10 12 14 16)) 3 gosh> (count < '(3 1 4 1) (circular-list 1 10)) 2 !2005-12-06 Tue まんま gosh> (use srfi-1) # gosh> (unzip2 '((1 one) (2 two) (3 three))) (1 2 3) (one two three) !2005-12-05 Mon まんま gosh> (use srfi-1) # gosh> (zip '(one two three) '(1 2 3) '(odd even odd even odd even odd even)) ((one 1 odd) (two 2 even) (three 3 odd)) gosh> (zip '(3 1 4 1) (circular-list #f #t)) ((3 #f) (1 #t) (4 #f) (1 #t)) !2005-12-04 Sun gosh> (use srfi-1) # gosh> (append-reverse '(1 2 3) 2) (3 2 1 . 2) gosh> (append-reverse '(1 2 3) '(4 5 6)) (3 2 1 4 5 6) !2005-12-03 Sat gosh> (use srfi-1) # gosh> (concatenate '((1 2 3) (4 5 6))) (1 2 3 4 5 6) gosh> (concatenate '((1 2 3) (4 5 6 7))) (1 2 3 4 5 6 7) gosh> (concatenate '((1 2 3) (4 5 6) (7 8 9))) (1 2 3 4 5 6 7 8 9) !2005-12-02 Fri gosh> (use srfi-1) # gosh> (length+ '(1 2 3)) 3 gosh> (length+ 1) 0 gosh> (length+ #f) 0 gosh> (length '(1 2 3)) 3 gosh> (length 1) *** ERROR: proper list required, but got 1 gosh> (proper-list? 1) #f gosh> (proper-list? #f) #f gosh> (length+ '(1 . 2)) 1 gosh> (length+ (circular-list 'z 'q)) #f ちょっと、 x が真性リストなら、その長さを返します。さもなければ、 #f を返します。 とは違っているような気もするが? !2005-12-01 Thu gosh> (last-pair '(1 2 3)) (3) gosh> (use srfi-1) # gosh> (last '(1 2 3)) 3 !2005-11-30 Wed gosh> (use srfi-1) # gosh> (split-at '(a b c d e) 2) (a b) (c d e) !2005-11-29 Tue gosh> (use srfi-1) # gosh> (define x '(a b c d e)) x gosh> (drop-right! x 2) (a b c) gosh> x (a b c) !2005-11-28 Mon gosh> (use srfi-1) # gosh> (take! '(a b c d e) 2) (a b) gosh> (define x '(a b c d e)) x gosh> (take x 2) (a b) gosh> x (a b c d e) gosh> (take! x 2) (a b) gosh> x (a b) !2005-11-27 Sun まんま gosh> (use srfi-1) # gosh> (take-right '(a b c d e) 2) (d e) gosh> (drop-right '(a b c d e) 2) (a b c) gosh> (take-right '(1 2 3 . d) 2) (2 3 . d) gosh> (drop-right '(1 2 3 . d) 2) (1) gosh> (take-right '(1 2 3 . d) 0) d gosh> (drop-right '(1 2 3 . d) 0) (1 2 3) !2005-11-26 Sat まんま gosh> (use srfi-1) # gosh> (take '(a b c d e) 2) (a b) gosh> (drop '(a b c d e) 2) (c d e) gosh> (take '(1 2 3 . d) 2) (1 2) gosh> (drop '(1 2 3 . d) 2) (3 . d) gosh> (drop '(1 2 3 . d) 3) d gosh> (take '(a b c d e) 10) *** ERROR: pair required, but got () !2005-11-25 Fri gosh> (use srfi-1) # gosh> (car+cdr '(1 2)) 1 (2) !2005-11-24 Thu gosh> (use srfi-1) # gosh> (fourth '(1 2 3 4)) 4 この辺で勘弁しといたる。 ということで、fifth 〜 tenth とばし。 !2005-11-23 Wed gosh> (use srfi-1) # gosh> (third '(1 2)) *** ERROR: pair required, but got () Stack Trace: _______________________________________ gosh> (third '(1 2 3)) 3 !2005-11-22 Tue gosh> (use srfi-1) # gosh> (second '(1 2)) 2 gosh> (second '(1 . 2)) *** ERROR: pair required, but got 2 !2005-11-21 Mon gosh> (use srfi-1) # gosh> (first '(1 2)) 1 gosh> (first '(1 . 2)) 1 !2005-11-20 Sun gosh> (use srfi-1) # gosh> (list= '(1 2) '(1 2)) #t !2005-11-19 Sat gosh> (use srfi-1) # gosh> (not-pair? '()) #t gosh> (not-pair? '(1 2)) #f gosh> (not-pair? '(1 . 2)) #f gosh> (not-pair? (circular-list 'z 'q)) #f !2005-11-18 Fri gosh> (null-list? '()) #t gosh> (null-list? '(1 2)) #f !2005-11-17 Thu gosh> (dotted-list? '(1 . 2)) #t gosh> (dotted-list? '(1 2)) #f !2005-11-16 Wed gosh> (use srfi-1) # gosh> (circular-list? '(1 2 3)) #f gosh> (circular-list? (circular-list 'z 'q)) #t !2005-11-15 Tue gosh> (use srfi-1) # gosh> (proper-list? '(1 2 3)) #t gosh> (proper-list? '(1 . 2)) #f gosh> (proper-list? (circular-list 'z 'q)) #f * 「真性リスト」って?循環でないということ? * (use srfi-1) しなくても proper-list? はあるみたい !2005-11-14 Mon まんま gosh> (use srfi-1) # gosh> (iota 5) (0 1 2 3 4) gosh> (iota 5 0 -0.1) (-2.7755575615628914e-17 -0.10000000000000003 -0.20000000000000004 -0.30000000000000004 -0.4) 結果がマニュアルと違うなぁ !2005-11-13 Sun まんま gosh> (use srfi-1) # gosh> (circular-list 'z 'q) #0=(z q . #0#) !2005-11-12 Sat まんま gosh> (use srfi-1) # gosh> (list-tabulate 4 values) (0 1 2 3) !2005-11-11 Fri まんま gosh> (use srfi-1) # gosh> (cons* 1 2 3 4) (1 2 3 . 4) gosh> (cons* 1) 1 gosh> (list* 1 2 3 4) (1 2 3 . 4) gosh> (list* 1) 1 !2005-11-10 Thu gosh> (use srfi-1) # gosh> (xcons 'a 'b) (b . a) !2005-11-09 Wed gosh> (cond-expand (srfi-13 (display "srfi-13") ) (else (display "not srfi-13") )) srfi-13# gosh> (cond-expand (hoge (display "hoge") ) (else (display "not hoge") )) not hoge# !2005-11-08 Tue with-input-conversion, with-output-conversion とばし。 wrap-with-output-conversion とばし。 gosh> (use gauche.charconv) # gosh> (call-with-output-file "zzzzz.txt" (lambda (out) (copy-port (wrap-with-input-conversion (open-input-file "zzzz.txt") "*jp" ;guess code :to-code "eucjp" :owner? #t) ;close unknown.txt afterwards out))) 6 理解はしていない… !2005-11-07 Mon gosh> (use gauche.charconv) # gosh> (call-with-output-conversion (current-output-port) display) ## gosh> (call-with-output-conversion (current-output-port) (lambda (x) (display x))) ## ? !2005-11-06 Sun gosh> (use gauche.charconv) # gosh> (call-with-input-conversion (current-input-port) read) "あ" "あ" !2005-11-05 Sat open-output-conversion-port とばし。 gosh> (use gauche.charconv) # gosh> (ces-convert "あいう" "*JP") "あいう" gosh> (ces-convert "あいう" 'shift_jis) "..." !2005-11-04 Fri まんま gosh> (use gauche.charconv) # gosh> (call-with-output-file "output.txt" (lambda (out) (copy-port (open-input-conversion-port (open-input-file "sjis.txt") "*jp" ;guess code :to-code "eucjp" :owner? #t) ;close unknown.txt afterwards out))) 6 !2005-11-03 Thu gosh> (use gauche.charconv) # gosh> (ces-guess-from-string "こんにちは" "*JP") "EUC-JP" !2005-11-02 Wed まんま gosh> (use gauche.charconv) # gosh> (ces-upper-compatible? "eucjp" "ASCII") #t gosh> (ces-upper-compatible? "eucjp" "utf-8") #f gosh> (ces-upper-compatible? "utf-8" "NoSuchEncoding" '?) ? !2005-11-01 Tue まんま gosh> (use gauche.charconv) # gosh> (ces-equivalent? 'eucjp "EUC-JP") #t gosh> (ces-equivalent? 'shift_jis "EUC-JP") #f gosh> (ces-equivalent? "NoSuchEncoding" 'utf-8 '?) ? !2005-10-31 Mon gosh> (use gauche.charconv) # gosh> (ces-conversion-supported? "none" "none") #t gosh> (ces-conversion-supported? "none" "euc-jp") #t gosh> (ces-conversion-supported? (gauche-character-encoding) "euc-jp") #t #f を返す例を思い浮かばない… gosh> (ces-conversion-supported? "hoge" "hogehoge") #f 例外が発生するわけじゃないのか !2005-10-30 Sun gosh> (use gauche.array) # gosh> (array-div-elements #,( (0 2 0 2) 1 2 3 4) 2) #,( (0 2 0 2) 0.5 1 1.5 2) gosh> (array-div-elements #,( (0 2 0 2) 2 4 6 8) #,( (0 2 0 2) 1 2 3 4)) #,( (0 2 0 2) 2 2 2 2) gosh> (define x #,( (0 2 0 2) 1 2 3 4)) x gosh> (array-div-elements! x 2) #t gosh> x #,( (0 2 0 2) 0.5 1 1.5 2) !2005-10-29 Sat gosh> (use gauche.array) # gosh> (array-mul-elements #,( (0 2 0 2) 1 2 3 4) 2) #,( (0 2 0 2) 2 4 6 8) gosh> (array-mul-elements #,( (0 2 0 2) 1 2 3 4) #,( (0 2 0 2) 1 2 3 4)) #,( (0 2 0 2) 1 4 9 16) gosh> (define x #,( (0 2 0 2) 1 2 3 4)) x gosh> (array-mul-elements! x 2) #t gosh> x #,( (0 2 0 2) 2 4 6 8) !2005-10-28 Fri gosh> (use gauche.array) # gosh> (array-sub-elements #,( (0 2 0 2) 1 2 3 4) 2) #,( (0 2 0 2) -1 0 1 2) gosh> (array-sub-elements #,( (0 2 0 2) 1 2 3 4) #,( (0 2 0 2) 1 2 3 4)) #,( (0 2 0 2) 0 0 0 0) gosh> (define x #,( (0 2 0 2) 1 2 3 4)) x gosh> (array-sub-elements! x 2) #t gosh> x #,( (0 2 0 2) -1 0 1 2) !2005-10-27 Thu gosh> (use gauche.array) # gosh> (array-add-elements #,( (0 2 0 2) 1 2 3 4) 2) #,( (0 2 0 2) 3 4 5 6) gosh> (array-add-elements #,( (0 2 0 2) 1 2 3 4) #,( (0 2 0 2) 1 2 3 4)) #,( (0 2 0 2) 2 4 6 8) gosh> (define x #,( (0 2 0 2) 1 2 3 4)) x gosh> (array-add-elements! x 2) #t gosh> x #,( (0 2 0 2) 3 4 5 6) !2005-10-26 Wed gosh> (use gauche.array) # gosh> (array-div-right #,( (0 2 0 2) 2 4 6 8) #,( (0 2 0 2) 1 2 3 4)) #,( (0 2 0 2) 2.0 0.0 0.0 2.0) ? !2005-10-25 Tue gosh> (use gauche.array) # gosh> (array-div-left #,( (0 2 0 2) 2 4 6 8) #,( (0 2 0 2) 1 2 3 4)) #,( (0 2 0 2) 2 0 0.0 2.0) gosh> (array-div-left #,( (0 2 0 2) 1 2 3 4) #,( (0 2 0 2) 2 4 6 8)) #,( (0 2 0 2) 0.5 0.0 0.0 0.5) 何をどう割っているんだ? !2005-10-24 Mon gosh> (use gauche.array) # gosh> (array-expt #,( (0 2 0 2) 0 1 2 3) 2) #,( (0 2 0 2) 2 3 6 11) 何? !2005-10-23 Sun gosh> (use gauche.array) # gosh> (array-mul #,( (0 2 0 2) 0 1 2 3) #,( (0 2 0 2) 4 5 6 7)) #,( (0 2 0 2) 6 7 26 31) !2005-10-22 Sat gosh> (use gauche.array) # gosh> (determinant #,( (0 2 0 2) 0 1 2 3)) -2 gosh> (define x #,( (0 2 0 2) 0 1 2 3)) x gosh> (determinant! x) -2 gosh> x #,( (0 2 0 2) 2 3 0 1) !2005-10-21 Fri gosh> (use gauche.array) # gosh> (array-inverse #,( (0 2 0 2) 0 1 2 3)) #,( (0 2 0 2) -1.5 0.5 1 0) !2005-10-20 Thu gosh> (use gauche.array) # gosh> (identity-array 2) #,( (0 2 0 2) 1 0 0 1) 何?大きさ 1 の行列??? !2005-10-19 Wed gosh> (use gauche.array) # gosh> (define x #,( (0 2 0 2) 0 1 2 3)) x gosh> (array-flip! x) #t gosh> x #,( (0 2 0 2) 2 3 0 1) !2005-10-18 Tue gosh> (use gauche.array) # gosh> (array-flip #,( (0 2 0 2) 0 1 2 3)) #,( (0 2 0 2) 2 3 0 1) !2005-10-17 Mon gosh> (use gauche.array) # gosh> (array-rotate-90 #,( (0 2 0 2) 0 1 2 3)) #,( (0 2 0 2) 2 0 3 1) !2005-10-16 Sun gosh> (use gauche.array) # gosh> (array-transpose #,( (0 2 0 2) 0 1 2 3)) #,( (0 2 0 2) 0 2 1 3) !2005-10-15 Sat gosh> (use gauche.array) # gosh> (array-concatenate #,( (0 2 0 2) 0 1 2 3) #,( (0 2 0 2) 4 5 6 7)) #,( (0 4 0 2) 0 1 2 3 4 5 6 7) !2005-10-14 Fri gosh> (use gauche.array) # gosh> (array->list #,( (0 3 0 3) 0 1 2 3 4 5 6 7 8)) (0 1 2 3 4 5 6 7 8) !2005-10-13 Thu gosh> (use gauche.array) # gosh> (array->vector #,( (0 3 0 3) 0 1 2 3 4 5 6 7 8)) #(0 1 2 3 4 5 6 7 8) !2005-10-12 Wed gosh> (use gauche.array) # gosh> (array-map (lambda (x y) (+ x y)) #,( (0 3 0 3) 9 10 11 12 13 14 15 16 17) #,( (0 3 0 3) 18 19 20 21 22 23 24 25 26)) #,( (0 3 0 3) 27 29 31 33 35 37 39 41 43) !2005-10-11 Tue array-retabulate! とばし。何するのか分からないから。 gosh> (use gauche.array) # gosh> (define x #,( (0 3 0 3) 0 1 2 3 4 5 6 7 8)) x gosh> (array-map! x (lambda (x y) (+ x y)) #,( (0 3 0 3) 9 10 11 12 13 14 15 16 17) #,( (0 3 0 3) 18 19 20 21 22 23 24 25 26)) #t gosh> x #,( (0 3 0 3) 27 29 31 33 35 37 39 41 43) gosh> (define x (make-array (shape 0 3 0 3))) x gosh> (array-map! x (lambda (x y) (+ x y)) #,( (0 3 0 3) 9 10 11 12 13 14 15 16 17) #,( (0 3 0 3) 18 19 20 21 22 23 24 25 26)) #t gosh> x #,( (0 3 0 3) 27 29 31 33 35 37 39 41 43) !2005-10-10 Mon gosh> (use gauche.array) # gosh> (tabulate-array (shape 5 9 1 3) (lambda (x y) (print x y))) 51 52 61 62 71 72 81 82 #,( (5 9 1 3) # # # # # # # #) ? !2005-10-09 Sun gosh> (use gauche.array) # gosh> (shape-for-each (shape 5 9 1 3) (lambda (x y) (print x y))) 51 52 61 62 71 72 81 82 #t !2005-10-08 Sat share-array とばし。 gosh> (use gauche.array) # gosh> (array-for-each-index #,( (0 3 0 3) 8 3 4 1 5 9 6 7 2) (lambda (x) (display x))) *** ERROR: wrong number of arguments for # (required 1, got 2) gosh> (array-for-each-index #,( (0 3 0 3) 8 3 4 1 5 9 6 7 2) (lambda (x i) (display x))) 000111222#t 逆か gosh> (array-for-each-index #,( (0 3 0 3) 8 3 4 1 5 9 6 7 2) (lambda (i x) (display x))) 012012012#t あれ? 何やっているんだっけ? 添字が渡るだけか gosh> (array-for-each-index #,( (0 3 0 3) 8 3 4 1 5 9 6 7 2) (lambda (i j) (print i ":" j))) 0:0 0:1 0:2 1:0 1:1 1:2 2:0 2:1 2:2 #t gosh> (array-for-each-index #,( (0 3 0 2) 8 3 4 1 5 9) (lambda (i j) (print i ":" j))) 0:0 0:1 1:0 1:1 2:0 2:1 #t !2005-10-07 Fri gosh> (use gauche.array) # gosh> (define x #,( (0 3 0 3) 8 3 4 1 5 9 6 7 2)) x gosh> (array-set! x 0 0 10) # gosh> x #,( (0 3 0 3) 10 3 4 1 5 9 6 7 2) gosh> (array-set! x #(0 0) 8) # gosh> x #,( (0 3 0 3) 8 3 4 1 5 9 6 7 2) !2005-10-06 Thu gosh> (use gauche.array) # gosh> (array-ref #,( (0 3 0 3) 8 3 4 1 5 9 6 7 2) '#(0 0)) 8 gosh> (array-ref #,( (0 3 0 3) 8 3 4 1 5 9 6 7 2) #(0 0)) 8 gosh> (array-ref #,( (0 3 0 3) 8 3 4 1 5 9 6 7 2) #(0 1)) 3 !2005-10-05 Wed gosh> (use gauche.array) # gosh> (array-ref #,( (0 3 0 3) 8 3 4 1 5 9 6 7 2) 0) *** ERROR: s32vector-range-check: argument object sizes do not match: #s32(2 2) vs (0) gosh> (array-ref #,( (0 3 0 3) 8 3 4 1 5 9 6 7 2) 0 0) 8 gosh> (array-ref #,( (0 3 0 3) 8 3 4 1 5 9 6 7 2) 0 1) 3 !2005-10-04 Tue まんま gosh> (use gauche.array) # gosh> (array-size (make-array (shape 5 9 1 3))) 8 gosh> (array-size (make-array (shape))) 1 gosh> (array-size (make-array (shape 0 0 0 2))) 0 !2005-10-03 Mon まんま gosh> (use gauche.array) # gosh> (define a (make-array (shape 1 5 0 2))) a gosh> (array-start a 0) 1 gosh> (array-end a 0) 5 gosh> (array-length a 0) 4 gosh> (array-start a 1) 0 gosh> (array-end a 1) 2 gosh> (array-length a 1) 2 !2005-10-02 Sun gosh> (use gauche.array) # gosh> (array-shape #,( (0 3 0 3) 8 3 4 1 5 9 6 7 2)) #,( (0 2 0 2) 0 3 0 3) gosh> (array-shape #,( (0 4 0 4) 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1)) #,( (0 2 0 2) 0 4 0 4) !2005-10-01 Sat まんま gosh> (use gauche.array) # gosh> (array-rank (make-array (shape 0 2 0 2 0 2))) 3 gosh> (array-rank (make-array (shape))) 0 !2005-09-30 Fri まんま gosh> (use gauche.array) # gosh> (array (shape 0 2 1 3) 'a 'b 'c 'd) #,( (0 2 1 3) a b c d) !2005-09-29 Thu まんま gosh> (use gauche.array) # gosh> (shape 0 2 1 3 3 5) #,( (0 3 0 2) 0 2 1 3 3 5) gosh> (shape) #,( (0 0 0 2)) !2005-09-28 Wed gosh> (use gauche.array) # gosh> (make-u8array (shape 0 2 0 2 0 2) 5) #,( (0 2 0 2 0 2) 5 5 5 5 5 5 5 5) gosh> (make-u8array (shape 0 2 0 2 0 2) 1024) *** ERROR: value out of domain for u8vector: 1024 !2005-09-27 Tue まんま gosh> (use gauche.array) # gosh> (make-array (shape 0 2 0 2 0 2) 5) #,( (0 2 0 2 0 2) 5 5 5 5 5 5 5 5) !2005-09-26 Mon gosh> (use gauche.array) # gosh> (array? '(1 2 3)) #f gosh> (array? #,( (0 3 0 3) 8 3 4 1 5 9 6 7 2)) #t !2005-09-25 Sun まんま gosh> (use gauche.array) # gosh> #,( (0 3 0 3) 8 3 4 1 5 9 6 7 2) #,( (0 3 0 3) 8 3 4 1 5 9 6 7 2) gosh> #,( (0 4 0 4) 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1) #,( (0 4 0 4) 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1) !2005-09-24 Sat まんま gosh> (use gauche.sequence) # gosh> (group-sequence '(1 1 1 2 3 4 4 2 2 3 1 1 3)) ((1 1 1) (2) (3) (4 4) (2 2) (3) (1 1) (3)) gosh> (group-sequence '(1 1 1 2 3 4 4 2 2 3 1 1 3) :key (cut modulo <> 2)) ((1 1 1) (2) (3) (4 4 2 2) (3 1 1 3)) マニュアル括弧一つ多いよー gosh> (group-sequence '#("a" "a" "b" "b" "c" "d" "d") :test string=?) (("a" "a") ("b" "b") ("c") ("d" "d")) gosh> (group-sequence "aabbcdd" :test char=?) ((#\a #\a) (#\b #\b) (#\c) (#\d #\d)) !2005-09-23 Fri まんま gosh> (use gauche.sequence) # gosh> (find-index char-upper-case? "abraCadabra") 4 gosh> (find-index char-numeric? "abraCadabra") #f !2005-09-22 Thu まんま gosh> (use gauche.sequence) # gosh> (find-with-index char-upper-case? "abraCadabra") 4 #\C gosh> (find-with-index char-numeric? "abraCadabra") #f #f !2005-09-21 Wed ほぼ、まんま gosh> (use gauche.sequence) # gosh> (map-with-index list '(a b c d) '(e f g h)) ((0 a e) (1 b f) (2 c g) (3 d h)) gosh> (map-to-with-index cons '(a b c d)) #((0 . a) (1 . b) (2 . c) (3 . d)) gosh> (for-each-with-index (lambda (i x) (format #t "~d ~a\n" i x)) '(1 2 3 4)) 0 1 1 2 2 3 3 4 #t !2005-09-20 Tue まんま gosh> (use gauche.sequence) # gosh> (fold-with-index acons '() '(a b c)) ((2 . c) (1 . b) (0 . a)) !2005-09-19 Mon まんま gosh> (use gauche.sequence) # gosh> (define s (vector 'a 'b 'c 'd 'e)) s gosh> (set! (subseq s 1 4) '(4 5 6)) #t gosh> s #(a 4 5 6 e) gosh> (set! (subseq s 0) "ab") #t gosh> s #(#\a #\b 5 6 e) !2005-09-18 Sun referencer, modifier は define-method で定義しろって意味なんだろうか??? まんま gosh> (use gauche.sequence) # gosh> (subseq '(a b c d e) 1 4) (b c d) gosh> (subseq '#(a b c d e) 1 4) #(b c d) gosh> (subseq "abcde" 1 4) "bcd" gosh> (subseq '(a b c d e) 3) (d e) !2005-09-17 Sat gosh> (use gauche.sequence) # gosh> (let ((x (list 'a 'b 'c))) (set! (ref x 1) 'z) x) (a z c) gosh> (let ((x (vector 'a 'b 'c))) (set! (ref x 1) 'z) x) #(a z c) gosh> (let ((x (string #\a #\b #\c))) (set! (ref x 1) #\z) x) "azc" !2005-09-16 Fri 「コレクションの実装」とばし まんま。 gosh> (use gauche.sequence) # gosh> (ref '(a b c) 1) b gosh> (ref '#(a b c) 1) b gosh> (ref "abc" 1) #\b !2005-09-15 Thu gosh> (use gauche.collection) # gosh> (with-builder ( add! get) (add! 'a) (add! 'b) (add! 'c) (get)) (a b c) gosh> (with-builder ( add! get) (add! 'a) (add! 'b) (add! 'c) (get)) #(a b c) !2005-09-14 Wed call-with-iterators 良く分からないので、とばし。 まんま gosh> (use gauche.collection) # gosh> (call-with-builder (lambda (add! get) (add! 'a) (add! 'b) (add! 'c) (get))) (a b c) gosh> (call-with-builder (lambda (add! get) (add! 'a) (add! 'b) (add! 'c) (get))) #(a b c) !2005-09-13 Tue gosh> (use gauche.collection) # gosh> (with-iterator ('(1 2 3 4 5) end? next) (do ((odd-nums 0)) ((end?) odd-nums) (when (odd? (next)) (inc! odd-nums)))) 3 !2005-09-12 Mon まんま gosh> (use gauche.collection) # gosh> (call-with-iterator '(1 2 3 4 5) (lambda (end? next) (do ((odd-nums 0)) ((end?) odd-nums) (when (odd? (next)) (inc! odd-nums))))) 3 !2005-09-11 Sun まんま gosh> (use gauche.collection) # gosh> (coerce-to '(1 2 3 4)) #(1 2 3 4) gosh> (coerce-to '#(#\a #\b #\c)) "abc" !2005-09-10 Sat gosh> (use gauche.collection) # gosh> (lazy-size-of "foo") 3 gosh> (lazy-size-of '(1 2 3)) 3 何が何だか分からない !2005-09-09 Fri gosh> (use gauche.collection) # gosh> (size-of "foo") 3 gosh> (size-of '(1 2 3)) 3 !2005-09-08 Thu まんま gosh> (use gauche.collection) # gosh> (group-collection '(1 2 3 2 3 1 2 1 2 3 2 3)) ((1 1 1) (2 2 2 2 2) (3 3 3 3)) gosh> (group-collection '(1 2 3 2 3 1 2 1 2 3 2 3) :key odd?) ((1 3 3 1 1 3 3) (2 2 2 2 2)) gosh> (group-collection '(("a" 2) ("b" 5) ("c" 1) ("b" 3) ("a" 6)) :key car :test string=?) ((("a" 2) ("a" 6)) (("b" 5) ("b" 3)) (("c" 1))) !2005-09-07 Wed まんま gosh> (use gauche.collection) # gosh> (partition-to char-upper-case? "PuPu") "PP" "uu" gosh> (partition-to even? '#(1 2 3 4)) #(2 4) #(1 3) !2005-09-06 Tue まんま gosh> (use gauche.collection) # gosh> (partition char-upper-case? "PuPu") (#\P #\P) (#\u #\u) gosh> (partition even? '#(1 2 3 4)) (2 4) (1 3) !2005-09-05 Mon まんま gosh> (use gauche.collection) # gosh> (remove-to even? '#(1 2 3 4)) #(1 3) gosh> (remove-to char-upper-case? "Hello, World") "ello, orld" !2005-09-04 Sun まんま gosh> (use gauche.collection) # gosh> (remove char-upper-case? "Hello, World") (#\e #\l #\l #\o #\, #\space #\o #\r #\l #\d) gosh> (remove even? '#(1 2 3 4)) (1 3) !2005-09-03 Sat まんま gosh> (use gauche.collection) # gosh> (filter-to even? '#(1 2 3 4)) #(2 4) gosh> (filter-to char-upper-case? "Hello, World") "HW" !2005-09-02 Fri まんま gosh> (use gauche.collection) # gosh> (filter char-upper-case? "Hello, World") (#\H #\W) gosh> (filter even? '#(1 2 3 4)) (2 4) !2005-09-01 Thu まんま gosh> (use gauche.collection) # gosh> (find char-upper-case? "abcDe") #\D gosh> (find even? '#(1 3 4 6)) 4 gosh> (find even? '(1 3 5 7)) #f !2005-08-31 Wed gosh> (use gauche.collection) # gosh> (define f (for-each$ print)) f gosh> (f '(1 2 3)) 1 2 3 # !2005-08-30 Tue gosh> (use gauche.collection) # gosh> (define m (map$ (lambda (x) (* x 2)))) m gosh> (m '(1 2 3)) (2 4 6) !2005-08-29 Mon gosh> (use gauche.collection) # gosh> (define f (fold$ + 0)) f gosh> (f '(1 2 3 4)) 10 !2005-08-28 Sun gosh> (use gauche.collection) # gosh> (for-each print '(1 2 3)) 1 2 3 # gosh> (for-each print 1 2 3) *** ERROR: list required, but got 1 gosh> (for-each print '(1 2 3) '(4 5 6)) 14 25 36 # gosh> (for-each print "foo") f o o #t gosh> (for-each print "foo" "bar") fb oa or #t !2005-08-27 Sat test/colseq.scm によると、こう使うんだと。 良く使うんだか分からない…。 gosh> (use gauche.collection) # gosh> (map-accum (lambda (elt seed) (values (* elt seed) seed)) 5 '(9 6 3)) (45 30 15) 5 gosh> (map-accum (lambda (elt seed) (values (* elt seed) (+ elt seed))) 5 '(2 4 8)) (10 28 88) 19 gosh> (map-accum (lambda (x y seed) (values (+ x y seed) (+ x seed))) 1 '(2 4 8) '(7 4 1)) (10 11 16) 15 !2005-08-26 Fri まんま gosh> (use gauche.collection) # gosh> (map-to + '#(1 2 3) '#(4 5 6)) #(5 7 9) gosh> (map-to char-upcase "def") "DEF" gosh> (map-to char=? "bed" "pet") #(#f #t #f) 処理後に変換をしているのか??? !2005-08-25 Thu まんま gosh> (use gauche.collection) # gosh> (map (lambda (x) (* x 2)) '#(1 2 3)) (2 4 6) gosh> (map char-upcase "abc") (#\A #\B #\C) gosh> (map + '#(1 2 3) '#(4 5 6)) (5 7 9) !2005-08-24 Wed まんま gosh> (use gauche.collection) # gosh> (fold2 (lambda (elt a b) (values (min elt a) (max elt b))) 256 0 '#u8(33 12 142 1 74 98 12 5 99)) 1 142 !2005-08-23 Tue まんま gosh> (use gauche.collection) # gosh> (fold acons '() "abc" '#(1 2 3)) ((#\c . 3) (#\b . 2) (#\a . 1)) gosh> (fold (lambda (a b r) (+ (* a b) r)) 0 '#(3 5 7) '#(2 4 6)) 68 !2005-08-22 Mon まんま gosh> (fold + 0 '#(1 2 3 4)) *** ERROR: argument must be a list, but got: #(1 2 3 4) Stack Trace: _______________________________________ gosh> (use gauche.collection) # gosh> (fold + 0 '#(1 2 3 4)) 10 gosh> (fold cons '() "abc") (#\c #\b #\a) !2005-08-21 Sun まんま gosh> (regexp-quote "[2002/10/12] touched foo.h and *.c") "\\[2002/10/12\\] touched foo\\.h and \\*\\.c" !2005-08-20 Sat まんま gosh> (regexp-replace #/c(.*)g/ "abcdefghi" (lambda (m) (list->string (reverse (string->list (rxmatch-substring m 1)))))) "abfedhi" !2005-08-19 Fri まんま gosh> (regexp-replace #/def|DEF/ "abcdefghi" "...") "abc...ghi" gosh> (regexp-replace #/def|DEF/ "abcdefghi" "|\\0|") "abc|def|ghi" gosh> (regexp-replace #/def|DEF/ "abcdefghi" "|\\\\0|") "abc|\\0|ghi" gosh> (regexp-replace #/c(.*)g/ "abcdefghi" "|\\1|") "ab|def|hi" !2005-08-18 Thu まんま gosh> (define (parse-date2 str) (rxmatch-case str (test (lambda (s) (not (string? s))) #f) (#/^(\d\d?)\/(\d\d?)\/(\d\d\d\d)$/ (#f mm dd yyyy) (map string->number (list yyyy mm dd))) (#/^(\d\d\d\d)\/(\d\d?)\/(\d\d?)$/ (#f yyyy mm dd) (map string->number (list yyyy mm dd))) (#/^\d+\/\d+\/\d+$/ (#f) (error "ambiguous: ~s" str)) (else (error "bogus: ~s" str)))) parse-date2 gosh> (parse-date2 "2001/2/3") (2001 2 3) gosh> (parse-date2 "12/25/1999") (1999 12 25) !2005-08-17 Wed まんま gosh> (define (parse-date str) (rxmatch-cond ((rxmatch #/^(\d\d?)\/(\d\d?)\/(\d\d\d\d)$/ str) (#f mm dd yyyy) (map string->number (list yyyy mm dd))) ((rxmatch #/^(\d\d\d\d)\/(\d\d?)\/(\d\d?)$/ str) (#f yyyy mm dd) (map string->number (list yyyy mm dd))) ((rxmatch #/^\d+\/\d+\/\d+$/ str) (#f) (error "ambiguous: ~s" str)) (else (error "bogus: ~s" str)))) parse-date gosh> (parse-date "2001/2/3") (2001 2 3) gosh> (parse-date "12/25/1999") (1999 12 25) !2005-08-16 Tue まんま gosh> (rxmatch-if (rxmatch #/(\d+:\d+)/ "Jan 1 11:22:33") (time) (format #f "time is ~a" time) "unknown time") "time is 11:22" gosh> (rxmatch-if (rxmatch #/(\d+:\d+)/ "Jan 1 11-22-33") (time) (format #f "time is ~a" time) "unknown time") "unknown time" おっ、これも使えそうだ !2005-08-15 Mon まんま gosh> (rxmatch-let (rxmatch #/(\d+):(\d+):(\d+)/ "Jan 1 23:59:58, 2001") (time hh mm ss) (list time hh mm ss)) ("23:59:58" "23" "59" "58") gosh> (rxmatch-let (rxmatch #/(\d+):(\d+):(\d+)/ "Jan 1 23:59:58, 2001") (#f hh mm) (list hh mm)) ("23" "59") おっ、これは便利そうだ !2005-08-14 Sun gosh> (info #t) *** ERROR: no info document for #t info ちゃんと入っていなかったかも gosh> (info 'apropos) おっ、うまくいった gosh> (info '+) おっ、うまくいった !2005-08-13 Sat gosh> (describe "foo") "foo" is an instance of class gosh> (d "foo") "foo" is an instance of class !2005-08-12 Fri まんま gosh> (apropos 'char 'srfi-14) *** ERROR: No such module: srfi-14 Stack Trace: _______________________________________ 0 (values) At line 103 of "/usr/local/share/gauche/0.8.5/lib/gauche/interactive.scm" 1 (values) At line 103 of "/usr/local/share/gauche/0.8.5/lib/gauche/interactive.scm" 2 (error "Bad object for module: " module) At line 66 of "/usr/local/share/gauche/0.8.5/lib/gauche/interactive.scm" gosh> (use srfi-14) # gosh> (apropos 'char 'srfi-14) char-set->list (srfi-14) char-set->string (srfi-14) ... ucs-range->char-set! (srfi-14) |->char-set| (srfi-14) !2005-08-11 Thu まんま gosh> (apropos 'string) %hash-string (gauche) %maybe-substring (gauche) %string-pointer-dump (gauche) %string-split-by-char (gauche) (gauche) (gauche) (gauche) (gauche) call-with-input-string (gauche) call-with-output-string (gauche) call-with-string-io (gauche) get-output-string (gauche) get-remaining-input-string (gauche) keyword->string (gauche) list->string (scheme) make-byte-string (gauche) make-string (scheme) make-string-pointer (gauche) number->string (scheme) open-input-string (gauche) open-output-string (gauche) port->byte-string (gauche) port->string (gauche) port->string-list (gauche) read-from-string (gauche) regexp->string (gauche) rxmatch-substring (gauche) string (scheme) string->list (scheme) string->number (scheme) string->regexp (gauche) string->symbol (scheme) string-append (scheme) string-byte-ref (gauche) string-byte-set! (gauche) string-ci<=? (scheme) string-ci=? (scheme) string-ci>? (scheme) string-complete->incomplete (gauche) string-complete->incomplete! (gauche) string-copy (scheme) string-fill! (scheme) string-immutable? (gauche) string-incomplete->complete (gauche) string-incomplete->complete! (gauche) string-incomplete? (gauche) string-interpolate (gauche) string-join (gauche) string-length (scheme) string-pointer-byte-index (gauche) string-pointer-copy (gauche) string-pointer-index (gauche) string-pointer-next! (gauche) string-pointer-prev! (gauche) string-pointer-ref (gauche) string-pointer-set! (gauche) string-pointer-substring (gauche) string-pointer? (gauche) string-ref (scheme) string-scan (gauche) string-set! (scheme) string-size (gauche) string-split (gauche) string-substitute! (gauche) string<=? (scheme) string=? (scheme) string>? (scheme) string? (scheme) substring (scheme) symbol->string (scheme) with-input-from-string (gauche) with-output-to-string (gauche) with-string-io (gauche) write-to-string (gauche) x->string (gauche) !2005-08-10 Wed まんま gosh> (use gauche.config) # gosh> (gauche-config "--cc") "gcc" gosh> (gauche-config "-L") "-L'/usr/local/lib/gauche/0.8.5/i686-pc-linux-gnu'" gosh> (gauche-config "-l") "-lgauche -ldl -lcrypt -lutil -lm" !2005-08-09 Tue gosh> (use gauche.version) # gosh> (version-compare "2.2.3" "2.2.11") -1 gosh> (version-compare "2.3.1" "2.3") 1 gosh> (version-compare "2.3.1-1" "2.3.1-10") -1 gosh> (version-compare "13a" "5b") 1 gosh> (version-compare "2.2.3" "2.2.3") 0 relnum-compare とばし !2005-08-08 Mon まんま gosh> (use gauche.version) # gosh> (version (version (version (version (current-class-of "foo") #> 適切ではないが、余り使わないらしいのでお茶を濁しておく !2005-08-06 Sat まんま gosh> (is-a? 3 ) #t gosh> (is-a? 3 ) #t gosh> (is-a? 5+3i ) #f gosh> (is-a? :foo ) #f !2005-08-05 Fri まんま gosh> (class-of 3) #> gosh> (class-of "foo") #> gosh> (class-of ) #> !2005-08-04 Thu まんま gosh> (define-class <2d-point> () ((x :init-value 0.0 :init-keyword :x :accessor x-of) (y :init-value 0.0 :init-keyword :y :accessor y-of))) <2d-point> gosh> (define-class () ((color :init-value '(0 0 0) :init-keyword :color) (thickness :init-value 2 :init-keyword :thickness))) gosh> (define *shapes* '()) *shapes* gosh> (define-method initialize ((self ) initargs) (next-method) (push! *shapes* self)) # gosh> (define-class () ((point :init-form (make <2d-point>) :init-keyword :point))) gosh> (define-class () ((points :init-value '() :init-keyword :points) (closed :init-value #f :init-keyword :closed))) gosh> (define-class () ()) gosh> (define-method draw ((self ) (device )) (format #t "gsave\n") (draw-path self device) (apply format #t "~a ~a ~a setrgbcolor\n" (ref self 'color)) (format #t "~a setlinewidth\n" (ref self 'thickness)) (format #t "stroke\n") (format #t "grestore\n")) # gosh> (define-method draw-path ((self ) (device )) (apply format #t "newpath ~a ~a 1 0 360 arc closepath\n" (point->list (ref self 'point)))) # gosh> (define-method draw-path ((self ) (device )) (let ((pts (ref self 'points))) (when (>= (length pts) 2) (format #t "newpath\n") (apply format #t "~a ~a moveto\n" (point->list (car pts))) (for-each (lambda (pt) (apply format #t "~a ~a lineto\n" (point->list pt))) (cdr pts)) (when (ref self 'closed) (apply format #t "~a ~a lineto\n" (point->list (car pts)))) (format #t "closepath\n")))) # gosh> (define-method point->list ((pt <2d-point>)) (list (x-of pt) (y-of pt))) #list (1)> gosh> (define-method draw ((shapes ) (device )) (format #t "%%\n") (for-each (cut draw <> device) shapes) (format #t "showpage\n")) # gosh> (use srfi-1) # gosh> (use math.const) # gosh> (define (shape-sample) ;; creates 5 corner points of pentagon (define (make-corners scale) (map (lambda (i) (let ((pt (make <2d-point>))) (move-by! pt (make-polar scale (* i 2/5 pi))) (move-by! pt 200 200) pt)) (iota 5))) (set! *shapes* '()) ;; clear the shape list (let* ((corners (make-corners 100))) ;; a pentagon in green (make :color '(0 1 0) :closed #t :points corners) ;; a star-shape in red (make :color '(1 0 0) :closed #t :points (list (list-ref corners 0) (list-ref corners 2) (list-ref corners 4) (list-ref corners 1) (list-ref corners 3))) ;; put dots in each corner of the star (for-each (cut make :point <>) (make-corners 90)) ;; draw the shapes (draw *shapes* (make ))) ) shape-sample gosh> (with-output-to-file "oointro.ps" shape-sampe) *** ERROR: unbound variable: shape-sampe Stack Trace: _______________________________________ 0 (with-output-to-file "oointro.ps" shape-sampe) At line 80 of "(stdin)" 1 (with-output-to-file "oointro.ps" shape-sampe) At line 80 of "(stdin)" gosh> (with-output-to-file "oointro.ps" shape-sample) *** ERROR: unbound variable: move-by! どの move-by! 使えば良いんだっけ? マニュアルでは :init-keyword が init-keyword だよー それらのサブクラスでも受け入れらること shape-sampe じゃない、shape-sample だ! !2005-08-03 Wed まんま gosh> (define-class <2d-point> () ((x :init-value 0.0 :init-keyword :x :accessor x-of) (y :init-value 0.0 :init-keyword :y :accessor y-of))) <2d-point> gosh> (define-method object-equal? ((a <2d-point>) (b <2d-point>)) (and (equal? (x-of a) (x-of b)) (equal? (y-of a) (y-of b)))) # gosh> (equal? (make <2d-point> :x 1 :y 2) (make <2d-point> :x 1 :y 2)) #t gosh> (equal? (make <2d-point> :x 1 :y 2) (make <2d-point> :x 2 :y 1)) #f gosh> (equal? (make <2d-point> :x 1 :y 2) 'a) #f gosh> (equal? (list (make <2d-point> :x 1 :y 2) (make <2d-point> :x 3 :y 4)) (list (make <2d-point> :x 1 :y 2) (make <2d-point> :x 3 :y 4))) #t !2005-08-02 Tue まんま gosh> (define-class <2d-point> () ((x :init-value 0.0 :init-keyword :x :accessor x-of) (y :init-value 0.0 :init-keyword :y :accessor y-of))) <2d-point> gosh> (define-class <2d-vector> () ((x :init-value 0.0 :init-keyword :x :accessor x-of) (y :init-value 0.0 :init-keyword :y :accessor y-of))) <2d-vector> gosh> (define-method move-by! ((pt <2d-point>) dx dy) (inc! (x-of pt) dx) (inc! (y-of pt) dy)) # gosh> (define a-point (make <2d-point>)) a-point gosh> (define b-point (make <2d-point> :x 50.0 :y -10.0)) b-point gosh> (move-by! b-point 1.4 2.5) # gosh> (d b-point) #<<2d-point> 0x8193d68> is an instance of class <2d-point> slots: x : 51.4 y : -7.5 gosh> (define-method move-by! ((pt <2d-point>) (delta <2d-vector>)) (move-by! pt (x-of delta) (y-of delta))) # gosh> (define-method move-by! ((pt <2d-point>) (c )) (move-by! pt (real-part c) (imag-part c))) # gosh> (define d-vector (make <2d-vector> :x -9.0 :y 7.25)) d-vector gosh> (move-by! b-point d-vector) # gosh> (d b-point) #<<2d-point> 0x8193d68> is an instance of class <2d-point> slots: x : 42.4 y : -0.25 gosh> (move-by! b-point 3+2i) # gosh> (d b-point) #<<2d-point> 0x8193d68> is an instance of class <2d-point> slots: x : 45.4 y : 1.75 gosh> move-by! # gosh> (d move-by!) # is an instance of class slots: name : move-by! methods : (# )> # (ref move-by! 'methods) (# )> # <2d-vector>)> # )>) gosh> (d x-of) # is an instance of class slots: name : x-of methods : (#)> # (define-method write-object ((pt <2d-point>) port) (format port "[[~a, ~a]]" (x-of pt) (y-of pt))) # gosh> (define-method write-object ((vec <2d-vector>) port) (format port "<<~a, ~a>>" (x-of vec) (y-of vec))) # gosh> a-point [[0.0, 0.0]] gosh> d-vector <<-9.0, 7.25>> !2005-08-01 Mon まんま gosh> (define-class <2d-point> () ((x :init-value 0.0 :init-keyword :x :accessor x-of) (y :init-value 0.0 :init-keyword :y :accessor y-of))) <2d-point> gosh> (define a-point (make <2d-point>)) a-point gosh> (d a-point) #<<2d-point> 0x8181a28> is an instance of class <2d-point> slots: x : 0.0 y : 0.0 gosh> (define b-point (make <2d-point> :x 50.0 :y -10.0)) b-point gosh> (d b-point) #<<2d-point> 0x8181540> is an instance of class <2d-point> slots: x : 50.0 y : -10.0 gosh> (x-of a-point) 0.0 gosh> (x-of b-point) 50.0 gosh> (set! (y-of a-point) 3.33) # gosh> (y-of a-point) 3.33 !2005-07-31 Sun まんま gosh> (define-class <2d-point> () (x y)) <2d-point> gosh> (define a-point (make <2d-point>)) a-point gosh> (d a-point) #<<2d-point> 0x80f41d0> is an instance of class <2d-point> slots: x : # y : # gosh> (slot-ref a-point 'x) *** ERROR: slot x of object of class #> is unbound Stack Trace: _______________________________________ gosh> (slot-set! a-point 'x 10.0) # gosh> (slot-ref a-point 'x) 10.0 gosh> (ref a-point 'x) 10.0 gosh> (set! (ref a-point 'y) 20.0) # gosh> (ref a-point 'y) 20.0 gosh> (d a-point) #<<2d-point> 0x80f41d0> is an instance of class <2d-point> slots: x : 10.0 y : 20.0 !2005-07-30 Sat gosh> (profiler-start) # gosh> (profiler-stop) 0 gosh> profiler-show *** ERROR: unbound variable: profiler-show なぬ? !2005-07-29 Fri gosh> (lambda (a b) (+ a b)) # gosh> (disasm (lambda (a b) (+ a b))) *** ERROR: unbound variable: disasm Stack Trace: _______________________________________ gosh> (use gauche.vm.disasm) (# #) gosh> (disasm (lambda (a b) (+ a b))) LREF1-PUSH ;; a LREF0 ;; b NUMADD2 ;; (+ a b) RET () use してから使えって書いておいて欲しいな〜。 って思ったら、0.8.5 を入れたら use しなくても大丈夫だった。 !2005-07-28 Thu gosh> (debug-print (+ 1 2)) #?="(stdin)":1:(+ 1 2) #?- 3 3 gosh> #?=(+ 1 2) #?="(stdin)":2:(+ 1 2) #?- 3 3 !2005-07-27 Wed gosh> (sys-random) 1804289383 gosh> RAND_MAX 2147483647 gosh> (sys-srandom 1) # 良くやる時間を種にするっぽい記述はどう書けば良いんだろうか? !2005-07-26 Tue gosh> (sys-sleep 1) 0 gosh> (sys-nanosleep (* 1000 1000 1000)) #f まんま gosh> (sys-nanosleep (make