ときどきの雑記帖 RE* (新南口)
冬の稲妻
今週のしずえさん
1月25日は「中華まんの日」
Quasi
南武線車内で流れる多言語一行ニュース(正式名称は知らない) で蔓延防止なんちゃらのニュースが流れてたのだけど、 あれって英語では「Quasi-Emergency」のような表現するのね。
Quasiと言う単語はまあLispプログラマーにはおなじみですかね。
- Tokyo, 12 other areas to be under quasi-emergency | NHK WORLD-JAPAN News
- Japan decides to put Tokyo, 12 more areas under COVID quasi-emergency
- Quasi-quotation - Wikipedia
- 準クオート (Gauche ユーザリファレンス)
1/19
「1/19は一年の1/19」っての見てすげ〜と思って調べてみたら他にも2日あって
— 鯵坂もっちょ🐟『つれづれなる数学日記』好評発売中! (@motcho_tw) January 19, 2022
「4/14は一年の4/14」だったし
「8/13は一年の8/13」だった
ということで(ry
$ ruby -rdate -e 'puts (Date.new(2022,1,1)..Date.new(2022,12,31)).select{_1.yday == (365.0*_1.month/_1.day).round}'
2022-01-19
2022-04-14
2022-08-13
なるほど。
i option of gawk
前回書いたこと の訂正とか補足とか。
そしてgawkに
-i
(inplace edit)オプションがついたことはないはずなんだがなぜ?
と書いたのだけど、実はiオプションそのものはある。
kbk@toybox4:/mnt/c/Users/kbk$ gawk --help
Usage: gawk [POSIX or GNU style options] -f progfile [--] file ...
Usage: gawk [POSIX or GNU style options] [--] 'program' file ...
POSIX options: GNU long options: (standard)
-f progfile --file=progfile
-F fs --field-separator=fs
-v var=val --assign=var=val
Short options: GNU long options: (extensions)
-b --characters-as-bytes
-c --traditional
-C --copyright
-d[file] --dump-variables[=file]
-D[file] --debug[=file]
-e 'program-text' --source='program-text'
-E file --exec=file
-g --gen-pot
-h --help
-i includefile --include=includefile
-l library --load=library
-L[fatal|invalid|no-ext] --lint[=fatal|invalid|no-ext]
-M --bignum
-N --use-lc-numeric
-n --non-decimal-data
-o[file] --pretty-print[=file]
-O --optimize
-p[file] --profile[=file]
-P --posix
-r --re-interval
-s --no-optimize
-S --sandbox
-t --lint-old
-V --version
To report bugs, see node `Bugs' in `gawk.info'
which is section `Reporting Problems and Bugs' in the
printed version. This same information may be found at
https://www.gnu.org/software/gawk/manual/html_node/Bugs.html.
PLEASE do NOT try to report bugs by posting in comp.lang.awk,
or by using a web forum such as Stack Overflow.
gawk is a pattern scanning and processing language.
By default it reads standard input and writes standard output.
Examples:
gawk '{ sum += $1 }; END { print sum }' file
gawk -F: '{ print $1 }' /etc/passwd
include
のi
だけどね
(自分では使わない機能だからすっかり忘れてたわ)。
いつ頃入ったかというとずいぶん前のことでこの辺。
Changes from 4.0.2 to 4.1.0
---------------------------
1. The three executables gawk, pgawk, and dgawk, have been merged into
one, named just gawk. As a result:
* The -R option is gone
* Use -D to run the debugger. An optional file argument is a
list of commands to run first.
* Use -o to do pretty-printing only.
* Use -p to do profiling.
This considerably reduces gawk's "footprint" and eases the documentation
burden as well.
2. Gawk now supports high precision arithmetic with MPFR. The default is
still double precision, but setting PREC changes things, or using
the -M / --bignum options. This support is not compiled in if the MPFR
library is not available.
3. The new -i option (from xgawk) is used for loading awk library files.
This differs from -f in that the first non-option argument is treated
as a script.
4. The new -l option (from xgawk) is used for loading dynamic extensions.
5. The dynamic extension interface has been completely redone! There is
now a defined API for C extensions to use. A C extension acts like
a function written in awk, except that it cannot do everything that awk
code can. However, this allows interfacing to any facility that is
available from C. This is a major development, see the doc, which has
a nice shiny new chapter describing everything.
This support is not compiled in if dynamic loading of shared libraries
is not supported.
The old extension mechanism is still supported for compatiblity, but
it will most definitely be removed at the next major release.
6. The "inplace" extension, built using the new facility, can be used to
simulate the GNU "sed -i" feature.
7. The and(), or() and xor() functions now take any number of arguments,
with a minimum of two.
8. New arrays: SYMTAB, FUNCTAB, and PROCINFO["identifiers"]. SYMTAB allows
indirect access to any defined variable or array; it is possible to
"walk" the symbol table, if that should be necessary.
9. Support for building gawk with a cross compiler has been improved.
10. Infrastructure upgrades: bison 2.7.1, gettext 0.18.2.1, automake 1.13.1,
libtool 2.4.2 for the extensions.
で、この6番にあるけど拡張という形でinplace editingが実装されてはいる (こっちは覚えていたけど前回書いていなかった)。
mac awk
awkネタをもうひとつ。
なんか会員登録しないと読ませてもらえない記事だったのだけど
- にわか管理者のためのLinux運用入門(315) Macで行く - Mac awkとGNU awkの違いを知る | TECH+
- にわか管理者のためのLinux運用入門(314) Macで行く - Mac awkとGNU awk | TECH+
というものがあるのを見かけた。 後者については検索したところ会員登録しないでも読めるところ にわか管理者のためのLinux運用入門 第314回 Macで行く - Mac awkとGNU awk:マピオンニュース も見つかったけど、会員登録しないとかけらも読ませてもらえない記事(のリンク)を こういうところ 新着記事一覧(1ページ目) | マイナビニュース に混ぜるのはどうなんだろう?
まあそれはさておき
gawkやnawkとの最大の違いは実行速度にある。mawkはバイトコードへ変換してから処理を実行するため、実行速度が速い。 nawkで実行できるものであれば、インタプリタをnawkからmawkへ入れ替えるだけで処理時間が短くなる。
という記述があったりしたが、gawkも今はバイトコード形式になってるんですけどね (と言ってmawk並みに速くなったかというとそうではない)。 記事書いたの誰よ?と名前を確かめたら…
まあそれはさておき、いつ変わったかというと公式のバージョンでは4.0になった時点。
ChangeLog.0
Sun Oct 10 15:30:34 2010 Arnold D. Robbins <arnold@skeeve.com>
MERGE with bytecode version! Many many files changed / added.
ChangeLogには(たぶん)これだけしか記述がなくて、 NEWSでは一行も触れられていないのでちょっとびっくりした。
検索するとA look at Gawk 4.0.0 [LWN.net] という記事があった。他にもArnoldがなにやら論文を書いていたようなのだけど paywallの向こうで中身の確認はできず。
To find out what was revamped, and why, I asked Gawk maintainer Arnold Robbins by email. It turns out that the revamp has a lengthy history. Robbins says that “some years ago” John Haque took on rewriting Gawk’s internals using a byte-code-style engine — and to implement a debugger in the process. Unfortunately, that work wasn’t integrated and Haque moved on. In early 2010, Robbins started trying to bring Haque’s code up to date. According to Robbins, the rewrite doesn’t provide a huge performance boost, but it does bring a major useful feature:
The performance is about the same (or slightly better) than the original internals, and I have not yet found a case where it’s worse. But the really big gain, and why I wanted to have the change, is that gawk now provides an awk-level debugger (similar to GDB).
locale
posixのchalacter class の話の続き。
glibcのソースツリーの localedata/localesに 色々なlocale用の定義があるのだけど、
- ja_JP
- ko_KR
- zh_CN
の三つでそのlocale独自の文字クラスを定義している模様。
たとえばja_JPだとLC_CTYPE
のところで
% This is a copy of the "i18n" LC_CTYPE with the following modifications:
% - Additional classes: jspace jhira jkata jkanji jdigit
% - Additional maps: tojhira tojkata
というコメントがあって、その通りjspaceなどのAdditional classesの定義と Additional mapsの定義がある。
copy "i18n"
charclass jspace;jhira;jkata;jkanji;jdigit
charconv tojhira;tojkata
jspace <U3000>
jdigit <UFF10>;<UFF11>;<UFF12>;<UFF13>;<UFF14>;/
<UFF15>;<UFF16>;<UFF17>;<UFF18>;<UFF19>
jhira <U3041>;<U3042>;<U3043>;<U3044>;<U3045>;<U3046>;<U3047>;<U3048>;/
<U3049>;<U304A>;<U304B>;<U304C>;<U304D>;<U304E>;<U304F>;<U3050>;/
<U3051>;<U3052>;<U3053>;<U3054>;<U3055>;<U3056>;<U3057>;<U3058>;/
<U3059>;<U305A>;<U305B>;<U305C>;<U305D>;<U305E>;<U305F>;<U3060>;/
<U3061>;<U3062>;<U3063>;<U3064>;<U3065>;<U3066>;<U3067>;<U3068>;/
<U3069>;<U306A>;<U306B>;<U306C>;<U306D>;<U306E>;<U306F>;<U3070>;/
<U3071>;<U3072>;<U3073>;<U3074>;<U3075>;<U3076>;<U3077>;<U3078>;/
<U3079>;<U307A>;<U307B>;<U307C>;<U307D>;<U307E>;<U307F>;<U3080>;/
<U3081>;<U3082>;<U3083>;<U3084>;<U3085>;<U3086>;<U3087>;<U3088>;/
<U3089>;<U308A>;<U308B>;<U308C>;<U308D>;<U308E>;<U308F>;<U3090>;/
<U3091>;<U3092>;<U3093>;<U309B>;<U309C>;<U309D>;<U309E>;<U30FC>
以下長いので略
ko_KR と zh_CNは短い。
LC_CTYPE
% This is a copy of the "i18n" LC_CTYPE with the following modifications:
% - Additional classes: hangul hanja
copy "i18n"
charclass hangul;hanja
hangul <UAC00>..<UD7A3>
hanja <U3400>..<U4DB5>;<U4E00>..<U9FA5>;<UF900>..<UFA0B>;<UFA0C>..<UFA2D>
translit_start
include "translit_combining";""
include "translit_hangul";""
translit_end
END LC_CTYPE
LC_CTYPE
% This is a copy of the "i18n" LC_CTYPE with the following modifications:
% - Additional classes: hanzi
copy "i18n"
translit_start
include "translit_combining";""
translit_end
class "hanzi"; /
% <U3400>..<U4DBF>;/
<U4E00>..<U9FA5>;/
<UF92C>;<UF979>;<UF995>;<UF9E7>;<UF9F1>;<UFA0C>;<UFA0D>;<UFA0E>;/
<UFA0F>;<UFA11>;<UFA13>;<UFA14>;<UFA18>;<UFA1F>;<UFA20>;<UFA21>;/
<UFA23>;<UFA24>;<UFA27>;<UFA28>;<UFA29>
END LC_CTYPE
この二つでは独自のtoXXXXXはないんすね。
その他、中国語(zh_**)でいくつか設定をzh_CNからコピーしているものがある。
LC_CTYPE
copy "zh_CN"
END LC_CTYPE
LC_CTYPE
copy "zh_CN"
END LC_CTYPE
LC_CTYPE
copy "zh_CN"
END LC_CTYPE
tcl
「なら戦わなくっちゃ!」 pic.twitter.com/WgOLSJZH43
— zick (@zick_minoh) January 11, 2022
そうか、The Tcl War ってこの頃の「ホットな話題」だったか。 当時rmsが主張していた手法(すごく大雑把に書くとJITトランスパイラー(not コンパイラー)?)には 「そんなん現実的に使えるものになるのか」 という感想しかなかったのだけど 今ならそうでもない?
BeagleVってその後(大量生産には入らず)中止になったんだよな。GIGAZINEは古い記事を流すのなら適切な注釈を入れるべきでは https://t.co/mQLR84xUHv
— mod_poppo (@mod_poppo) January 17, 2022
この辺の話ですか。
まあGIGAZINEはねえ…
えっ?若者はuuencode知らないんですか?
— Yosuke HASEGAWA (@hasegawayosuke) January 17, 2022
ishとかもっと知られてないな。きっと😄