ときどきの雑記帖 倒行逆施編

最新ページへのリンク
目次ページへのリンク

一つ前へ 2016年2月(下旬)
一つ後へ 2016年3月(中旬)

ホームへ

2016年03月10日

■_

元記事から一か月以上経って出た翻訳記事を見て、 それがつい最近のものであるかのように受け取るなんて……

■_

2016年03月09日

■_

今週の百分で名著SPもなんだかなーな内容だったなあ。 来週(と再来週)はもういいかな。

この記事、 新卒が冬のボーナスで購入したプログラミング書籍一覧 - Qiita 購入して読もうという本が洋書ばかりなのに感心した その理由も書いてあるんだけど、それはそれとして

新卒が冬のボーナスで購入したプログラミング書籍一覧 - Qiita

全然関係ないですが、Amazon.comの方では2015年現在でも高レビューがつくような書籍でも、Amazon.co.jpでは中古本しかない、 みたいな本がいくつかあって、日本のプログラマと海外のプログラマの間でよく買われる本や流行る本は結構違うのかな、 という印象でした。なので、海外の動向がきになる人は、 Amazon.comの書籍コーナーをウォッチリストに加えてみるのも良いかもしれませんね。

油断すると絶版状態になるのはよくあることですからねえ。 出る数とか(それを踏まえた上での)契約の問題なんだろうけど。

■_

2016年03月08日

■_

PASMO の設定変更完了。 新しいタイプの券売機だととても楽だった (でなければ定期券売り場の窓口に行ってごにょごにょ…だったらしい)

■_

■_

なぜマニュアルを見ないのだろう… Bashの括弧 - 超ウィザード級ハッカーのたのしみ

で、調べてみたら結構バラバラで探すのに苦労したw (少なくとも、索引からすぐ。というわけにはいかなかった) Bash Reference Manual 3.5.1 Brace Expansion

Bash Reference Manual

3.2.4.2 Conditional Constructs 
(略)
((…)) 
 
 (( expression )) 

The arithmetic expression is evaluated according to the rules described below (see Shell Arithmetic). If the value of the expression is non-zero, the return status is 0; otherwise the return status is 1. This is exactly equivalent to

 let "expression" 
 
 See Bash Builtins, for a full description of the let builtin. 
[[…]] 
 
 [[ expression ]] 

Return a status of 0 or 1 depending on the evaluation of the conditional expression expression. Expressions are composed of the primaries described below in Bash Conditional Expressions. Word splitting and filename expansion are not performed on the words between the [[ and ]]; tilde expansion, parameter and variable expansion, arithmetic expansion, command substitution, process substitution, and quote removal are performed. Conditional operators such as ‘-f’ must be unquoted to be recognized as primaries.

Bash Reference Manual

3.2.4.3 Grouping Commands 

Bash provides two ways to group a list of commands to be executed as a unit. When commands are grouped, redirections may be applied to the entire command list. For example, the output of all the commands in the list may be redirected to a single stream.

() 
 
 ( list ) 

Placing a list of commands between parentheses causes a subshell environment to be created (see Command Execution Environment), and each of the commands in list to be executed in that subshell. Since the list is executed in a subshell, variable assignments do not remain in effect after the subshell completes.

{} 
 
 { list; } 

Placing a list of commands between curly braces causes the list to be executed in the current shell context. No subshell is created. The semicolon (or newline) following list is required.

In addition to the creation of a subshell, there is a subtle difference between these two constructs due to historical reasons. The braces are reserved words, so they must be separated from the list by blanks or other shell metacharacters. The parentheses are operators, and are recognized as separate tokens by the shell even if they are not separated from the list by whitespace.

The exit status of both of these constructs is the exit status of list.

Bash Reference Manual

3.5.3 Shell Parameter Expansion 

The ‘$’ character introduces parameter expansion, command substitution, or arithmetic expansion. The parameter name or symbol to be expanded may be enclosed in braces, which are optional but serve to protect the variable to be expanded from characters immediately following it which could be interpreted as part of the name.

When braces are used, the matching ending brace is the first ‘}’ not escaped by a backslash or within a quoted string, and not within an embedded arithmetic expansion, command substitution, or parameter expansion.

The basic form of parameter expansion is ${parameter}. The value of parameter is substituted. The parameter is a shell parameter as described above (see Shell Parameters) or an array reference (see Arrays). The braces are required when parameter is a positional parameter with more than one digit, or when parameter is followed by a character that is not to be interpreted as part of its name.

Bash Reference Manual

3.5.4 Command Substitution 

Command substitution allows the output of a command to replace the command itself. Command substitution occurs when a command is enclosed as follows:

$(command) 
 
or 
 
`command` 

