tag:blogger.com,1999:blog-376552092024-02-09T22:56:44.641+01:00時の羅針盤@blogオランダの生活、自身が行っているSagittarius Schemeの開発日誌、<br>
その他雑多なことをつづってます。keihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.comBlogger1128125tag:blogger.com,1999:blog-37655209.post-78385204409041767852023-10-09T14:25:00.001+02:002023-10-09T14:25:16.801+02:00OAS stubここ数ヶ月Kotlinを書いていたのだが、なんとなく形になったしちょっと紹介記事を書こうかなぁと。Swagger/OpenAPI Specificationは多分誰でも知っているだろう。Microserviceな流れになっていた前職で10を超えるバックエンドサービスに接続する必要があったのだが、毎回stubを書くのは馬鹿らしいと思い提供されているAPI定義(たいていSwaggerかOAS)を読み込んだらリクエストの検査からレスポンスの生成をやってくれないかなぁと思って作ったものの焼き増しがOAS stubになる。実際にこのアプリはかなり便利で、恐ろしく時間の短縮が可能だった*1ので多分OSSにしても需要があるんじゃないかなぁと。基本的な使用方法は今のところ二つ、Spring Bootアプリとしてスタンドアローンにするか、テスト用フレームワークとして使うか。スタンドアローンアプリスタンドkeihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com0tag:blogger.com,1999:blog-37655209.post-8424975726037358282023-10-02T15:16:00.005+02:002023-10-02T15:22:36.903+02:00転職して一ヶ月で異動、または履歴書に前職の経歴を書く功罪転職して一ヶ月で異動になった話。ちょっと個人的にツボったので後で振り返るように書いておく。2023年9月から銀行Iで働くことになった。前職である銀行Rではオランダで最も使われているペイメントスキームの一つであるiDealのメンテナンス及びメジャーバージョンアップに多大に貢献した。当然ではあるが、履歴書にそのことを載せていた。ちなみに、銀行Iはオランダ最大手の銀行かつ銀行Rの競合他社であるが、iDealのメジャーバージョンアップ(以降iDeal 2.0)において銀行Rの後塵を配していた。自慢になるが、銀行RがiDeal 2.0において他の追随を許さない勢いで成功を収めたのは、僕の功績が大きい*1。ちなみに銀行Iに転職する前の面接では一応そのことを仄めかしていたが、大きくは取り上げなかった。個人的にiDeal 2.0に関わりたくなかったし*2。転職直後の月曜日に別のチームのマネージャからkeihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com0tag:blogger.com,1999:blog-37655209.post-60264331754039654502023-06-14T09:44:00.002+02:002023-06-14T09:44:33.230+02:00英語の勉強のお供に?同僚のスクリーンセーバが英単語とその意味を表示するやつなのをみて、こういうのあると便利かなぁと思い始めたのでなんとなく似た感じのものを作ってみた。まぁそこまで似ているというほどでもないのだが、起動するとコンソールに単語の意味と例文をなんちゃってカード形式で表示するというもの。ちなみに単語はUrban Dictionaryの非公式APIを使って取得していたりするので、このスクリプトがある日突然使えなくなっても泣かないようにしないといけない。Gistに載せたのはコピペしたものなので、色がついてたり太字になってたり下線がついてたりするのが見えないのが残念。実際にどのように見えるのかは実行すればわかるということで。
別段特筆すべきこともないのだが、これを書くために使ったライブラリ達(当然だが全部Sagittariusに付属している)(net http-client): モダン(なつもり)なkeihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com0tag:blogger.com,1999:blog-37655209.post-37316883489776366202023-05-04T20:57:00.000+02:002023-05-04T20:57:04.893+02:00Remote debugger(ish)In the previous post, I've mentioned that I needed to collect all threads
to see which one is hanging. After implementing it, I've also noticed that
all threads were hanging. So I've decided to implement a better remote
debugger(ish).
CAVEAT
The functions and interface are experimental, so it might get changed
in the future.
Suppose we have this script:
(import (rnrs)
(srfi :1)
(keihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com0tag:blogger.com,1999:blog-37655209.post-53300580390978546732023-04-26T11:09:00.003+02:002023-04-26T11:09:32.500+02:00Thread monitoringWhen I write multi thread programs, it's always a trouble to debug whenever
a thread hangs. That's because:
You don't see what's going on.
I don't put logging when I write a library and I don't usually use raw
thread.
The problem is gone away if I put a debug print
And/or it happens only once in a hundred
So, I started thinking that if I want to resolve this, it has to be a
fundamental solutionkeihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com0tag:blogger.com,1999:blog-37655209.post-61686937725482819842023-01-03T10:42:00.001+01:002023-01-03T10:43:12.019+01:00New crypto libraryLast year, I've written a portable cryptographic library
Springkussen. And then
I've also noticed that (crypto) and (math) libraries are not really
well designed. For example, a cipher object must support both encryption
and signing operations which can only be applied to RSA operations. So, I decided to
rewrite Sagittarius' cryptograpihc library and now I can show what it looks
like.
Library keihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com0tag:blogger.com,1999:blog-37655209.post-80313257972711594082022-06-20T15:03:00.003+02:002022-06-20T15:03:13.326+02:00AMQP
Sagittarius supports
AMQP,
Advanced Message Queue Protocol, since probably 0.6.x, I don't recall
which version, to be honest. The reason I wanted to support this was because
I was using QM, I think IBM MQ, at that moment at my work and wanted to send
a message from a command-line, instead of using a Web browser. Unfortunately,
the version of MQ was too old and didn't support AMQP yet. So, I keihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com0tag:blogger.com,1999:blog-37655209.post-88335808307649608222022-05-19T22:31:00.000+02:002022-05-19T22:31:09.908+02:00Markdown supportOn Sagittarius, I was, well still am, using scribble, which the parser is
ported from Chibi Scheme, to write the document. Recently, though it's
been already a couple of years, I've been thinking that using one of the
documentation formats might be better so that users can read better on
the repository if they want to use the latest version.
So, I've updated (text markdown) library to support keihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com0tag:blogger.com,1999:blog-37655209.post-4733226980368020322021-11-26T11:24:00.003+01:002021-11-26T11:24:46.204+01:00JWT と愉快な仲間たち多分2017年くらいにやるかと思って放置していた JWT 周りのサポートをようやく重い腰をあげて完了した。一応、現時点て RFC になってるものは全部入れたはず(EdDSA とか ES256K とか)。ドラフトの ECDH-1PU はそのうちファイナルになったらサポートするかもしれない。こんな感じで使える。(import (rnrs)
(rfc jwt)
(rfc jwk)
(rfc jwe)
(rfc jws)
(rfc uuid)
(crypto)
(srfi :19)
(math ec) ;; for ec-parameters
(sagittarius combinators))
(define keypair (keihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com0tag:blogger.com,1999:blog-37655209.post-70109000394004773102021-09-06T11:21:00.003+02:002022-06-20T15:06:30.439+02:00Problem of future-mapI've introduced some future related procedures, in the context of concurrency, not the future in general as I'm not a prophet. The procedures will be available after the next release, version 0.9.8, which I'm planning to release very soon.When I'm testing or writing scripts with future-map, one of the future related procedures, I've noticed there's a thread blocking issue. The future-map keihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com0tag:blogger.com,1999:blog-37655209.post-73792420688128842282021-06-25T15:28:00.002+02:002021-06-25T15:28:34.329+02:00HTTP クライアントライブラリ前回のポストから二ヶ月近く空いてしまった。要るもの追加してたら時間がかかったのと、まぁ家庭の事情というやつなので仕方ない(と自分に言い訳)ここ数年、PostMan みたいなので REST API を叩くみたいなことをしていたのだが、それ以前は Scheme で書く元気があったのに急にやらなくなったなぁという気がしていた。原因をなんとなく考えて、多分 Sagittarius に付属している HTTP 周りのライブラリが貧弱かつイマイチ使い勝手が悪いというのが原因だと結論づけた。使い勝手に関しては完全に自分の主観なので、現状の素朴な実装の方がいい場合もあるかもしれないが、本業では Apache Http Client とか Spring Framework の WebClient とか使っているので真面目なアプリ/スクリプトを書く際はその辺の使用感が欲しいというのはある。ということで作った。keihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com0tag:blogger.com,1999:blog-37655209.post-10228473187651609112021-05-06T15:18:00.004+02:002021-05-06T15:18:40.430+02:00ソケットライブラリSagittarius は随分長らくソケット周りのライブラリが二つ(SRFI も入れると三つ)あった。(sagittarius socket) と (rfc tls) である。どっちもそれなりに良くできていると思っているのだが、タイムアウト系の設定、特にコネクションタイムアウトを入れるのが大変だなぁという感じがしていた。(フラグが全部オプショナル引数なので、コネクションタイムアウトを後方互換を保ったまま入れるには引数の最後につける必要がある)。また、今時普通のソケットと TLS ソケットを分けて作るのも面倒が多いなぁと思いつつあったので、色々統合した感じのライブラリを作った。
(net socket) ライブラリはなんとなく今風な感じでソケットの作成を行うライブラリである。使い方はこんな感じ。
(import (rnrs)
(net socket))
(define keihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com0tag:blogger.com,1999:blog-37655209.post-40167923832026994672021-04-22T21:00:00.003+02:002021-04-22T21:07:16.314+02:00レコードビルダー R6RS のレコードは便利である。またポータブルに継承をしたい場合にはこれしか手がない。不便な点としてはフィールドが増えるとデフォルトのコンストラクタでは引数の数が増大するところだろう。何かしらのクライアントとか、コネクションみたいなものであれば、protocol を使って逃げる手もあるが、データ型だと面倒になってくる。引数の数が片手の数で足りなくなると尚更である。ということで、そんな悩みを緩く解決するライブラリを作ってみた。これである。使い方は非常に簡単でこんな感じで使える。
(import (rnrs)
(record builder))
(define-record-type base
(fields a b))
(define-syntax base-builder
(make-record-builder base ((a 'ok))))
keihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com0tag:blogger.com,1999:blog-37655209.post-62882578578502372042020-11-02T20:57:00.002+01:002020-11-02T20:57:31.899+01:00XML signatureIt's been a while writing a blog post. I wasn't really actively working on Sagittarius or Scheme, so there was nothing I can write. (and I was super busy with my life, incl. work). That's the excuse. I hope I will keep posting something, but I can't promise.Even though I wasn't actively writing Scheme, I've been trying to enrich XML related libraries of Sagittarius. As we, probably, all know, keihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com1tag:blogger.com,1999:blog-37655209.post-49325477354846478062019-09-10T11:25:00.003+02:002019-09-10T11:25:39.207+02:00Saven: あなたの悩みを救うかもしれないビルドツールScheme にはSNOW!、Akku等のリポジトリ的がある。個人的にはこれらに乗っかってプログラムを組んだ方が楽だと思っているのではあるが、これらのリポジトリには登録されていないライブラリの依存関係を手作業でインストールするのは面倒。個人的によく使う r7rs-postgresql、r6rs-redis はどこのリポジトリにも入ってなかったりする。GitHub にコードがあるだけで、パッケージのパの字も考慮されていない(製作者の顔が見てみたいものだ)。リポジトリが使えれば楽だが、使えない状況である。となれば、今欲しいのはリポジトリではなくビルドツールではないだろうか?
ライブラリの依存関係は割と頭の痛い問題だ。例えば、r6rs-redis は r6rs-usocket に依存していて、r6rs-usocket は r6rs-pffi と r6rs-psystem に依存している。拙作keihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com0tag:blogger.com,1999:blog-37655209.post-66834217973151943192019-07-08T15:28:00.002+02:002019-07-08T15:28:47.264+02:00ベンチマークしてみるこんなツイートを見かけた。
charのlistをequal?とか適当なcdr再帰で比較するのと、そのlistと同じ文字列が表すsymbolをeq?で比較すんのって処理どっちが早いんだろう…
— Aaron先生(でがらしのすがた) (@takum97) 1 July 2019
個人的にシンボルに変換するのはあり得ないかなと思ってはいるのだが、equal?と再帰はどっちが速いか分からない(特に Sagittarius では C 側で実装されているし)。ということでベンチマークを取ってみた。単純な比較でいいかなぁと思ったので、スクリプトは以下のようなものにした。
#!r6rs
(import (rnrs)
(bench time))
(define string (let-values (((o e) (open-string-output-port)))
keihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com0tag:blogger.com,1999:blog-37655209.post-39183550417177062452019-05-24T09:56:00.002+02:002019-05-24T09:56:43.776+02:00R6RS ライブラリ周りの解説ツイッターで R6RS のライブラリ解決の挙動について言及している呟きを見かけたので、ちょっと書いてみることにした。あくまで Sagittarius 内部ではこうしているというだけで、これが唯一解ではないことに注意。
R6RS 的なライブラリファイルの位置付け
R6RS 的にはライブラリはファイルである必要はない。ライブラリは式の定義が書かれていると記載されているだけで特にそれがどこにあるかということには言及していないからだ。これを都合よく解釈すれば、処理系の判断でライブラリを In Memory にしておいても問題ないし、マシン語の塊にしておいても問題ないということである。またライブラリは Top level のプログラムではないので、スクリプトファイルにその定義を置くことは許されていない(っが Sagittarius では利便性のため許していたりする)。
このことから、keihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com0tag:blogger.com,1999:blog-37655209.post-26066288145148773852019-04-12T15:57:00.000+02:002019-04-12T15:57:27.790+02:00R6RS MongoDB with transactionI've made a portable R6RS MongoDB library, I think, last year. Now I needed to support transaction so decided to implement it. Since MongoDB 4.0.0, it supports transactions. However, their document doesn't say which command to use or how. The only thing it mentions is I need to set up replica sets.
If you there's no documentation, then what you can do is reverse engineering. So, I've written a&keihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com0tag:blogger.com,1999:blog-37655209.post-81774066756240093262019-04-01T23:18:00.001+02:002019-04-01T23:18:20.604+02:00JSON 周りのライブラリ宝クジが大当たりしました。
四月馬鹿お終い。
Sagittarius は意外にも JSON 周りのライブラリが充実している。開発者である僕の本業が Web 系だからというのも要因の一つだと思う。一昔前の XML みたいな位置に JSON がいるのが大きい。最近書いてるアプリでこれらのライブラリをふんだんに使って我ながら便利な物を書いたものだと感心したので宣伝を兼ねて自慢することにする(これくらいの勢いじゃないとブログ書くネタがないともいう)。
簡単なクエリ
(text json pointer) は簡単な JSON クエリを提供する RFC6901 を実装したもの。対象となる JSON の構造や配列の要素番号が予め分かっている時に使える。こんな感じ
(import (rnrs) (text json pointer) (text json))
(define keihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com0tag:blogger.com,1999:blog-37655209.post-26553697854400409022019-03-15T09:07:00.002+01:002019-03-15T09:07:35.631+01:00R7RS-large タンジェリンタンジェリンってみかんじゃないのか…
2月にR7RS-largeのタンジェリンエディションがでた。ブログ記事を書こうとずっと思っていたのだが、所謂「life gets in」な状態だったので中々時間も取れずズルズルと一月以上経ってしまった(言い訳)。前回のR7RS-largeはレッドエディションだったのだが、レッドの次はオレンジなのに、いきなりタンジェリンになった。理由はこの辺(要するに準備できなかったらしい)。
さて、前置きが長いとダレるのでまずは結果。温州みかんになれたSRFIは以下:
SRFI 115 (combinator-based regular expressions) - (scheme regex)
SRFI 141 (comprehensive integer division operators) - (scheme division)
SRFI 143 (keihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com0tag:blogger.com,1999:blog-37655209.post-24053004962774366512019-01-02T11:18:00.000+01:002019-01-02T11:18:30.185+01:00(My) best practice of conditionsI've been writing portable/non-portable Scheme libraries for a rather long time and kind of getting my best practice of how to make conditions for libraries. So let me share the opinion.
Disclaimer
This is not community approved best practice nor it can be applied to the latest standard (R7RS). So I don't have any responsibility for your implementation can't handle or claims that nobody keihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com0tag:blogger.com,1999:blog-37655209.post-76518137165157930182018-12-20T14:51:00.001+01:002018-12-20T14:51:21.923+01:00(usocket): R6RS portable socket library
Motivation
When I wrote the MongoDB client library in R6RS portable manner, I have included socket procedures inside of the library. Now, I want to write Redis client, then I've noticed that it's very inconvenient that if there's no R6RS portable socket library. We have SRFI 106 for a socket library, however, it's not widely implemented especially on R6RS implementations. So I've keihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com2tag:blogger.com,1999:blog-37655209.post-16586922428950788862018-12-02T00:00:00.000+01:002018-12-02T11:07:54.868+01:00SRFI-123の紹介この記事は Lisp SETF Advent Calendar 2018 二日目の為に書かれました。
0x25歳になって最初に書く記事です(実際には投稿予約の機能を使っているので数日若いが…)。いい感じの区切りの歳の最初の記事としてはイマイチな題材かもしれないなぁとも思いつつ…
SRFI 123: Generic accessor and modifier operators は Taylan Ulrich Bayırlı/Kammer によって提唱された Gauche 風の総称アクセサを提供する SRFI です。取りあえず簡単な例を見てこれの何が嬉しいのかというのを確認してみましょう。
(import (rnrs) (srfi :123))
(define l (list (list 1) 2 3)) ;; Must not a literal list :)
(ref 1 keihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com0tag:blogger.com,1999:blog-37655209.post-57987064795272912232018-10-08T15:48:00.002+02:002018-10-08T15:48:53.865+02:00JMESPathJSON用のクエリーがほしいなぁと思いいろいろ探していたのだが、まともな仕様があるものが少ない。JSONPathは超有名なブログ記事のみで今一不安だし、JSONiqはちょっとしたクエリ書くだけにしては巨大すぎる感があるし、JSON Queryでググると山のようにオレオレ実装が出てきて嫌気がしたというのがある。(今思えばJSONiqでもよかった気はする)
そんな中で手ごろなサイズでそれなりに仕様が固まっていて、AWS CLIでも使われているらしいJMESPathなるものを知った。名前は微妙だけど(提唱者名が入ってる)AWS CLIで使われているということはそれなりに実績もあるんだろうし、準拠テストもあるしこれでいいかということで実装してみた。(ここまで前置き)
ということで、こんな感じで使える
(import (rnrs) (text json jmespath))
((keihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com0tag:blogger.com,1999:blog-37655209.post-62391437118232654852018-09-16T17:29:00.003+02:002018-09-16T17:29:19.224+02:00JSON パーサJMESPathの実装をしていてJSONのパーサをPEGで書いた方が便利だなぁということに気付いたので実装してみた。仕様は最新のJSONの仕様(RFC8259)を参照することにした(別にjson.orgのでもよかったんだけど、なんとなく。どうせ一緒だろ?)。
どうでもいいのだが、「\」を使った文字列のエスケープがかなり制限されてる気がする。「\a」とか「\c(意味のないエスケープ)」とかは仕様に従うならイリーガルになるっぽい。どうしようかな?
書きあえるにあたって気になるのはもちろんパフォーマンス。以前使っていたPackratの実装だと現在の実装に比べて30倍程度遅い(参照: JSONパーサの性能改善)。ということで書いた後にベンチマークをとってみる。こんな感じのコードで測る。結論だけ先に言えば、現在の実装はかなり速いので、いろんな角度で速度を計測した。I/O有、I/O無等。
(keihttp://www.blogger.com/profile/04280471934183261698noreply@blogger.com0