ときどきの雑記帖 RE* (新南口)
2020年12月5日
小ネタ拾い (小ネタでないものを書いたことがあるのかというハナシはさておき)。
lint
p5js web editorに日本語を加えた話 - Qiita
これはlintだけの話なんですが、NYに来てから、技術関連の会話以外で単語を聞いた事ない上に、 日本でも開発チーム内で使うくらいなので、扱いどうするべきか悩みました。 最終的には自分がITPでRessearcherやってた時に学生にlintを使った時に返ってきた"You、何言ってんの"という反応と、 p5js自体がプログラミング教育に重きをおいている点を考慮して、リントを採用しました。
ここでいう lint って起源をたどれば jargon fileにもある lint だろうから、知ってる人はまあ少ないだろうとは思う (とは言えプログラミング関連では見かける頻度が linter なども含めて上がっているように感じる)。
そもそも プログラミングにおける lint trap - Google 検索 から来た名前で、さらにそれを略したlintだけみてもなんのこっちゃという話なんだろう lintの意味・使い方・読み方 | Weblio英和辞書。
(ツールとしての)lint の名前の由来がどこかにあったなと思い検索すると、
(半ば予想通りではあったが) 日本語版Wikipedia lint - Wikipedia にはなく、 英語版にはあった lint (software) - Wikipedia。
英語版のlintの項の Historyによると
Stephen C. Johnson, a computer scientist at Bell Labs, came up with lint in 1978 while debugging the yacc grammar he was writing for C and dealing with portability issues stemming from porting Unix to a 32-bit machine.[3][2] The term “lint” was derived from the name of the tiny bits of fiber and fluff shed by clothing. In 1979, lint was used outside of Bell Labs for the first time in the seventh version (V7) of the Unix operating system.
日本語では以下のものが見つかった。
Steve Johnson が lint を作った時に、このプログラムがやっていることが乾燥機のリントトラップ (糸くず取り) に似ていることに気づいて (本来あってはならない、ふわふわしたくずをすべて摘みとり、とらえることが仕事)、最初は『リントトラップ』と名づけようと考えたが、 当時の UNIX では4 文字以上の命令が使えなかったので『lint』と命名したそうである。文献によっては、 包帯やガーゼ用の布 lint が名の由来で、 C のプログラムに関して極度にきれい好きだからこの名がつけられた、と書いてあるものもある。
lintとは元々「リント」という布(リンネルの片面を起毛して柔らかくした布で昔の包帯などに用いられた)または「糸くず」の意で、 乾燥機の糸くず取り(lint trap)から余計なゴミを取り除く様をプログラム名として流用したものである。
ところで実はこのlintにはオライリーから解説書 Checking C Programs with Lint: C Programming Utility (Nutshell Handbooks) (英語) が出ていた。 日本語訳 lint (UNIXユーティリティライブラリ) 単行本 – 1990/12/1 も出ていたのだけど、それはオライリージャパンができる前、 オライリーの翻訳本が複数の出版社から出ていた はるかな昔のお話でございます。
さらに脱線すると、この翻訳本を以前ここに欲しいと書いたら譲ってもらったことがある (当時は古本でも手に入らなかったような気がする)。 その方の名前も思い出せないし(ごめんなさい) やりとりしたメールも見つけられないのだけど、 あの時はありがとうございました。
Shell Parameter Expansion
つづき。
【シェル芸人への道】Bashの変数展開と真摯に向き合う - Qiita
の記事にある
- 【シェル芸人への道】Bashの変数展開と真摯に向き合う - Qiita
- 【シェル芸人への道】Bashの変数展開と真摯に向き合う - Qiita
- 【シェル芸人への道】Bashの変数展開と真摯に向き合う - Qiita
のそれぞれの例の見出しを見ると、
${parameter^pattern}: 大文字化
小文字の大文字化だってできます。
大文字化$ echo ${hoge} hoge-value
$ echo ${hoge^} Hoge-value
のように、記号の後にも「パラメーター」が置けるように見える(例そのものには置かれていないけど)。 実際マニュアルでも
Shell Parameter Expansion (Bash Reference Manual)
${parameter^pattern}
${parameter^^pattern}
${parameter,pattern}
${parameter,,pattern}
のように書かれていて
This expansion modifies the case of alphabetic characters in parameter. The pattern is expanded to produce a pattern just as in filename expansion. Each character in the expanded value of parameter is tested against pattern, and, if it matches the pattern, its case is converted. The pattern should not attempt to match more than one character. The ‘^’ operator converts lowercase letters matching pattern to uppercase; the ‘,’ operator converts matching uppercase letters to lowercase. The ‘^^’ and ‘,,’ expansions convert each matched character in the expanded value; the ‘^’ and ‘,’ expansions match and convert only the first character in the expanded value. If pattern is omitted, it is treated like a ‘?’, which matches every character. If parameter is ‘@’ or ‘’, the case modification operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with ‘@’ or ‘’, the case modification operation is applied to each member of the array in turn, and the expansion is the resultant list.
pattern
の部分では、変換の対象を指定するようだ。省略した場合は
If pattern is omitted, it is treated like a ‘?’, which matches every character.
と。
How To Use Bash Parameter Substitution Like A Pro
タイミングよく?
- (1) How To Use Bash Parameter Substitution Like A Pro : programming
- How To Use Bash Parameter Substitution Like A Pro - nixCraft
という記事が。reddit にあるコメント (1) How To Use Bash Parameter Substitution Like A Pro : programming の
Parameter substitution is only as good as the supporting documentation and in-line comments. Otherwise it becomes a cryptic, abstract mess.
にはまあそうだよねえという感想になる。 それはそれとして言及されている記事の 8. Convert to upper to lower case or vice versa にある例を試してみると
$ dest="Home"
echo "${dest,H}"
$ echo "${dest,H}"
home
$ dest="Fhome"
$ echo "${dest,H}"
Fhome
なるほど。
ところで cryptic で思い出したのは、 Perl や Ruby の .. と … は後から知った人にはとても cryptic だけど swift では少しわかりやすくなっているよね 【Swift】範囲型について - Qiita という話。
I, J, K, …
うぃきぺにこんな記述いつからあったんだろう (編集履歴は調べない)
FORTRANのプログラムにおいては、とくに型宣言をしない場合、アルファベットI,J,K,L,M,Nのいずれかで始まる変数名で表される変数は 整数型(integer)になり、その他のアルファベット(A~H, O~Z)で始まるものは実数型(real)になる。これが「暗黙の型宣言」 といわれるFORTRANの文法上の規則である。なお、この命名規則についてBakusは『Iから始まる6文字に決まったのは、みんな添え字に I、J、Kをつかっていたので、(L、M、Nを)気前よく増やした。』と言っている[1]。
ちゃんとBakusの発言へのリンクがあって偉い (ある意味当然のことではあるのだけど)。
Ruby
Ruby のリポジトリで ruby/.gdbinit at ruby_2_7 · ruby/ruby · GitHub にこんな部分があるのに遭遇した。
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
Autocoder / Autocode
とても似た名前だが違うもののようだ