Bash performs the expansion by executing command and replacing the command substitution with the standard output of the command, with any trailing newlines deleted. Embedded newlines are not deleted, but they may be removed during word splitting. The command substitution $(cat file) can be replaced by the equivalent but faster $(< file).

以下略
Bash Reference Manual

3.5.5 Arithmetic Expansion 

Arithmetic expansion allows the evaluation of an arithmetic expression and the substitution of the result. The format for arithmetic expansion is:

$(( expression )) 

The expression is treated as if it were within double quotes, but a double quote inside the parentheses is not treated specially. All tokens in the expression undergo parameter and variable expansion, command substitution, and quote removal. The result is treated as the arithmetic expression to be evaluated. Arithmetic expansions may be nested.

The evaluation is performed according to the rules listed below (see Shell Arithmetic). If the expression is invalid, Bash prints a message indicating failure to the standard error and no substitution occurs.

Bash Reference Manual

3.5.6 Process Substitution 

Process substitution is supported on systems that support named pipes (FIFOs) or the /dev/fd method of naming open files. It takes the form of

<(list) 
 
or 
 
>(list) 

The process list is run with its input or output connected to a FIFO or some file in /dev/fd. The name of this file is passed as an argument to the current command as the result of the expansion. If the >(list) form is used, writing to the file will provide input for list. If the <(list) form is used, the file passed as an argument should be read to obtain the output of list. Note that no space may appear between the < or > and the left parenthesis, otherwise the construct would be interpreted as a redirection.

When available, process substitution is performed simultaneously with parameter and variable expansion, command substitution, and arithmetic expansion.

Bash Reference Manual

6.7 Arrays 
(略)
 
Arrays are assigned to using compound assignments of the form 
 
name=(value1 value2 … )

■_

sedの-iオプションの非互換 - Qiita これ、「シェル」じゃなくてgetopt(とgetopt_long)の仕様の違いじゃないのかね。 訳がちとあれだけど日本語のやつで。 GETOPT(3) - 標準Cライブラリ関数 - YOS OPENSONAR

GETOPT(3) - サブルーチン - YOS OPENSONAR

getopt() 関数は、コマンドラインの引数リスト argv を増加させながら解析して、次の 既知 オプション文字を返します。 受け入れオプション文字集合 optstring に指定されていた場合、そのオプション文字は、 既知 です。

オプション文字列 optstring は、次の要素を含めます。個々の文字と、 後にオプションの引数が続くことを意味する後にコロンが付いた文字です。 例えば、オプション文字列 "x" は、オプション“ -x”と認識され、オプション文字列 "x:" は、 オプションと引数“ -x argument”と認識されます。後に続く引数に先導する空白があっても、 getopt() には重要ではありません。

getopt() から戻った時、 optarg は、それが予期されていればオプションの引数を指しており、変数 optind は、 続く getopt() 呼び出しのための argv 引数のインデックスが含まれます。変数 optopt は、 getopt() によって返された最後の 既知 オプション文字を保存してます。

BSD はこうだけど

Man page of GETOPT

struct option { 
 const char *name; 
 int has_arg; 
 int *flag; 
 int val; 
}; 
 
それぞれのフィールドの意味は以下の通り。 

name 

長いオプションの名前。

has_arg

no_argument (または 0) なら、オプションは引き数をとらない。 required_argument (または 1) なら、 オプションは引き数を必要とする。 optional_argument (または 2) なら、 オプションは引き数をとっても とらなくても良い。

で、実際 GNU sed では
#define COPYRIGHT_NOTICE "Copyright (C) 2003 Free Software Foundation, Inc."

/*  GNU SED, a batch stream editor.
    Copyright (C) 1989,90,91,92,93,94,95,98,99,2002,2003
    Free Software Foundation, Inc.

(略)

int
main(argc, argv)
  int argc;
  char **argv;
{
#ifdef REG_PERL
#define SHORTOPTS "bsnrRuEe:f:l:i::V:"
#else
#define SHORTOPTS "bsnruEe:f:l:i::V:"
#endif

  static struct option longopts[] = {
    {"binary", 0, NULL, 'b'},
    {"regexp-extended", 0, NULL, 'r'},
#ifdef REG_PERL
    {"regexp-perl", 0, NULL, 'R'},
#endif
    {"expression", 1, NULL, 'e'},
    {"file", 1, NULL, 'f'},
    {"in-place", 2, NULL, 'i'},
    {"line-length", 1, NULL, 'l'},
    {"quiet", 0, NULL, 'n'},
    {"posix", 0, NULL, 'p'},
    {"silent", 0, NULL, 'n'},
    {"separate", 0, NULL, 's'},
    {"unbuffered", 0, NULL, 'u'},
    {"version", 0, NULL, 'v'},
    {"help", 0, NULL, 'h'},
#ifdef ENABLE_FOLLOW_SYMLINKS
    {"follow-symlinks", 0, NULL, 'F'},
#endif
    {NULL, 0, NULL, 0}
  };
(略)
  while ((opt = getopt_long(argc, argv, SHORTOPTS, longopts, NULL)) != EOF)
    {
      switch (opt)
	{
(略)

	case 'i':
	  separate_files = true;
	  if (optarg == NULL)
	    /* use no backups */
	    in_place_extension = ck_strdup ("*");

	  else if (strchr(optarg, '*') != NULL)
	    in_place_extension = ck_strdup(optarg);

	  else
	    {
	      in_place_extension = MALLOC (strlen(optarg) + 2, char);
	      in_place_extension[0] = '*';
	      strcpy (in_place_extension + 1, optarg);
	    }

	  break;

(オプションに対する引数が)省略可能な指定になってて、 オプション解析の部分でも optarg == NULL で引数があるか判定して切り分けてる。

おまけ。

$ cat >foo.sh
echo $1
echo $2

$ bash foo.sh aaa bbb
aaa
bbb

$ bash foo.sh '' aaa bbb

aaa

$ bash foo.sh ''aaa bbb
aaa
bbb

2016年03月07日

■_

何日か前から、改札を通るときにPASMOのチャージ額の他に なにかメッセージが出てたのだけど、 後ろにも人がいるときにそれを読んでる余裕はなかったし 定期の期限はまだ先のはずということでそのままだったのが 人が続いてこないタイミングを狙ってゆっくり通って確かめた。 すると「オートチャージの期限切れ」みたいなメッセージで、 (オートチャージ用の)クレジットカードの期限とは別に この機能にも期限が設定されてたらしい。 しらんかったわー(あるいはすっかり忘れてた)。

某所で逆向き傘が売っているのを目撃。 値段はまあさておき、思ったより(傘の大きさが)小さいのねあれ。 普段70cm使ってるんであれではもの足りん。

■_

■_

ささださんがこーゆーツイートをしてたので、 「最後」ってなんかあったっけと疑問に思い調べてみた。これか?

372 付録A さらにそのほかのRuby 仮想マシン

(略)本書はRuby 2.0 をベースに紹介しているが、Ruby 2.1 では、さらに品質を向上するためにさまざまな修正 を行った。そして、これからリリースする予定であるRuby 2.2 を、より良いものにするため、改善を続けている。

たとえば、キーワード引数の改善である。 本書の第4 章では、キーワード引数の実装方法について紹介している。 (略) この実装は非効率である。メソッド呼び出しごとにHash オブジェクトが生成されることになり、 Hash オブジェクト生成、およびGC のコストがかかる。 また、暗黙に展開されるHash オブジェクトの読み込みも、複数のメソッド呼び出しを含むため、遅い。

この問題を改善するため、Ruby 2.2 から、可能な限りHash オブジェクトを生成 しないようにキーワード引数を実装し直した。その代わり、コンパイル時にキー ワード引数の名前をまとめておき、呼び出し側では値のみ渡すことにした。そし て、受け側では渡された値と、コンパイル時に作成した名前を用いて対を復元す るようにした。この工夫によりキーワード引数を用いるメソッド呼び出しを、場 合によっては10 倍以上高速化することができた。

【ruby】キーワード引数のメソッド呼び出しは遅い!しかし2.2.0-preview2 以降で劇的に改善されていた話 - 圧倒亭グランパのブログ

「Rubyのしくみ」を読んでいたら、「キーワード引数って遅いんじゃないか?」と思ったので調べてみました。 
 
まずは結果から。 
 
rubyの各バージョンで、キーワード引数がどのくらい遅いのかを調べてみました。

なるほど。

2016年03月06日

■_

田園都市線の人身事故による遅延の影響を受けた(-10点)

■_

■_

Issues · ThomasDickey/original-mawk
  https://github.com/ThomasDickey/original-mawk/issues
mawk - pattern scanning and text processing language
  http://invisible-island.net/mawk/mawk.html
MAWK - Freecode
  http://freecode.com/projects/mawk

■_

7 leadership lessons from a first-time manager - Lucidchart

  1. Ask people to do hard things
  2. Know each team member
  3. Protect the team’s time
  4. Foster a culture of trying
  5. Let the team be the heroes
  6. Don’t be so serious
  7. Be prompt with difficult conversations
  Bonus: care about each individual

2016年03月05日

■_

いつものように購入 歴史群像 2016年 04 月号 [雑誌]
歴史群像 2016年 04 月号 [雑誌] 歴史群像―学研デジタル歴史館-「雑誌 歴史群像」

LambdaNative: Scheme for Mobile, Desktop, and Embedded Cross-Platform Development で紹介されている ここ、 何日か前に HN でも言及しているスレッドがあったと思うんだけど(それでアクセスした)、 ページの最初にある Development Time (Hours) の図のこれは なんだろう? 箱ひげ図なら黒いバーはないし、いったい…… ところでこの記事翻訳出ますかね?

■_

■_

No Starch Press を何の気なしに眺めてたら Game Console | No Starch Press という本があるのに気づいたんだけど The Game Console is a tour through the evolution of video game hardware, with gorgeous full-color photos of 86 consoles. ほー。

2016年03月04日

■_

The Joy and Agony of Haskell in Production にあったDon’t be afraid to train people. ってどういう意味かとちと悩んだのだけど これ、train は動詞か。 trainの意味 - 英和辞典 Weblio辞書 「train people」ってなにものとか考えちゃったよw

■_

■_

Strcpyのソースコードを見比べてみる - Qiita http://qiita.com/mitkot/items/a1b86095ad3647d5035e

■_

Feature #12142: Hash tables with open addressing - Ruby trunk - Ruby Issue Tracking System

  GCC has widely-used such hash tables

へー。

■_

Mathematica 10.4 Released - Increased functionality and improvements : programming https://redd.it/48s4ua Open source Mathematica clone Mathics version 0.9 released : programming https://redd.it/48idix https://groups.google.com/forum/#!topic/mathics-users/cDoYP-04AM8

2016年03月03日

■_

何日か前の、とある新聞の連載記事(だったと思う)で 「(コンピューターの)ソフトウェアもハードウェアも元を辿っていくと フォン・ノイマンに行き着く」みたいなことが書かれていて以下略

あれとかあれとか行きそびれたなあ○| ̄|_

会社最寄りの駅近くにあったマクドナルドが閉店してた。 (駅周辺で進められている)再開発の影響とかもあったりするんだろうか。 あの辺りいかにもな感じだし。

■_

■_

with はこういう使い方もあったのか

CSVを1行ずつフィールドの型変換をしながら読み込んで(プログレスバーも表示しながら)処理したい - Qiita


def foobar(csv_path):
    with CSV_Iterator(csv_path,
                  skip_header=True,
                  with_progress_bar=True,
                  field_converter=FieldConverter(int, int, 'iso-8859-1', 'iso-8859-1', float)) as line:
        for id, uid, title, query, target in line:
            ...

with構文とは何なのか - 年中アイス python - "with"文のファイルI/O以外の使い方 - スタック・オーバーフロー

2016年03月02日

■_

司馬遼だってんで、「100分で名著」観たけどなにあれ……

■_

■_

アニメアイコンさんはTwitterを使っています: "mawkが速い速いと言われているけど、どれぐらい速いのよ?って事でnawkとgawk、あとBSDsedとGNUsedとtrとか適当に比較してみた。平均とったりしてないし目安程度だけど、うん、やっぱりmawk速いね。全てに於いて速い。 https://t.co/mu92qVdyvN" にあるデータを打ち込んでみた (時間データは real のみ)

操作mawknawkgawk
{print}11.5030.9122.69
{print $1}23.1852.1047.09
{i=$0}14.3335.7632.46
{i=$1}25.2259.9538.34
/1234567/{}13.1533.2227.93
/[0-9]\{7\}/{}33.6733.4728.39
{$1+$2}28.0148.6273.72
{$1*$2}28.3548.4674.10
{$1/$2}27.9848.4773.67
{$1%$2}28.8949.8376.91
{printf("%d %d\n",$2,$1)}56.36133.54188.09
{printf("%s %s\n",$2,$1)}32.92135.1082.68
{gsub(/[0-9]/,"@"); print}76.0099.14877.60
{gsub(/[0-9]/,"@")}68.5283.21889.82

もちろん表を作るのが目的ではなくて、これからチャート(グラフ)を作った。 今回は Google Spreadsheet を使ったんだけど そのまま publish してしまえば良かったんだろうか

これだとひとつ(ふたつか?)だけ数字のでかいのがいるので、それを抜いたものでも。

gawk の置換のデータがやたらと遅いのは locale 設定が影響してる気がするんだけどどうだろう

2016年03月01日

■_

まーったくやるきがごーざいませーん♪

■_

■_

12 Greatest Programmers of all Time (according to someone). Who do you think should be on that list? : programming 12 Greatest Programmers of all Time | Arkhitech あの人やあの人はー? と思うけどこういうのは意見が割れるよな。 ということであえて12人のメンツは書き出さない。


一つ前へ 2016年2月(下旬)
一つ後へ 2016年3月(中旬)

ホームへ


リンクはご自由にどうぞ

メールの宛先はこちらkbk AT kt DOT rim DOT or DOT jp