ときどきの雑記帖 新生編

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

一つ前へ 2011年5月(下旬)
一つ後へ 2011年6月(中旬)

ホームへ

2011年06月10日

■_

最近(でもないか)は、周辺の地名を足したような駅名ってよくありますよね。 溜池山王とか王子神谷とか浦和美園とか池尻大橋とか(最後のはかなり古い)。 どうにかならなかったんですかね。あれ。

この英単語、割と見かけるしなんども辞書ひいて調べたのに意味を覚えてない というのがいくつか。

OpenJDKを読んでいたり~

■_

わたなべさんが ■ gawk 4 public beta で書いているように、mingw でもビルドできないものがあるようです (というかビルドできるものもあるの方が近い?)。

>gmake mingw32
gmake  all \
       CC=gcc O=.o CF="-O2 -gdwarf-2 -g3" OBJ=popen.o \
       LNK=LMINGW32 PLNK=PLMINGW32 DLNK=DLMINGW32 \
       LF="-gdwarf-2 -g3" LF2=-lmsvcp60 RSP=
gmake[1]: Entering directory `C:/Users/xxx/yyy/zzz/gawk-3.1.84''
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  array.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  builtin.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  eval.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  field.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  floatcomp.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  gawkmisc.c
In file included from c:\strawberry\c\bin\../lib/gcc/i686-w64-mingw32/4.4.3/../../../../i686-w64-mingw32/include/windows.h:64,
                from pc/gawkmisc.pc:538,
                from gawkmisc.c:36:
c:\strawberry\c\bin\../lib/gcc/i686-w64-mingw32/4.4.3/../../../../i686-w64-mingw32/include/wingdi.h:2921: error: expected ';', ',' or ')' before '.' token
c:\strawberry\c\bin\../lib/gcc/i686-w64-mingw32/4.4.3/../../../../i686-w64-mingw32/include/wingdi.h:2923: error: expected declaration specifiers or '...' before 'MFENUMPROC'
c:\strawberry\c\bin\../lib/gcc/i686-w64-mingw32/4.4.3/../../../../i686-w64-mingw32/include/wingdi.h:2923: error: expected ';', ',' or ')' before '.' token
c:\strawberry\c\bin\../lib/gcc/i686-w64-mingw32/4.4.3/../../../../i686-w64-mingw32/include/wingdi.h:2933: error: expected ';', ',' or ')' before '.' token
c:\strawberry\c\bin\../lib/gcc/i686-w64-mingw32/4.4.3/../../../../i686-w64-mingw32/include/wingdi.h:3194: error: expected ';', ',' or ')' before '.' token
c:\strawberry\c\bin\../lib/gcc/i686-w64-mingw32/4.4.3/../../../../i686-w64-mingw32/include/wingdi.h:3195: error: expected ';', ',' or ')' before '.' token
gmake[1]: *** [gawkmisc.o] Error 1
gmake[1]: Leaving directory `C:/Users/xxx/yyy/zzz/gawk-3.1.84'
gmake: *** [mingw32] Error 2

>grep param win*.h
wingdi.h:  typedef int (CALLBACK *MFENUMPROC)(HDC hdc,HANDLETABLE *lpht,METARECORD *lpMR,int nObj,LPARAM param);
wingdi.h:  WINGDIAPI WINBOOL WINAPI EnumMetaFile(HDC hdc,HMETAFILE hmf,MFENUMPROC proc,LPARAM param);
wingdi.h:  WINGDIAPI WINBOOL WINAPI EnumEnhMetaFile(HDC hdc,HENHMETAFILE hmf,ENHMFENUMPROC proc,LPVOID param,CONST RECT *lpRect);
wingdi.h:  WINGDIAPI int WINAPI EnumICMProfilesA(HDC hdc,ICMENUMPROCA proc,LPARAM param);
wingdi.h:  WINGDIAPI int WINAPI EnumICMProfilesW(HDC hdc,ICMENUMPROCW proc,LPARAM param);
winuser.h:    UINT paramL;
winuser.h:    UINT paramH;

↑より古い(どのくらいかは調べるの忘れた) strawberryperl についてる mingw だと この param 問題に引っかからずにビルドできるようです。 見た感じ、引っかかる環境のほうが多い気もするのだけど MLにはビルドできたというのしか(数少ないけど)なかったような。

■_ 今日の Amazon.comからのオススメがすごい

すでに持っているのはともかくとして、どれも欲しいものを出してきてからに ○| ̄|_

■_

■_ C++

他の言語で同じことやるとどうなるんだろう? http://weegen.home.xs4all.nl/eelis/cppgrammar.png

2011年06月09日

■_

こちとら自腹じゃ
ユニコード戦記 ─文字符号の国際標準化バトル

ハードカバーとは思わなかった(見落としてた)。

■_ 4th ed.

Programming Perl 4th ed. の話。あまり伸びてませんが。

Programming Perl 4th Ed. due in 2011 : programming


I guess it's pretty clear Perl 6 didn't take up.


But the O'Reilly Perl 6 book is already out: http://i.imgur.com/PCMo1.gif


Perl 5 does everything I really need to do, I never saw the point in Perl 6.


The Perl6 runtime isn't quite ready, so it is hard for app devs to use.


this isn't true. the runtime is slow, but a lot of the core synposes are implemented. 
complete support for the synopses and improved performance is next. but, if you simply 
want to go read some of the tutorials and try out code, its there, go at it


there's already been one ORA p6 book, although its irrelevant now

there are p6 books on the way from onyx neon (run by the people who are writing p6), 
and ORA will surely be back in the game when the time is right

Perl 6 is a new, separate language to Perl 5. It is not intended to replace Perl 5, 
but rather to be capable in areas that Perl 5 is sub-optimal.

A new revision of Programming Perl is long overdue, new Perl 5 programmers need to be 
brought up to date with best practice (As do a few of the veterans).

It is a reference book. You probably want Learning Perl, if you want a Perl book you 
can read front to back. But if you want to read everything about, let's say Unicode, 
Programming Perl, is for you. I guess a lot of programming books aren't really used.

■_ 8080とかZ80とか

8080というプロセッサーが昔ありましてね。



Intel 8080

Intel 8080(インテル 8080、i8080)は、インテルによって開発された8ビットマイクロプロセ
ッサであり、1974年4月に発表された。同社の8008の後継に当たるが命令の互換性はない。8080
の命令は、後に拡張され、ザイログ社のZ80や日立製作所の64180に継承された。初期のパーソナ
ルコンピュータの多くに採用され、モトローラ社の6800やモステクノロジー社の6502(アップル、
コモドール、ファミコン、他)と覇を競った。

PCHL / JP (HL)
    HLの内容をPCに転送する。

XTHL / EX (SP),HL
    HLレジスタとスタックトップの内容を交換する。

この辺の命令に絡んだお話を。と思ったが面倒なのでまたの機会に。 読みたいという人はわっふる(ry

■_ Is C++ Just a Better C?

ここでウェストボール。

Is C++ Just a Better C?

Is C++ Just a Better C?
C++ は Better C にすぎないのだろうか?

A lot of money and energy was spent in converting or writing new software in C++
during the 80s and 90s. Even nowadays, when the leading commercial language is Java,
there is a lot of effort spent in learning and using C++ in several areas where
performance is considered to be an important asset.


80年代と90年代を通じて、C++ に書き換えたり C++ で新しいソフトウェアを書くために多くの
金銭やエネルギーがつぎ込まれました。現在でさえ、leading commercial language はJavaとな
っていて、C++ は学ぶのに多大な努力を要し、性能が重要な asset であるとみなされる領域に
おいて使われています。

However, despite all these efforts after 20 years, C++ is not used to its full extent.
Some features such as the STL have become really successful and widely accepted by the
industry. On the other hand, other features such as checked exceptions and RTTI have
been met with little enthusiasm.

しかし20年努力を積み重ねたあとでさえも、C++ はその full extent を使われてはいません。
STL のような一部の機能は本当に成功して産業的にも広く受け入れられました。その一方で例
外であるとか RTTI のようなそのほかの機能は little enthusiasm (わずかの熱狂?) と遭遇
しました。
#have been met with little enthusiasm がわかんねえ


It is necessary to understand what these features have in common and why they were not
considered to be so useful as their creators supposed them to be. Especially when such
features have been introduced more than a decade ago and are still nowhere near full
acceptance.


these features have in common と、なぜそれらが creator たちが想像していたほどには有用で
あると受け止められなかったのかを理解する必要があります。特に一昔前ににそういった機能が
導入されたときと、そしてそれが未だに完全に受け入れられた場所がないことに。
#ぐちゃぐちゃだ


Duplicate Features
重複した機能

One of the problems of the C++ language is that it has, more than once, introduced
features that are difficult to use and/or implement. As a general rule, this is a
disadvantage of languages designed by a committee. Some features end up becoming part
of the standard document, but they have little support in the real world.

C++ という言語が抱えている問題の一つは実装や使用が難しいような機能の導入が一度ならず行
われたということです。一般的に言って、これは委員会によって設計された言語の disadvantage
です。一部の機能は結局標準ドキュメントの一部にはなっても現実世界においてはわずかのサポ
ートしかなかったりするのです。


For example, a decade ago the designers of C++ though about the possibility of having
templates defined in separate translation units from the ones where the templates are
used. The intention is good, since templates take a long time to parse and compile.

たとえば一昔 (a decade ago) に、C++ の設計者たちは使う翻訳単位とは別の翻訳単位で
テンプレートを定義できるようにすることについて考えました。
テンプレートは解析とコンパイルに時間がかかるものでしたから、
その意図は良いものです。


However, the big problem with separate compilation of templates, provided by the
external template keyword, is that it was never implemented by major compilers. The
main justification is that it is a complicated feature to implement. Also, it would
require modifications to the current way programmers declare and templates.

しかし、 external template keyword を使ったテンプレートによる分割コンパイルに伴う大き
な問題はメジャーなコンパイラーがどれ一つとしてそのテンプレートの分割コンパイルを実装し
なかったということです。それに対する主たる justification (正当事由) は、テンプレートの
分割コンパイルが実装するには複雑すぎる機能であったということです。また、the current 
way programmers declare and templates に対して修正が必須でした。その結果は、 external 
templates が dead feature として見られていることでありまた、(external templates は) 
有用かもしれないけれどもどの major なコンパイラーでも使えないようななにかであるという
ことです。


Coding Standards
コーディング標準

A related problem for C++ is that nobody uses all its features. Due to the fact that
there are competing implementation for the same concept (for example, two IO libraries
― the old C-base library and a stream object-based library), C++ users have to decide
which option to use. This may be done in a case-by-case basis, or even by the use of a
coding style.

related problem for C++ はそのすべての機能を使う人が皆無だということです。(たとえば古
いCベースのライブラリとストリームオブジェクトベースのライブラリの二つのIOライブラリの
ような)同一のコンセプトに対する competing implementaion があるために、C++ ユーザーは選
択肢のどちらを使うのかを決めなければなりません。この選択は case-by-case で為されますが、
コーディングスタイルの使用によってさえ為されることがあります。


Big companies such as Google have decide to rule out most of the advanced features
found in newer versions of C++. These features include exceptions, multiple
inheritance, for example. What this means in practice is that C++ is being used just
as a better C, without many of the features that its creators though would be useful.

Google のような大企業は、新しいバージョンの C++ にあるような先進機能のほとんどをrule 
out (排除、除外) すると決定しました。そういった機能には例外や多重継承があります。in 
practice でこれが意味するところはC++ は creators が便利であろうと考えた機能の多くを使
っていない、単なる better C として使われているということです


On close inspection, it seams that C++ is mostly a language designed at two levels:
the first level, incorporating the ideas of the day, which change every few years with
the desires of researchers. Examples include checked exceptions and run time type
information. In the process, lots of incompatible ways of writing the same code are
introduced. For example, are you going to use return values or exceptions? Streams or
standard buffered I/O? Both have its advantages and disadvantages, so you better know
what they are.


close inspection では、C++ は二つのレベルで設計されたように思われます: 第一のレベルは
研究者たちの要望による数年ごとに行われる変更である the ideas of the day の取り込みです。
checked exception や実行時型情報といったものがそれに含まれます。設計の過程では数多くの
非互換な同じコードを書くための方法が導入されました。たとえば、(エラーの処理をするのに)
戻り値と例外のどちらを使うのか?あるいは、ストリームと standard bufferd I/O のどちらを
使うのかといったものです。どちらにも利点と欠点がありますから
so you better know what they are.



In the other hand, there is also a second level dictated by developers, as they decide
which subset of the language to use. Since it is not possible to use all the provided
features at the same time, one has to selectively use C++ to create new software
projects. One of the ways this is done is by adopting a styling convention. In this
process, developers rule out a set of features that believe are not productive.

一方で developers が使用する言語のサブセットを決めている、developers によって dictate 
されている第二のレベルもあります。与えられた機能のすべてを同時に使うことはできないので、
新しいソフトウェアプロジェクトを作るためには C++ を selectively に使わなければなりませ
ん。一つのやり方は styling convention を適用することで行うものです。このプロセスでは 
developers は productive でないと確信している機能のセットを除外します。


Still, another result of this evolutionary process is that there are some features
that people don't like, but that are not easy to substitute. For example, templates
are a pain to create and even to use. However most developers use them because it is
the only way to do some things in C++. Somebody else could create better container
classes, but that would become a huge problem for compatibility with existing
libraries.

もう一つの result of this evolutionary process はユーザーが好まないような一部の機能が
あるけれども、それは容易に置き換えられるものではないというものです。たとえば、テンプレ
ートは作成するのも、使うのすらも苦痛なものです。それでも大部分のdeveloeper はテンプレ
ートを使いますが、なぜならそれは一部のことについては C++ で行うための唯一の方法だから
です。ほかの誰かがより良いコンテナークラスを作れたかもしれませんが、それは既存のライ
ブラリとの互換性にとって巨大な問題となっていたでしょう。

Conclusion
結論

C++ is an evolving language. As a consequence many of its features are not welldeveloped. 
Other features have been rejected by the community as too complex or unsafe to use.

C++ は進化の途上にある言語です。
many of its features are not welldeveloped の結果として。
他の機能は複雑すぎたり安全でないために委員会から拒絶されました。


A large part of being a good C++ developer is understanding what are the good and bad
parts of the language, and how to take advantage of them when necessary.

good C++ developer になることの large part は C++ という言語の good parts と bad parts
を理解することと、必要なときにそれらの advantage をどのように take するかを理解するこ
とです。


Further Reading
併せて読みたい

The Design and Evolution of C++, by Bjarne Stroustrup is a great book that explain the
reasoning for most of the features in C++. It is a must read if you want to understand
the initial phase of evolution of the language.


Published on April 23rd, 2011

Copyright c Carlos Oliveira ・ All rights reserved.

■_

■_ 変換ルーチン

UTF-16(or UTF-32) と UTF-8 との相互変換関数を3回くらい書いてるんだけど、 なんかこう、決定版てな感じの書けないものかなあなどと考えたり。 UTF-8 の冗長表現を蹴るとか無効なシーケンスをチェックするとか考えると ちと面倒。

ある程度のパターン(とルール)を記述して自動生成できたりしないかねえ。

2011年06月08日

■_

あまぞんさんで、お届け先を近くのコンビニにしようと思って操作しても その場所にはお届けできませんとかいって蹴られる。 ヘルプにある届け先に指定できない条件には引っかかってないと思うんだけどなあ。 高額なものではないし、とりたてて大きなものでも重いものでもないし、 別の会社の取り扱っているものでもない。 なんでじゃ。

■_ 100号あたりで断念したような記憶が

~みなもと太郎「風雲児たち」茶屋 其の参拾参~ 

88 おじん ◆abcDBRIxrA [sage] 2011/06/07(火) 10:00:03.97 ID:xvNYmUA/0 Be:
    (/-\) 週刊スタートレック全314巻を買ったオレ様が通りますよっと。 

あれはそんなに行ったんだ。 段々扱う本屋が少なくなったりなんだりで途中で放り投げたなあw

■_ 今日の丸投げ

探してみると、Yahoo!知恵袋にも投げてた模様。

【入門】Common Lisp その7【質問よろず】

918 デフォルトの名無しさん [sage] 2011/06/07(火) 19:19:25.21 ID: Be:
    現在英語で書かれた教科書でschemeを学んでいます.

    そこで練習問題として
    Write predicates free? (respectively, bound?) that detemines if an expression contains a free (respectively, bound) instance of a particular variable.

    という問題がありました.

    特定の変数の独立したインスタンスを含むかどうか判別する述語free?を作れという文章だと思うのですが,どうでしょうか?
    また,その場合free?をどう作れば良いのかわかりません.
    どなたか方針だけでも
    お願いします. 

919 デフォルトの名無しさん [sage] 2011/06/07(火) 19:50:15.65 ID: Be:
    schemeはスレ違い

    Lisp Scheme Part32
    http://hibari.2ch.net/test/read.cgi/tech/1303299696/ 

920 918 [sage] 2011/06/07(火) 20:23:04.06 ID: Be:
    >>919
    そのようなスレがあったんですね
    誘導ありがとうございます 

Lisp Scheme Part32 

254 デフォルトの名無しさん [sage] 2011/06/07(火) 20:16:45.04 ID: Be:
    現在英語で書かれた教科書でschemeを学んでいます.

    そこで練習問題として
    Write predicates free? (respectively, bound?) that detemines if an expression contains a free (respectively, bound) instance of a particular variable.

    という問題がありました.

    特定の変数の独立したインスタンスを含むかどうか判別する述語free?を作れという文章だと思うのですが,どうでしょうか?
    また,その場合free?をどう作れば良いのかわかりません.
    どなたか方針だけでも
    お願いします. 

255 デフォルトの名無しさん [sage] 2011/06/07(火) 20:31:02.75 ID: Be:
    >>254
    線形代数のガウスの消去法をやったときに出てくる自由変数についての問題のようにも見えるが 

256 デフォルトの名無しさん [sage] 2011/06/07(火) 20:57:34.05 ID: Be:
    >>254
    式をどんどん分解して深くいく分割統治的再帰
    関数の返り値は自由変数のリスト
    分割統治の合併はappendで
    累積変数でbounded variableのリスト
    変数を見たら↑に含まれているかどうかチェック
    自由変数なら返り値で返す




257 デフォルトの名無しさん [sage] 2011/06/07(火) 22:22:48.84 ID: Be:
    >>256
    すみません。
    もう少し詳しくお願いします・・・
    理解力がなくて申し訳ありません 

258 デフォルトの名無しさん [sage] 2011/06/08(水) 00:18:15.92 ID: Be:
    http://oshiete.goo.ne.jp/qa/6793270.html 

259 デフォルトの名無しさん [sage] 2011/06/08(水) 00:28:09.86 ID: Be:
    (define (f x) (+ x y))みたいなのがあったときに
    (free? '(define (f x) (+ x y)) 'x)とやるとfalseで
    (free? '(define (f x) (+ x y)) 'y)とやるとtrueな感じ?
    変数を束縛する可能性のある構文
    関数引数(define (f x)...)やλ式(lambda (y) ...)やlet(let ((z 1)...)みたいなのに出会うごとに
    束縛されてる式をappendしてく
    ((x v1) (y v2) (z 1)))みたいなリストができるので
    最後に、それに'xが含まれていないかどうかを調べる 

260 デフォルトの名無しさん [sage] 2011/06/08(水) 00:30:27.20 ID: Be:
    なんてことだ
    書き込む前にリロードすればよかった 


プログラミング言語のschemeについて | OKWave

現在英語で書かれた教科書でschemeを学んでいます.

そこで練習問題として
Write predicates free? (respectively, bound?) that determines if an expression contains a free (respectively, bound) instance of a particular variable.

という問題がありました.

特定の変数の独立したインスタンスを含むかどうか判別する述語free?を作れという文章だと思うのですが,どうでしょうか?
また,その場合free?をどう作れば良いのかわかりません.
どなたか方針だけでもお願いします.

投稿日時 - 2011-06-07 20:17:40
ANo.1


これはあんま良い質問の仕方じゃないですね。

>現在英語で書かれた教科書でschemeを学んでいます.

教科書名を挙げるべきでしょう。同じ本所有している人もいるでしょうし。
ググってみたらこれですね。

Essentials of Programming Languages:
http://www.eopl3.com/

んで、問題の解釈はそれで良いのかな?っつーか、恐らくScheme固有の意味で「自由変数」がど
ーの、っつーよりラムダ算法の話なんじゃないか、と思います。その辺も詳細が教科書が無いん
で分かりませんね。

多分Schemeのやり方(と言うかLisp一般でのやり方)だと、この問題の前の解を利用して問題を解
け、とかそう言う流れになってんじゃないかな?だから恐らくこの問題単一でどう答えを作るか、
って話にはならないでしょう。

でググッてみると、案の定メーリングリストに投稿されたりしています。それを参考にして解い
てみたら良いのではないでしょうか(そして予想通り、問題自体が連鎖してる = 解が連鎖してる)。

more trivial CS homework:
http://lists.canonical.org/pipermail/kragen-tol/1999-August/000451.html

投稿日時 - 2011-06-07 21:38:06

質問文はこぴぺで貼り付けてるのかねえ。

■_

■_

今日も#3が終わらなかったよーん

2011年06月07日

■_

今日(火曜日)の夕方あたりに、「ユニコード戦記」が(先行販売でなく)入荷というのを ついったでみかけたのだけど、やっぱ予定は10日だよなあ。 まあ先行販売でなくても早めに売ってるところではあるんだけど。

■_ Dr. Alan Kay on the Meaning of "Object-Oriented Programming

誰か訳(ry "Dr. Alan Kay on the Meaning of "Object-Oriented Programming" : javascript"

Dr. Alan Kay on the Meaning of "Object-Oriented Programming" : javascript

Hi Stefan --

Sorry for the delay but I was on vacation.

At 6:27 PM +0200 7/17/03, Stefan Ram wrote:
>   Dear Dr. Kay,
>
>   I would like to have some authoritative word on the term
>   "object-oriented programming" for my tutorial page on the
>   subject. The only two sources I consider to be "authoritative"
>   are the International Standards Organization, which defines
>   "object-oriented" in "ISO/IEC 2382-15", and you, because,
>   as they say, you have coined that term.

I'm pretty sure I did.

>
>   Unfortunately, it is difficult to find a web page or source
>   with your definition or description of that term. There are
>   several reports about what you might have said in this regard
>   (like "inheritance, polymorphism and encapsulation"), but
>   these are not first-hand sources. I am also aware that later
>   you put more emphasis on "messaging" - but I still would like
>   to know about "object oriented".
>
>   For the records, my tutorial page, and further distribution
>   and publication could you please explain:
>
>     When and where was the term "object-oriented" used first?

At Utah sometime after Nov 66 when, influenced by Sketchpad, Simula, 
the design for the ARPAnet, the Burroughs B5000, and my background in 
Biology and Mathematics, I thought of an architecture for 
programming. It was probably in 1967 when someone asked me what I was 
doing, and I said: "It's object-oriented programming".

The original conception of it had the following parts.

(略)

■_ 4th Ed.

この辺経由で "Programming Perl, 4th Edition in time for holiday gifting | brian d foy [blogs.perl.org]"

Programming Perl, Fourth Edition - O'Reilly Media
Programming Perl, Fourth Edition
Unmatched power for text processing and scripting

By
    Tom Christiansen, Larry Wall, Jon Orwant
Publisher:
    O'Reilly Media
Released:
    October 2011 (est.) 
Pages:
    1000 (est.) 

でるのか。しかし 1000ページ! 3rd Ed.で何ページだっけ。と。あ、減ってるんだ → "Pages: 1104 "

どちらにしてもProgramming Python には負けるか。

Programming Perl, Fourth Edition - O'Reilly Media

Full Description

When it comes to learning Perl, programmers consider this book to be the undisputed 
bible. You not only learn every nuance of this language, you also get a unique 
perspective on the evolution of Perl and its future direction. The 4th edition has 
been thoroughly updated for version 5.14, with details on regular expressions, support 
for UNICODE, threads, and many other features.

Many Perl books explain typeglobs, pseudohashes, and closures, but only this one shows 
the motivations behind these features and why they work the way they do. It's exactly 
what you'd expect from its prominent authors: Larry Wall is the inventor of Perl, and 
Tom Christiansen was one of the first champions of the language.

In print since 1991, the book affectionately known as "the Camel" has played 
a central role in computing among programmers and system administrators around the 
world. With Programming Perl, you too will learn the most efficient ways to use this 
language.

5.14ベースか。まあ今年だそうって本ならそうなりますわね。

数多のPerl本が型グロブや疑似ハッシュ、クロージャの解説をしているけれども、 この本は “ motivations behind these features and why they work the way they do” を説明しますよ。と。

■_

■_

#3 があともう少し。

2011年06月06日

■_

つかですね、出勤時刻を一時間前倒し → 起床時刻を(ry → となると正直きついんですがw

■_

このネタ先送り~

■_ 今日の重箱の隅

原文を混ぜながら。 原文へのリンクは InfoQ: Reactions to the VB 6 Open Source Rumor

InfoQ: VB6オープンソースの噂に対するリアクション
TechEdの間、多くの人がVisual Basicがオープンソースになるというデマを信じ込んでいた。そ
れが嘘だと判明したが、言語に関すること、それがレガシーであること、そしてオープンソース
の実装に関する様々な議論を生み出した。

A prank during TechEd caused many to believe that Visual Basic 6 would be open sourced. 
While it turned out to be false, it did start a lot of conversations about the 
language, its legacy, and an open source implementation would mean.

原文では「6」って書かれているのに、訳で抜けてるのはまずいんじゃないですかね。 このバージョン番号に大きな意味があると思うのだけど。 そして、its legacy を「それがレガシーであること」ってのもちと。 んで、 and an open source implementation would mean も含めてこの文が VB6 のことを指しているのが訳文ではぼけてしまっている気がします。

Visual Basicは、3バージョンごとに大きな変更があった。最初の大きな変更は、バージョン4
の16ビットから32ビットへの移行であった。「純粋な」なアプリケーションには大きな影響は
なかったが、多くのVisual Basicプログラマーは、サードパーティーのライブラリやコンポーネ
ントに頼っていた。16ビットのDLLとVBXコンポーネントが対応していない場合、32ビットのDLL
とOCXコンポーネントに大幅に書き換えることが必要であった。

Visual Basic undergoes significant breaking changes in every third version. The first 
major change was the transition from 16-bit to 32-bit programming in Version 4. While 
not much of a problem for “pure” applications, most Visual Basic programmers heavily 
relied on third party libraries and components. In cases where the 16-bit DLLs and VBX 
components didn't have corresponding 32-bit DLLs and OCX components a major rewrite 
could be required.

  

undergoes significant breaking changesmajor change を「大きな変更」と同じにしちゃうのは…

最後の「16ビットの~」は、 VB デベロッパーが作っていたプログラムで使用していた 16bit DLL や VBX に対応した 32bit DLL や ODXがない場合には、VBのプログラム大幅に書き換える必要が あったかもしれない。ってことですよね。その辺のニュアンスが抜けてるし 32bit DLLやOCXをVBデベロッパーが書かなければいけなかったように読めちゃうんですが。

次の大きな変更は、VB.NETとして知られるVisual Basic 7である。この変更は、ネイティブに
コンパイルされたコードとランタイムライブラリを.NETのILとCommon Language Runtimeに置き
換えることであった。この過程において、いくつかの主要な機能は変更された。もっとも特筆す
るべきものは、リソースモデルである。Visual Basic 4から6では、変数にnullをセットして、
リソースを解放する必要のあった、COMの参照カウントデザインであった。これを.NETの非決定
性ガベージコレクションに置き換える作業は、特にファイルハンドルなどの制限のあるリソース
については、簡単ではなかった。

The next major shift occurred in Visual Basic 7, also known as VB.NET. This replaced 
the natively compiled code and runtime libraries with .NET's IL code and Common 
Language Runtime. In the process some core functionality was broken, the most notably 
being the resource model. Visual Basic 4 thru 6 used COM's reference counting design, 
which requires setting a variable to null to free resources. Translating this to .NET’
s non-deterministic garbage collection is not an easy task, especially with working 
with limited resources such as file handles.

  

変更は~Visual Basic 7である。って言い回しにひっかかるものがあります。 VB7 であった。行われた。じゃないでしょうか。 それと、ここでは原文の shift が 変更 になってますね。 これもどうかと。

特筆すべきは~ の辺りも Visual Basic の4から6までは、 リソースを解放するのには変数にnullを代入する必要がある COMの参照カウント方式を使っていたがしかし、といった方が良さそうな気がします。 その前の文、後の文とのつながりが良くないというかリズムが悪いというか。

この影響は、未だに企業や開発者に及んでいる。90年代においては、Visual Basicは、ビジネス
アプリケーションの内部で使われている最もポピュラーな言語であった。それらのアプリケーシ
ョンをスクラッチから書き直す場面に直面した時、多くの開発者はVBを完全にあきらめて、
JavaかC#に切り替えた。

The ramifications of this are still plaguing companies and developers. In the 90's 
Visual Basic was by far the most popular language for writing internally used business 
applications. Faced with the prospect of more or less rewriting their applications 
from scratch, many developers gave up entirely on VB and switched to Java or C#.

割とよく見かける気もするのですが、“from scratch”を「スクラッチから」としちゃうのは かなーりまずい気がします。 ニュアンスで通じちゃうでしょうけど(プラモデルとかで「フルスクラッチ」とかいうし)、 ゼロから~とか一から~で良いと思います。

for writing internally used business applications ビジネスアプリケーションの内部で使われている となるのも変ですね。原文の writing が消えてるし。 企業内部で使われるようなビジネスアプリケーションを書くのにVBは使われました ということだと思うんですが。

さくっと飛ばして


Visual Basic 6は、現在どこにいるのか。

Visual Basic 6は、一般に公表されている情報や、2010年3月のサービス速報によると、64ビッ
トバージョンで使用することが*できない*。Microsoft Office製品には、64ビットバージョンの
Visual Basic for Applicationsが組み込まれているため、不可能ということではない。これは
単に、Microsoftがそこにリソースを裂くことがないことを意味している。

さらに悲惨なのは、MicrosoftがWindows Server 2008/Windows 7以降、VB 6ランタイムの出荷を
停止する予定があることである。もともとはVisual Basic 6のランタイムはインストーラーに含
めることが必要であったが、ここ10年の間、実質的にDLLはWindowsとともに出荷されていたこ
とになる。現在使っているインストーラーパッケージを書き直して、昔のモデルに戻る必要が
ある。

Where Visual Basic 6 Currently Stands

Visual Basic 6 still doesn’t have a 64-bit version available to the general public 
and, according to the March 2010 service bulletin, it never will. That isn’t to say 
it is impossible, there is a 64-bit version of Visual Basic for Applications included 
in the Microsoft Office product line; it merely means Microsoft has no intention of 
dedicating resources to it.

More distressing to some is Microsoft's intention to stop shipping the VB 6 runtime 
after Windows Server 2008/Windows 7. While Visual Basic 6 originally required the 
installer to include the runtime, these essential DLLs have been shipped with ever 
version of Windows for the last decade. Going back to the old model will require 
rewriting the installer packages currently in use.

リソースを割く。ですよね。

最後のパラグラフも訳文だけ見ても意味が良く取れません(と思うんだけどなあ)。 これは、 最近のWindowsではVB6のラインタイムをシステムから外しちゃってるのは問題になるだろう。 なぜなら、元々インストーラー自体がVB6ランタイムを持っていなければならないのに これまでのWindowsではインストールされているもの (shipped with)だったので 持たなくても大丈夫だった(自分がランタイムをインストールしなくても良い)。 しかし、これからはそうではないので、 新しいWindowsにインストールできるようにするにはランタイムを含めた形で 作り直さないといけないよ。ということですよね。

■_ 10×3

Perl と Pyhon と Clojure。

10 Perl One Liners to Impress(?) Your Friends

1. Multiply each item in a list by 2

perl -E 'say for map { $_ * 2 } 1..10'

2. Sum a list of numbers

use List::Util qw(sum);
say sum 1..1000;

say reduce { $a + $b } 1..1000;

3. Check if word exists in a string

my @wordlist = ("scala", "akka", "play framework", "sbt", "typesafe");
my $tweet = "This is an example tweet talking about scala and sbt.";
say for grep { $tweet =~ /\b$_\b/ } @wordlist;


You can also use split:

my @tweet_words = split /\W/, $tweet;
say for grep { $_ ~~ @tweet_words } @wordlist;


4. Read in a file

use File::Slurp qw(slurp);
my $file = slurp("filename");  # read_file also works

Before File::Slurp people came up with all kinds of abominations to do this:

my $file = do { local(@ARGV,$/)="filename";<>};

5. Happy birthday to you

say for map { "Happy Birthday to " . ($_ == 2 ? "dear Name" : "you") } 0..3;

6. Filter list of numbers

use List::MoreUtils qw(part);
my ($failed, $passed) = part { $_ > 60 } (49, 58, 76, 82, 88, 90);

It’s more common to grep for one case at a time.

my @passed = grep { $_ > 60 } (...);

7. Fetch and parse an XML service

use LWP::Simple qw(get);
use XML::Simple;

my $data = XMLin(get("http://search.twitter.com/search.atom?&q=xml+sucks"));

8. Minimum and maximum of a list

use List::MoreUtils qw(minmax);
my ($min, $max) = minmax @LIST;

9. Parallel processing

use Parallel::Iterator qw(iterate_as_array);

my @result = iterate_as_array( sub { processItem($_[1]) }, \@dataList );


10. Sieve of Eratosthenes

sub sieve3 {
    grep{@_[map$a*$_,2..@_/($a=$_)]=0if$_[$_]>1}@_=0..pop
}
print join "  ", sieve(100);


perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/' [number]


Richard Harris 2011 ©

10 Python one liners to impress your friends « /code/blog

10 Python one liners to impress your friends

1. Multiple Each Item in a List by 2

print map(lambda x: x * 2, range(1,11))

2. Sum a List of Numbers

print sum(range(1,1001))

3. Verify if Exists in a String

wordlist = ["scala", "akka", "play framework", "sbt", "typesafe"]
tweet = "This is an example tweet talking about scala and sbt."

print map(lambda x: x in tweet.split(),wordlist)

4. Read in a File

print open("ten_one_liners.py").readlines()

5. Happy Birthday to You!

print map(lambda x: "Happy Birthday to " + ("you" if x != 2 else "dear Name"),range(4))

6. Filter list of numbers

print reduce(lambda(a,b),c: (a+[c],b) if c > 60 else (a,b + [c]), [49, 58, 76, 82, 88, 90],([],[]))

7. Fetch and Parse an XML web service

from xml.dom.minidom import parse, parseString
import urllib2
# note - i convert it back into xml to pretty print it
print parse(urllib2.urlopen("http://search.twitter.com/search.atom?&q=python")).toprettyxml(encoding="utf-8")

8. Find minimum (or maximum) in a List

print min([14, 35, -7, 46, 98])
print max([14, 35, -7, 46, 98])

9. Parallel Processing

import multiprocessing
import math

print list(multiprocessing.Pool(processes=4).map(math.exp,range(1,11)))

10. Sieve of Eratosthenes

There is no Sieve of Eratosthenes operator, but that is hardly a constraint.

n = 50 # We want to find prime numbers between 2 and 50

print sorted(set(range(2,n+1)).difference(set((p * f) for p in range(2,int(n**0.5) + 2) for f in range(2,(n/p)+1))))


© 2011. /code/blog. Powered by WordPress. Theme design by WPShoppe.

10 Clojure One Liners to Impress Your Friends « The Free Geek

10 Clojure One Liners to Impress Your Friends

1. Multiple Each Item in a List by 2

(map #(* % 2) (range 1 11))

2. Sum a List of Numbers

(reduce + (range 1 1001))

3. Verify if Word Exists in a String

I used a regex here, because I believe that’s the right way to do it.

(def tweet "This is an example tweet talking about clojure and emacs.")
(def regex (re-pattern (apply str (interpose "|" ["clojure" "logic" "compojure" "emacs" "macros"]))))
(re-seq regex tweet) ; Gives me the actual matches instead of just true/false


4. Read a File

(def file-text (slurp "data.txt")) ; Reads the whole file
(def file-lines (clojure.contrib.io/read-lines "data.txt")) ; Reads as a sequence of lines

5. Happy Birthday to You

(doseq [l (map #(str "Happy Birthday " (if (= % 2) "dear Rich" "to You")) (range 4))] (println l))

Alternate version -

(dotimes [n 4] (println "Happy Birthday " (if (= n 2) "dear Rich" "to You")))

6. Filter List of Numbers

(partition-by #(> % 60) [49 58 76 82 88 90])

7. Fetch and Parse XML Web Service

(clojure.xml/parse "http://search.twitter.com/search.atom?&q=clojure")

8. Find Maximum (or Minimum) in a List

(reduce max [14 35 -7 46 98])
(reduce min [14 35 -7 46 98])
;; Now both together
((juxt #(reduce max %) #(reduce min %)) [14 35 -7 46 98]) ; Returns [98 -7]

9. Parallel Processing

;; Assuming process-line to be a CPU intensive function that operates on a line
(pmap process-line lines) ; Note the "p" in front of map

10. Sieve of Eratosthenes

I don’t I have a sufficiently good (in terms of performance & beauty) one line 
implementation of SoE. I would recommend checking out Christophe Grand’s treatise on 
the subject titled Everybody loves the Sieve of Eratosthenes for a great discussion on 
writing real world prime sieves in Clojure.

11. Solve FizzBuzz

(map #(cond (zero? (mod % 15)) "FizzBuzz" (zero? (mod % 3)) "Fizz" (zero? (mod % 5)) "Buzz" :else %) (range 1 101))

© 2011. The Free Geek. Powered by WordPress. Theme design by WPShoppe.

10 * one liners to impress your friends - Google 検索

■_

■_

だうん

2011年06月05日

■_

えーと、今月発売予定の本はなにがあったんだっけ。 みずしまさんたちのScala本と、ユニコード戦記と、 6月発売のオライリー本にも何かあったような。

O'Reilly Japan - Books :: New and Upcoming
近刊書籍

近刊書籍の情報は、諸般の事情により変更される可能性があります。あらかじめご了解ください。
Title	ISBN	定価	発売日
Being Geek 	978-4-87311-499-6 	\2,415 	2011年06月
Made by Hand 	978-4-87311-500-9 	\2,310 	2011年06月
Linuxカーネル Hacks 	978-4-87311-501-6 	\3,570 	2011年07月

あ、これだ>「Being Geek」

二分冊になってしまった すぽすっぽセンセイの御著書の翻訳版はどうしますかね。っと。

■_ call by reference と聞いて

リリカル☆Lisp開発日記 » Blog Archive » C++の参照を使ってもcall by referenceにはならない

* はじめに *
ここ最近(昔から?)、C言語の本や記事などに
「ポインタを使うことで参照呼び(call by reference)が…」
なんて書いてあると、
「C言語には値呼び(call by value)しかないくぁwせdrftgyふじこlp…」
などというツッコミで荒れるみたいでが、
C++の本や記事に「参照呼び」と書いてあることで荒れるところを
(少なくても私は)見たことがないのが不思議なので、このエントリを書きます。
(以下略)

一部で反応するのを期待されたようですが、途中まで書いて面倒くさくなったので放棄しましたw

■_ awk

なぜか(?) Linux 板の awk スレが最近それなりに書き込みの波が来るように。

awk ファンクラブ 
91 login:Penguin [sage] 2011/06/02(木) 22:37:43.51 ID:jvZfUiPL Be:
    不要な部分を全部削って87の方が2バイト短いか。
    mawkだとsrand()を省けるから、もっと短い。エレガント!

    それにしても、4ヶ月ぶりに上がったんだ。ほんと人居ない。 

92 login:Penguin [sage] 2011/06/02(木) 22:45:23.28 ID:twwaY/QA Be:
    ワタスは監視してますよ。 

93 login:Penguin [sage] 2011/06/03(金) 00:28:36.43 ID:lUf7A9Qj Be:
    俺も。 

94 login:Penguin [sage] 2011/06/03(金) 00:49:49.88 ID:cydHNqeK Be:
    じゃあ、暫く書く 

95 login:Penguin [sage] 2011/06/03(金) 01:07:11.81 ID:cydHNqeK Be:
    空行を削除する
    awk 1 RS=

    sedだと、
    sed /^$/d
    かな?同じ9文字か。 

99 login:Penguin [sage] 2011/06/03(金) 22:11:19.49 ID:cydHNqeK Be:
    なんか利点が無いように見えるので、sedじゃなくawkを使う理由を探してみた。

    tar xf linux-2.6.39.1.tar.bz2 --wildcards '*.c' -O >src.txt
    time cat src.txt |awk 1 RS= >/dev/null
    real 0m3.172s
    user 0m2.786s
    sys 0m0.757s

    time cat src.txt |sed /^$/d >/dev/null
    real 0m32.503s
    user 0m31.465s
    sys 0m0.882s

    ※参考
    time cat src.txt |cat >/dev/null
    real 0m0.606s
    user 0m0.036s
    sys 0m0.586s

    おー。sedより、ずっとはやーい
    やったね、awk! 

100 login:Penguin [sage] 2011/06/03(金) 22:26:22.52 ID:lSuFEE/Z Be:
    うむ。grep よりも awk の方が速かった記憶がある。 

101 login:Penguin [sage] 2011/06/04(土) 12:42:54.20 ID:HzZByxDX Be:
    複数のtimeコマンドの出力から平均を求める
    awk -Fm '{ a[$1]+=$2; a[0,$1]++ }; END{ for(i in a) if(i~/^[rus]/) printf "%sm%.3fs\n",i,a[i]/a[0,i] }'

    昨日の時間計測のために書いた。
    いろいろ問題あり。これ以上短くかけなかった、残念だわ。

    sedがすっごい遅いので全部メモリに読み込んで処理させてみた。
    time cat src.txt |sed -n '1x;1!H;${x;s/\n\n\+/\n/gp}' >/dev/null
    real 0m24.515s
    user 0m18.584s
    sys 0m2.005s
    # ちなみに、昨日のも含めて3回試した結果を平均した

    …やっぱ遅い。GNU sedが悪いの?スレ的に満足な結果だけど。
    便利で速くてシンプルなのに、あまり使われない紹介されない、消え行くawk、カワイソス 

102 login:Penguin [sage] 2011/06/04(土) 13:21:18.28 ID:El9DLlK0 Be:
    フィールドを抜き出すワンライナーはやっぱawkでしょ
    perl -pae'$_=$F[8].$/'
    ruby -nae'puts$F[8]'
    awk 'print$9' 

103 login:Penguin [sage] 2011/06/05(日) 00:51:57.16 ID:kp3qNbsC Be:
    >>95の表記初めて見た
    このスレの住民にはこれくらい当たり前なのか… 

104 login:Penguin [sage] 2011/06/05(日) 05:45:10.75 ID:jNueNt7Q Be:
    それってどういう構造なんだ?
    1番目の引数である「1」は「パターンは常に成り立つ、アクションは指定しない(=レコードを加工せずに出力)」というawkコードだろうけど
    その次の引数って入力ファイルになるはずじゃ? 

105 login:Penguin [sage] 2011/06/05(日) 07:57:57.27 ID:k4Gl3aKk Be:
    わかんねー。なんでこれをコマンドプロンプトに打ち込んで、うまくいくのか。
    gawk 1 RS= testfile.txt 

106 login:Penguin [sage] 2011/06/05(日) 08:10:41.12 ID:SucWQMoo Be:
    RSが空だとRS=\n+として解釈されるんじゃまいか 

107 login:Penguin [sage] 2011/06/05(日) 08:50:42.42 ID:jNueNt7Q Be:
    だとしても、何故にRS=\n+がコードとして実行されるの?
    コードは1で終わってね? 

108 login:Penguin [sage] 2011/06/05(日) 09:34:08.07 ID:jNueNt7Q Be:
    自己解決、assignment optionsなんて仕様があったのか 

109 login:Penguin [sage] 2011/06/05(日) 09:55:54.81 ID:Tq0aYVo2 Be:
    おー、いっぱい居るね!まだまだやれるぞ、awk!

    一応説明すると、プログラム自体は>>104の解釈の通りです。

    また、RS=""なら、RS="\n\n+"とほぼ同じです。
    違いは、RS=""はファイルの先頭に改行が続くとき、それを無視します。

    ついでに、POSIXではRSに2文字以上設定すると、結果は不定とされています。
    gawkでは、正規表現を使える拡張がされていますけど。

    引数ですが、ここに代入文を書くとBEGINの後に処理されます。
    まあ、ああ書いたのは-vオプションを使うと3文字コマンドが増えるからなんですが、
    こういう変数の設定方法もあるということで。 

110 login:Penguin [] 2011/06/05(日) 10:44:14.22 ID:3GXVErWF Be:
    awk /./

    の7文字だけでOK
    RSは初期値が入ってるんだから

111 login:Penguin [sage] 2011/06/05(日) 14:48:51.10 ID:jNueNt7Q Be:
    そうか、sed /^$/d って grep . で良かったんだな 

112 login:Penguin [sage] 2011/06/05(日) 19:30:13.18 ID:Tq0aYVo2 Be:
    >>109
    書き忘れ。
    RS=""のとき、ファイルの末尾の改行も無視する。
    あと、FSが"\n"に設定されているように振舞う。
    元々複数行を一気に処理したい場合に使うことを想定してたのだろう。

    >>110
    ああ、すごい、これは短い!頭柔らかいねえ、スマートだわ。
    夢の中でも考えたのに…無能過ぎワラタ

    >>111
    grep最強伝説はっじまっ…らないぞ。同じ方法で時間計測したら2時間半たっても終わらない。
    grep捨ててawkを使おう! 

grep が遅いってのは、例の multibyte locale だと遅いよ病にかかっちゃってるやつじゃなかろうか。

変数に空文字入れるなら、自分は RS='' のようにするかな。 RS= だとなんか不安だw

■_

2011年06月04日

■_

・グラゼニ
ようやく1巻購入。漫画板にも独立スレがw 辛口のコメントが目立つけど。 【モーニング】 グラゼニ 1球目【アダチケイジ】

む。出るのか。欲しいなあ。 Amazon.co.jp: THE PACIFIC / ザ・パシフィック コンプリート・ボックス(初回限定生産) [DVD]: ジョー・マゼロ, ジェームズ・バッジ・デール, ジョン・セダ, ラミ・マレック: DVD Amazon.co.jp: THE PACIFIC / ザ・パシフィック コンプリート・ボックス(初回限定生産) [Blu-ray]: ジョー・マゼロ, ジェームズ・バッジ・デール, ジョン・セダ, ラミ・マレック: DVD

■_ What Every C Programmer Should Know About Undefined Behavior #2/3

その2.

LLVM Project Blog: What Every C Programmer Should Know About Undefined Behavior #2/3

LLVM Project News and Details from the Trenches

Saturday, May 14, 2011

What Every C Programmer Should Know About Undefined Behavior #2/3
すべての C プログラマーが未定義動作について知っておくべきこと (2/3)

In Part 1 of our series, we discussed what undefined behavior is, and how it allows C
and C++ compilers to produce higher performance applications than "safe"
languages. This post talks about how "unsafe" C really is, explaining some
of the highly surprising effects that undefined behavior can cause. In Part #3, we'll
talk about what friendly compilers can do to mitigate some of the surprise, even if
they aren't required to.

シリーズの第一回では未定義動作とは何であるか、また、C や C++のコンパイラーがどのようにして
“安全な”言語よりも高性能なアプリケーションの生成を可能にしているのかについて論じました。
今回は C が実際にどのように“安全でない”(unsafe) のかについて述べ、未定義動作が可能にする
highly surprising effects のいくつかを解説します。第三回では、たとえ求められていなかったと
しても親切なコンパイラーが some of the surprise を和らげてくれることについてお話します。


I like to call this "Why undefined behavior is often a scary and terrible thing
for C programmers". :-)

わたしはこれを
"Why undefined behavior is often a scary and terrible thing for C programmers".
(なぜ未定義動作は C プログラマーにとってしばしば奇妙で恐ろしいこと (scary and terrible thing) なのか)
と呼ぶのが好きなのです :-)


Interacting Compiler Optimizations Lead to Surprising Results
Interacting Compiler Optimizations (コンパイラーの相互的な最適化?) は驚くべき結果へ導く


A modern compiler optimizer contains many optimizations that are run in specific
orders, sometimes iterated, and change as the compiler evolves over time (e.g. new
releases come out). Also, different compilers often have substantially different
optimizers. Because optimizations run at different stages, emergent effects can occur
due to previous optimizations changing the code.

modern なコンパイラーのオプティマイザーは、特定の順序で実行され、ときに繰り返し行われ
ることもありコンパイラーの進化として繰り返し(たとえば新しいリリースの度に)変更される最
適化を多数含んでいます。同様に、コンパイラーが異なればそれが持つオプティマイザーもかな
り異なるものです。最適化はそれぞれが異なるステージで行われますから、先行して行われた最
適化でコードが変更されたことによって emergent effects が起きる可能性があります。


Lets take a look at a silly example (simplified from an exploitable bug that was found
in the Linux Kernel) to make this more concrete:

より具体的に話をするために、Linux カーネルで発見された exploitable bug を単純にした
silly example を例に見てみましょう:

  void contains_null_check(int *P) {
    int dead = *P;
    if (P == 0)
      return;
    *P = 4;
  }


In this example, the code "clearly" checks for the null pointer. If the
compiler happens to run "Dead Code Elimination" before a "Redundant
Null Check Elimination" pass, then we'd see the code evolve in these two steps:

この例では null ポインターをコードが“きちんと”チェックしています。
もしこのコンパイラーが "Redundant Null Check Elimination" パスの前に
"Dead Code Elimination" を実行してしまったら、
以下のような二ステップの結果のコードを見ることになります:


  void contains_null_check_after_DCE(int *P) {
    //int dead = *P;     // deleted by the optimizer. オプティマイザーによって削除された
    if (P == 0)
      return;
    *P = 4;
  }


and then:

  void contains_null_check_after_DCE_and_RNCE(int *P) {
    if (P == 0)   // Null check not redundant, and is kept. ここでの null チェックは冗長でないのでそのまま
      return;
    *P = 4;
  }


However, if the optimizer happens to be structured differently, it could run RNCE
before DCE. This would give us these two steps:

しかし仮にオプティマイザーが異なる構成であったりすると、DCE の前に RNCE が実行されるかもしれません。


  void contains_null_check_after_RNCE(int *P) {
    int dead = *P;
    if (false)  // P was dereferenced by this point, so it can't be null
      return;   // (この地点に来るまでに P は dereference されているので null ではありえない)
    *P = 4;
  }


and then dead code elimination runs:
そしてそのあと dead code の削除が実行されます:

  void contains_null_check_after_RNCE_and_DCE(int *P) {
    //int dead = *P;
    //if (false)
    //  return;
    *P = 4;
  }


To many (reasonable!) programmers, deleting the null check from this function would be
very surprising (and they'd probably file a bug against the compiler :). However, both
"contains_null_check_after_DCE_and_RNCE" and"contains_null_check_after_RNCE_and_DCE"
are perfectly valid optimized forms of"contains_null_check" according to the
standard, and both of the optimizations involved are important for the performance of
various applications.

多くの (reasonable な!) プログラマーたちにとって、この関数から null チェックを削除して
しまうことはとても驚くこと (そしておそらく、コンパイラーのバグであると主張する :)
でしょう。しかし標準によれば、"contains_null_check_after_DCE_and_RNCE"
と "contains_null_check_after_RNCE_and_DCE" のどちらも、"contains_null_check" の
完全に正当な最適化後の形 (perfectly valid optimized forms) なのです。そしてこの最適化の
結果はどちらも多くのアプリケーションの性能にとって重要なのです。


While this is intentionally a simple and contrived example, this sort of thing happens
all the time with inlining:inlining a function often exposes a number of secondary
optimization opportunities. This means that if the optimizer decides to inline a
function, a variety of local optimizations can kick in, which change the behavior of
the code. This is both perfectly valid according to the standard, and important for
performance in practice.

この例は意図的に単純にして作られたものですが、この種のことはインライン化の際にいつも発生して
います。関数のインライン化はしばしば secondary optimization opportunities の多くを expose し
ます。これは、オプティマイザーがある関数をインライン化すると決定するとコードの動作を変更して
しまうさまざまな局所的な最適化が kick in するかもしれないことを意味します。これらは両方とも
標準に従った完全に正当で、実用上の性能 (performance in practice) にとって重要なものです。


Undefined Behavior and Security Don't Mix Well
未定義動作とセキュリティを混ぜてはいけない

The C family of programming languages is used to write a wide range of security critical code,
such as kernels, setuid daemons, web browsers, and much more. This code is exposed to hostile
input and bugs can lead to all sorts of exploitable security problems. One of the widely
cited advantages of C is that it is relatively easy to understand what is going on when you
read the code.

C ファミリーのプログラミング言語はカーネルや setuid デーモン、web ブラウザーを始めとす
る広い範囲で security critical なコードを書くのに使われています。このコードは hostile 
input (悪意のある入力?) とバグがあらゆる種類の exploitable security problems につなが
りやすいことを expose しています。広く引き合いに出される C のアドバンテージの一つが、
そのコードを読んだときに何をやろうとしているものなのかが相対的に理解しやすいものである
というものです。


C family
Cファミリー

However, undefined behavior takes this property away. After all, most programmers
would think that"contains_null_check" would do a null check above. While
this case isn't too scary (the code will probably crash in the store if passed a null
check, which is relatively easy to debug) there are a wide range of very reasonable
looking C fragments that are completely invalid. This problem has bit many projects
(including the Linux Kernel, OpenSSL, glibc, etc) and even led to CERT issuing a
vulnerability note against GCC (though my personal belief is that all widely-used
optimizing C compilers are vulnerable to this, not just GCC).

しかし、未定義動作はこの属性を取り去ってしまいます。そしてなんといっても、大部分のプロ
グラマーは "contains_null_check" が先に null チェックを行うと考えるでしょう。
このケースは too scary ではありませんが (このコードは null チェックをパスしていたらお
そらくクラッシュしてしまうでしょうが、相対的にはデバッグが容易なものです)、very reasonable
に見えるけれども完全に invalid である C fragments が広範囲に存在します。この問題は
(Linux Kernel, OpenSSL, glibc  等を含む) bit many project が抱えていて、GCC に対して
CERT が issuing a vulnerability note することにさえつながりました (my personal belief
では GCC に限らず広く使われている最適化 C コンパイラーはすべてこれに対する脆弱性が
あります)。


Lets look at an example. Consider this carefully written C code:

では例を挙げて見てみましょう。次のような注意深く書かれた C のコードがあります:

  void process_something(int size) {
    // Catch integer overflow. 整数オーバーフローを捕捉
    if (size > size+1)
      abort();
      ...
    // Error checking from this code elided. この部分でのエラーチェックを省略
    char *string = malloc(size+1);
    read(fd, string, size);
    string[size] = 0;
    do_something(string);
    free(string);
  }

This code is checking to make sure that the malloc is big enough to hold the data read
from the file (because a nul terminator byte needs to be added), bailing out if an
integer overflow error occurs. However, this is exactly the example we gave before in
which the compiler is allowed to (validly) optimize out the check. This means that it
is perfectly possible for the compiler to turn this into:

このコードは (nul 終端バイトを追加する必要があるので) malloc がファイルから読み込んだ
データを保持するのに十分に大きい領域を正しく確保できるかをチェックしています。このとき、
整数オーバーフローが発生した場合には bailng out します。しかし、これはまさしくわたした
ちが以前にコンパイラーが out the check での最適化を (validly に) 許可されているものと
して例示したそのものです。これはコンパイラーが次のように変形することは完全に可能なこと
であるであることを意味します:


  void process_something(int *data, int size) {
    char *string = malloc(size+1);
    read(fd, string, size);
    string[size] = 0;
    do_something(string);
    free(string);
  }


When being built on a 64-bit platform, it is quite likely that this is an exploitable
bug when "size" is INT_MAX (perhaps the size of a file on disk). Lets
consider how terrible this is: a code auditor reading the code would very reasonably
think that a proper overflow check is happening. Someone testing the code would find
no problem unless they specifically tested that error path. The secure code seems to
work, until someone goes ahead and exploits the vulnerability. All in all, this is a
surprising and quite scary class of bugs. Fortunately, the fix is simple in this case:
just use "size == INT_MAX" or similar.


64 ビットプラットフォーム上でビルドを行った場合に "size" が INT_MAX (たぶんディ
スク上にあるファイルのサイズ) であると、これはとても exploitable なバグになりがちなも
のです。これがどれほど怖いのかを考えてみましょう。ある code auditor がこのコードを読ん
だならば適切なオーバーフローチェックが行われていると考えてしまうでしょう誰かがこのコー
ドをテストしても、エラーの経路を specifcally にテストしていない限りは何の問題も見つか
らないでしょう誰かが目をつけてその脆弱性を exploit するまではこのセキュアなコードは動
作するように見えます。概してこれは、 surprising and quite scary class のバグです。運の
良いことにこれを修正するのはとても簡単で、"size == INT_MAX" のような式を使うだ
けです。


As it turns out, integer overflow is a security problem for many reasons. Even if you
are using fully defined integer arithmetic (either by using -fwrapv or by using
unsigned integers), there is a wholly different class of integer overflow bug possible.
Fortunately, this class is visible in the code and knowledgable security auditors are
usually aware of the problem.

すでに説明したように整数オーバーフローは多くの理由によってセキュリティ問題です。たとえ 
(-fwrapv を使うか符号なし整数を使うかして) 完全に定義された整数演算を使っていたとしても、
整数オーバーフローバグが起こりうる完全に別個のクラスがあります。幸いにもこのクラスはコ
ード中で目に見えるものであり、knowledgable security auditors (知識を持ったセキュリティ
監査役) であれば普通はこの問題に注意を払っているでしょう。


Debugging Optimized Code May Not Make Any Sense
最適化済みのコードをデバッグするのは意味のないことかもしれない

Some people (for example, low level embedded programmers who like to look at generated
machine code) do all of their development with optimizations turned on. Because code
frequently has bugs when it is being developed, these folks end up seeing a
disproportionate number of surprising optimizations that can lead to
difficult-to-debug behaviors at runtime. For example, accidentally leaving out the
"i = 0" in the "zero_array" example from the first article allows
the compiler to completely discard the loop (compiling zero_array into
"return;") because it is a use of an uninitialized variable.

一部の人たち (たとえば生成された機械語を確認するのが好きな low level 組み込みのプログラマー)
は最適化を有効にしてすべての開発を行います。なぜなら開発途上にあるコードは頻繁にバグを持つも
のであるので、そういった人たちは結局実行時の difficult-to-debug behaviors (デバッグが困難な
動作) に繋がりやすい surprising optimizations の数を過剰に見てしまうことになるのです。たとえ
ば第一回の例にあった "zero_array" 関数で "i = 0" を間違って消してしまった
場合、コンパイラーはループを完全に捨て去ってしまう (zero_array 関数を "return"にコン
パイルする) ことを許可していしまいます。なぜならその代入を消したことによって、初期化していな
い変数を使うようになってしまっているからです。


Another interesting case that bit someone recently happened when they had a (global)
function pointer. A simplified example looks like this:

もう一つの intersting case は彼らが(グローバルな)関数ポインターを使ったときに発生しました。
以下に単純にした例を示します:


  static void (*FP)() = 0;
  static void impl() {
    printf("hello\n");
  }
  void set() {
    FP = impl;
  }
  void call() {
    FP();
  }

which clang optimizes into:
clang はこれを次のように最適化します:

  void set() {}
  void call() {
    printf("hello\n");
  }

It is allowed to do this because calling a null pointer is undefined, which permits it
to assume that set() must be called before call(). In this case, the developer forgot
to call "set", did not crash with a null pointer dereference, and their code
broke when someone else did a debug build.

null ポインターの呼び出し (の動作とその結果) は未定義であるため set() が call() よりも
先に呼び出されるはずであると仮定できるので、このような最適化が可能となります。この場合、
developer が"set" を呼び出すのを忘れても null ポインター の dereference では
クラッシュせず、他の誰かがデバッグビルドを行ったときにコードが壊れます。


The upshot is that it is a fixable issue: if you suspect something weird is going on
like this, try building at -O0, where the compiler is much less likely to be doing any
optimizations at all.

その結論はこれが修正可能な問題 (fixable issue) であるということです: もしあなたがなに
かおかしなことが起こっているのではないかと思ったなら、-O0 オプションを指定してビルドし
てみましょう。このオプションはコンパイラーがすべての最適化をあまり行わないようにする
ものです。



"Working" code that uses undefined behavior can "break" as the
compiler evolves or changes

未定義動作を使っている “Working”コードがコンパイラーの進化や変化に伴って“壊れる”かもしれない


We've seen many cases where applications that "appear to be work" suddenly
break when a newer LLVM is used to build it, or when the application was moved from
GCC to LLVM. While LLVM does occasionally have a bug or two itself :-), this is most
often because of latent bugs in the application that are now being exposed by the
compiler. This can happen all sorts different ways, two examples are:

わたしたちはより新しい LLVM をビルドに使ったときや GCC から LLVM に移行したときに
"appear to be work" なアプリケーションが突如として動かなくなるケースを数多く
目撃してきました。LLVM はそれ自身に一つや二つのバグを抱えてしまうこともあるのです :-) 
が、コンパイラーによって expose されるアプリケーションの潜在バグのためにこれは とても
頻繁にあるのです。これは all sorts different ways で起こる可能性があります。
二つ例を挙げましょう:


1. an uninitialized variable which was zero initialized by luck "before",
and now it shares some other register that isn't zero. This is commonly exposed by
register allocation changes.

“以前は”偶然にもゼロで初期化されていたがゼロではない別のレジスターを共有のようになっ
た未初期化変数。このバグは一般的にレジスター割り当てが変更されたときに expose されます。

2. an array overflow on the stack which starts clobbering a variable that actually
matters, instead of something that was dead. This is exposed when the compiler
rearranges how it packs things on the stack, or gets more aggressive about sharing
stack space for values with non-overlapping lifetimes.

すでに死んでいるのではなく actulally matters な変数の clobbering を始めてしまう
スタック上配列のオーバーフロー。これはスタック上でどのようにパッキングするかをコンパイ
ラーがアレンジしなおしたときや、生存期間がオーバーラップしていない values のためのスタ
ックスペースを共有することをより積極的に行おうとしたときにexpose します。


The important and scary thing to realize is that just about *any* optimization based
on undefined behavior can start being triggered on buggy code at any time in the
future. Inlining, loop unrolling, memory promotion and other optimizations will keep
getting better, and a significant part of their reason for existing is to expose
secondary optimizations like the ones above.

認識すべき重要かつ scary なことは、将来のどこかの時点でバギーなコードにしてしまう可能性
のある未定義動作に基づいた *すべての* 最適化についてだけです。インライン化、ループのア
ンローリング、memory promotion、さらにはそのほかの最適化は改良され続けるでしょうし、そ
してそれらが存在する理由の significant part はひとつ前のような secondary optimizations
を expose するためです。
#だめだー

To me, this is deeply dissatisfying, partially because the compiler inevitably ends up
getting blamed, but also because it means that huge bodies of C code are land mines
just waiting to explode. This is even worse because...

わたしにとってこれはとても満足できるものではありません。それは部分的にはコンパイラーが
必然的に責任を負わされるからだけでなく、C のコードの huge bodies が explode を待ちかま
えている地雷でもあるからです。これは一層ひどいことでさえあります。なぜなら…


There is No Reliable Way to Determine if a Large Codebase Contains Undefined Behavior
ある大規模なコードベースが未定義動作を含んでいるかどうかを決定する信頼できる方法はない

Making the landmine a much much worse place to be is the fact that there is no good
way to determine whether a large scale application is free of undefined behavior, and
thus not susceptible to breaking in the future. There are many useful tools that can
help find some of the bugs, but nothing that gives full confidence that your code
won't break in the future. Lets look at some of these options, along with their
strengths and weaknesses:

Making the landmine a much much worse place to be (地雷をもっともっと悪い場所へ置く?) とは、
大規模アプリケーションが free of undefined behaviir であるかどうか、また、将来において 
breaking する影響を受けないかどうか判断するための good way はないということです。これ
らのバグの一部を見つけるのを手助けできるたくさんの便利なツールがありますが、あなたのコ
ードが将来においても壊れることがないという full confidence を与えてくれるものはありませ
ん。ではこれらの選択肢のいくつかをその長所と短所とともに見てみましょう: 

1. The Valgrind memcheck tool is a fantastic way to find all sorts of uninitialized
variables and other memory bugs. Valgrind is limited because it is quite slow, it can
only find bugs that still exist in the generated machine code (so it can't find things
the optimizer removes), and doesn't know that the source language is C (so it can't
find shift-out-of-range or signed integer overflow bugs).

Valgrind というメモリーチェックのツールは未初期化変数を始めとするメモリバグを見つけ出
すための fantastic way です。Valgrind はとても遅く、また、生成された機械語に存在してい
るバグだけを見つけられる(オプティマイザーが除去したものを見つけ出すことはできない) と
かソースの言語が C であることを知らない(そのため、範囲外シフトバグや符号付き整数
オーバーフローバグといったものを検出できない) といった理由でその使用が限定されます。


2. Clang has an experimental -fcatch-undefined-behavior mode that inserts runtime
checks to find violations like shift amounts out of range, some simple array out of
range errors, etc. This is limited because it slows down the application's runtime and
it can't help you with random pointer dereferences (like Valgrind can), but it can
find other important bugs. Clang also fully supports the -ftrapv flag (not to be
confused with -fwrapv) which causes signed integer overflow bugs to trap at runtime
(GCC also has this flag, but it is completely unreliable/buggy in my experience). Here
is a quick demo of -fcatch-undefined-behavior:

Clang は、シフト量の out of range だとか一部の単純な配列の範囲外エラーのチェックなどと
いったものを検出するための実行時チェックを挿入する、実験的な -fcatc-undefined-behavior 
モードを持っています。これはアプリケーションのランタイムをスローダウンさせ、またrandom 
pointer の dereferences に関しては(Valgrind ができるようには) 手助けしてくれないので制
限がありますが、そのほかの重要なバグを見つける助けはしてくれます。Clang はまた、符号付き
整数オーバーフローバグを実行時にトラップさせる -ftrapvフラグ (-fwrapv と混同しないでくだ
さい) をフルサポートしています (GCC もこのフラグをサポートしていますが、それはわたしの
経験からすると全然信用できないバギーなものです)。以下に挙げたのは
-fcatch-undefined-behavior の quick demo です:

  $ cat t.c
  int foo(int i) {
    int x[2];
    x[i] = 12;
    return x[i];
  }

  int main() {
    return foo(2);
  }
  $ clang t.c
  $ ./a.out
  $ clang t.c -fcatch-undefined-behavior
  $ ./a.out
  Illegal instruction

3. Compiler warning messages are good for finding some classes of these bugs, like
uninitialized variables and simple integer overflow bugs. It has two primary
limitations: 1) it has no dynamic information about your code as it executes, and 2)
it must run very quickly because any analysis it does slows down compile time.

コンパイラーの警告メッセージは、未初期化変数や単純な整数オーバーフローバグのような一部
のクラスのバグを見つけ出すのに役立ちます。ここには二つの primary な制限があります。
それは
1) コードが実行されるときの動的情報を持っていないことと、
2) すべての解析はコンパイル時間を増大させるので very quickly に実行しなければならない
ことです。


4. The Clang Static Analyzer performs a much deeper analysis to try to find bugs
(including use of undefined behavior, like null pointer dereferences). You can think
of it as generating souped up compiler warning messages, because it is not bound by
the compile time constraints of normal warnings. The primary disadvantages of the
static analyzer is that it 1) doesn't have dynamic information about your program as
it runs, and 2) is not integrated into normal workflows for many developers (though
its integration into Xcode 3.2 and later is fantastic).

Clang の Static Analyzer はバグを見つけ出すために (null ポインターの dereference のような未
定義動作の使用を含む)より deep な解析を行います。通常の警告を制約しているコンパイル時間に束
縛されていないので、これはコンパイラーの警告メッセージの生成を souped up (活発にする) する
ように考えられます。static analyzer の primary disadvantaes はこうです
1) プログラムが実行されたときの動的情報を持っていないこと。および
2) 多くのdevelopersにとっての通常のワークフローに統合されていない
   (ただし、Xcode 3.2 以降の統合は fantastic です)。


5. The LLVM "Klee" Subproject uses symbolic analysis to "try every
possible path" through a piece of code to find bugs in the code and it produces a
testcase. It is a great little project that is mostly limited by not being practical
to run on large-scale applications.

LLVM の "Klee" サブプロジェクトは symbolic analysis を使い、コードにあるバグ
を見つけ出すための a piece of code を通じてテストケースを生成することを
"try every possible path" しています。
この“Klee”サブプロジェクトは
mostly limited by not being practical to run on large-scale applications
#大規模アプリケーションで実行するという実践的なものではないことが理由で制限されている?
である優れた小規模プロジェクトです。


6. While I have never tried it, the C-Semantics tool by Chucky Ellison and Grigore
Rosu is a very interesting tool that can apparently find some classes of bugs (such as
sequence point violations). It is still a research prototype, but may be useful for
finding bugs in (small and self-contained) programs. I recommend reading John Regehr's
post about it for more information.

わたしは試したことがないのですが、Chucky Ellison と Grigore Rosu による C-Semantics と
いうツールは副作用完了点 (sequence point) 違反のような一部のクラスのバグを見つけ出すの
が可能な非常に興味深いツールです。このツールはまだ研究段階のプロトタイプですが、(小さ
くて  self-contained な)プログラムにあるバグを見つけ出すのに便利かもしれません。この件
についての詳細は John Regehr のポストを読むことをお勧めします。


The end result of this is that we have lots of tools in the toolbox to find some bugs,
but no good way to prove that an application is free of undefined behavior. Given that
there are lots of bugs in real world applications and that C is used for a broad range
of critical applications, this is pretty scary. In our final article, I'll look at
various options that C compilers have when dealing with undefined behavior, with a
specific focus on Clang.

今回の結論は、わたしたちはいくつかのバグを見つけだすためのたくさんのツールを道具箱の
中に持っているけれども、検出する良い手段を持たないアプリケーションが free of undefined
behavior であるということです。現実世界のアプリケーションには多くのバグがあり、そして
critical アプリケーションでとても広く C は使われているのですが、これはとても怖いことな
のです。最終回では、特に Clang に焦点を置いて、未定義動作を扱うときに C コンパイラーが
持っている様々なオプションを見ていきます。
#Given that ってどう解釈すべきなんだー

-Chris Lattner

Posted by Chris Lattner at 12:33 PM

About The LLVM Blog

This blog is intended to be a news feed for information about the LLVM Compiler
Infrastructure and related subprojects.

Note that comments are disabled here, we prefer you to respond on mailing lists like
llvmdev or cfe-dev.

We welcome new contributors. If you'd like to write a post, please get in touch with Chris.

ご意見歓迎。

■_

ちょい寝かせる

■_

I'm spending more time having in-person in-depth conversations, and less time coding. とかまつもとさんを連想した。

Neopythonic: The depth and breadth of Python

Friday, June 3, 2011

The depth and breadth of Python

As of late I'm noticing a trend: I'm spending more time having in-person in-depth 
conversations, and less time coding. While I regret the latter, I really enjoy the 
former. Certainly more than weekly meetings, code reviews, or bikeshedding email 
threads. (I'm not all that excited about blogging either, as you may have guessed; but 
some things just don't fit in 140 characters.)

Two conversations with visitors I particularly enjoyed this week were both with very 
happy Python users, and yet they couldn't be more different. This to me is a 
confirmation of Python's enduring depth and breadth: it is as far away of a one-trick 
language as you can imagine.

略
Of course Annie had some requests as well. I'll probably go over these in more detail 
on python-ideas, but here's a quick rundown (of what I could remember):

当然、Annie はリクエストもいくつか持っていました。わたしはそれを python-ideas で
より詳細に検討するだろうと思いますが、ここに(思い出すことのできた)ものを
quick rundown します:

    * Quantifiers. She is really longing for the "SOME x IN xs HAS pred" notation
      from ABC (and its sibling "EACH x IN xs HAS pred"), which superficially
      resemble Python's any() and all() functions, but have the added semantics of making x
      available in the scope executed when the test succeeds (or fails, in the case of EACH
      -- then x represents a counterexample).
      Quantifiers.
      彼女は ABC にあった "SOME x IN xs HAS pred" 記法と (その sibling である
      "EACH x IN xs HAS pred") をとても熱望していました。
      これは Python の any() や all() といった関数に superficially に似たものですが、
      テストが成功したときに x を、それが実行されたスコープで利用可能にするというセマン
      ティクスを持っています(EACH では失敗した場合にそうなる(?)
      -- then x represents a counterexample)。

    * Type declarations. (Though I think she would be happy with Python 3 function annotations,
      possibly augmented with the attribute declarations seen in e.g. Django and App Engine's
      model classes.)
      型宣言 (Python 3の関数アノテーションがあれば彼女は満足だろうと思ったのですが、
      Django や App Engine の モデルクラスに見られるような属性宣言を伴った主張だったようです)
      #わからん

    * Pattern matching, a la Erlang. I have been eying these myself from time to time; it is
      hard to find a syntax that really shines, but it seems to be a useful feature.

      Erlang のような パターンマッチング。
      わたし自身、これには時々注目していたのですが、really shines (本当に優れた?) な構文を
      見つけ出すのが困難です。とはいえ、これは有用な機能になるでしょう。

    * Something she calls labels or yield points. It seems somewhat similar to yield statements
      in generators, but not quite.

      彼女が labels とか yield points と呼んでいた何か。
      ジェネレーターにおける yield 文と同様のもののように思えたたのですが、まったく同じものでは
      ありません。

    * She has only recently begun to look at distributed algorithms (she had some Leslie Lamport
      anecdotes as well) and might prefer sets to be immutable after all. Though that isn't so
      clear; her work so far has actually benefited from mutating sets to maintain some
      algorithmic invariant. (The "incrementalize" of the three I's actually refers to
      a form of "differentiation" of expressions that produce a new set for each input.)

以下略
Next Monday I'm having lunch with another high-tech enterpreneur, a Y-combinator 
start-up founder using (and contributing to) App Engine. Maybe I should just cancel 
all weekly meetings and sign off from all mailing lists and focus on two things: 
meeting Python users and coding. That's the life!

Posted by Guido van Rossum at 9:17 AM


Guido van Rossum
    Python's BDFL

コメント欄のやり取りも面白いものがあるんだけど、略。

■_ 今日のawkネタ

OKWvaeから。

awkで計算した結果を反映させる方法 | OKWave

初心者です。おしえてください。
awkで次のようなことをするにはどうすればよいでしょうか?
コーディング例を教えてください。


テキストファイルのレコードの一部が数値項目で、
その数値項目から3を引いた結果をその数値項目に置換えたいです。
(区切り文字がない1レコードのみが入ったテキストファイルを読み込みます。)


例)
aaaaa10000bbbbb20000

6~10カラムの「10000」から-3をした「9997」を置き換えて、

aaaaa09997bbbbb20000

としたいです。


awkで無くても、Unix(HP-UX)のコマンドやBシェルで可能であれば、
構わないのでおしえてください。

よろしくお願いいたします。

質問者が選んだベストアンサー

awk 'BEGIN{FIELDWIDTHS="5 5 100";OFS=""}{$2=sprintf("%05d",$2-3);print}'

または

awk '{print substr($0,1,5) sprintf("%05d",substr($0,6,10)-3) substr($0,11)}'

FIELDWIDTHS は gawk 固有の拡張だってばよ…

substr 3回呼びは美しくないが、といって substr の戻り値が lvalue 持ってるのはPerlか。 こういう局面で使える gawk の拡張があったと思うんだけどなんだったかなあ。

■_ Haskell参戦

Scala と Rubyでやってたあれね。

-= 10 Haskell One Liners to Impress Your Friends =-

10 Haskell One Liners to Impress Your Friends

Jun 3, 2011

I would truly appreciate feedback from people whom actually know Haskell. As you may 
notice below, my grasp is not yet strong.

Multiple Each Item in a List by 2 (リストの全要素をそれぞれ2倍にする)

map (*2) [1..10]

Sum a List of Numbers (数値のリストの合計を求める)

foldl (+) 0 [1..1000]

-- or better (より良い別解)

sum [1..1000]

Verify if Exists in a String (文字列が存在するものかどうかべりファイ)

import Data.List
let wordlist = ["monad", "monoid", "Galois", "ghc", "SPJ"]
let tweet = "This is an example tweet talking about SPJ interviewing with Galois"

or $ map (flip isInfixOf tweet) wordlist

-- or better

any (flip isInfixOf tweet) wordlist

Read in a File

fileText <- readFile "data.txt"

let fileLines = lines fileText

-- or better

let fileLines = fmap lines $ readFile "data.txt"

Happy Birthday to You!

mapM_ putStrLn ["Happy Birthday " ++ (if x == 3 then "dear NAME" else "to You") | x <- [1..4]]

Filter list of numbers (数値のリストをフィルタリング)

let (passed, failed) = partition (>60) [49, 58, 76, 82, 88, 90]

Fetch and Parse an XML web service

this example needs the curl and xml packages. see RWH for info on installing them

import Network.Curl
import Text.XML.Light
import Control.Monad

let results = liftM parseXMLDoc $ liftM snd (curlGetString "http://search.twitter.com/search.atom?&q=haskell" [])

-- or better 

Control.Applicative
let results = parseXMLDoc . snd <$> curlGetString "http://search.twitter.com/search.atom?&q=haskell" []

Find minimum (or maximum) in a List (リスト中の最小値を求める)

foldl1 min [14, 35, -7, 46, 98]
foldl1 max [14, 35, -7, 46, 98]

-- or better

minimum [14, 35, -7, 46, 98] 
maximum [14, 35, -7, 46, 98]

Parallel Processing

this example needs the parallel package.

import Control.Parallel
import Control.Parallel.Strategies

parMap rseq (*2) [1..100]

Prime number generation (素数ジェネレーター)

let pgen (p:xs) = p : pgen [x|x <- xs, x `mod` p > 0]

take 40 (pgen [2..])

:F

■_

■_

アレがアレなことになりそうなのがほぼ確定でとってもアレです(謎)

2011年06月03日

■_

東風戦

■_ 今日の重箱の隅

InfoQ: プログラミング言語Colmの紹介

    変換言語は形式言語に基づいた型システムを持っています。クラスやデータ構造を定義するの
    ではなく、文法を定義するのです。パーサーは文法から自動で生成されます。パーサーの目的
    はふたつです。入力された言語を解析することと分析を行うプログラムの構造パターンを解析
    します。文法に基づいた構文解析は重要です。入力と構造パターンが同じ型からツリーへと解
    析されることを保証するからです。これによって比較が可能になります。

Colmはこの解析の手法を改善する。

    Colmの解析エンジンは汎用的で、解析中に利用できる任意のグローバルデータ構造が構築できま
    す。他の汎用的な方法では、グローバルデータ構造を構築するのは細心の注意が必要です。構文
    解析固有の並列性があるからです。したがって、この方法は使われず、問題は解析後の解析フォ
    レストの曖昧さの排除に持ち越されます。 

    Colmを使えば、バックトラック法が利用できるなら、最初に入力した段階で正しい解析木を生成
    できます。グローバルデータの並列更新可否の判断をしなくて済みます。また、間違っている解
    析木を排除するためだけにあり得る解析木を生成する必要もありません。 

言語ワークベンチの開発とColmのような強力な変換技術のおかげでメタプログラミング(または、
メタモデル指向プログラミング)はずいぶん進歩した。あなたは既に利用しているだろうか。ど
うお考えだろうか。

一つ目のパラグラフ、 「パーサの目的は二つです」ときて、それに続く文でその目的は X と Y です。 てな感じではなく、 入力された言語を解析することと分析を行うプログラムの構造パターンを解析します。 なぜに「することと~」ときて「解析します。」で文を締めているんでしょうか。 その後ろの短い文三つもリズムが悪いというか不必要にぶった切っちゃってるというか。

InfoQ: Introducing the Colm Programming Language

    A transformation language has a type system based on formal languages. Rather than
    define classes or data structures, one defines grammars. A parser is constructed
    automatically from the grammar, and the parser is used for two purposes: to parse
    the input language, and to parse the structural patterns in the program that
    performs the analysis. In this setting, grammar-based parsing is critical because
    it guarantees that both the input and the structural patterns are parsed into
    trees from the same set of types, allowing comparison. 

Colm's main contribution lies in the parsing method:

    Colm's parsing engine is generalized, but it also allows for the construction of
    arbitrary global data structures that can be queried during parsing. In other
    generalized methods, construction of global data requires some very careful
    consideration because of inherent concurrency in the parsing method. It is such a
    tricky task that it is often avoided altogether and the problem is deferred to a
    post-parse disambiguation of the parse forest. 

    Using Colm it is possible to get the correct parse tree on the first pass of the
    input, granted that some backtracking is acceptable. Colm eliminates the need to
    reason about concurrent updates to global data or to acquire many possible parse
    trees, only to throw away the incorrect ones.

Metaprogramming (a.k.a. Metamodel Oriented Programming) is making great progress 
thanks to the development of Language Workbenches and powerful transformation 
technologies such as Colm. Are you closer to use one? Are you already using one? what 
is your take on it?

「これによって」というのに違和感があるし、なにとなにの「比較」が「可能」になったんでしょう。 その前の文と分けちゃいけない気がするんですけど。

二つ目のパラグラフ、原文の but also を反映してないような。 それと、It is such a tricky taskのあたりも一部がすこーんと抜けてるし したがって、この方法は使われず、はどこから? 比較されている二つのどちらも「generalized」されているという点では同じで、 「global data」の取り扱いが違うとあるのだからその辺明確にしないといけないのではないでしょうか。

三つ目のパラグラフも granted that some backtracking is acceptableバックトラック法が利用できるなら のように、仮定とか条件として出てくるのは? or を挟んだ前後の文も違和感が。

■_

InfoQ: Exceptional Ruby


    また、本書が確立されたプログラミング文献に基づいているよう強く望みました。そこで、
    "Code Complete"、"The Practice of Programming"、"The Pragmatic
    Programmer"といった古典を本棚から引っ張り出して、エラー処理に関するセクションを
    読み返しました。それらの定義や、例外やエラーについて検討するための信頼できるフレー
    ムワークを確立するために、Bertrand Meyer氏の "Object-Oriented Software 
    Construction" に立ち返りました。Meyer氏のプログラミング言語Eiffelは、Rubyの例外シ
    ステムに強い影響を与えています。メソッドが呼び出し元と「契約」を共有するというアイデア
    は、「エラー」「失敗」「例外」といった用語について語るとき、何を意味しているかを明確に
    するのに本当に役立ちます。

InfoQ: Exceptional Ruby


    I also wanted very much for the book to be grounded in the established programming 
    literature. So dusted off my library and re-read sections on dealing with failure in 
    classics like "Code Complete", "The Practice of Programming", and 
    "The Pragmatic Programmer". In order to establish definitions, as well as a 
    solid framework for thinking about exceptions and failures, I went back to Bertrand 
    Meyer's "Object-Oriented Software Construction". Meyer's programming 
    language, Eiffel, strongly influenced Ruby's exception system, and his work on the 
    idea of a method having a "contract" with its caller really helps clarify 
    what we mean when we talk about terms like "error", "failure", and 
    "exception".

最後の文の 「and his work on the idea of a methods ~」 の his work が抜けてるし、「contract with its caller」 を「契約を共有」ってのも違和感が。 「契約」って「共有」するもの?

■_ gawk

3.1.84 のはなし。 ひとつ前のベータ版と比較するとわりと差分がでかいのだけど それほど込み入った変更ではないっぽい感じ。 んで、

--- gawk-3.1.76/dfa.c	2010-10-31 19:25:52.000000000 +0900
+++ gawk-3.1.84/dfa.c	2011-05-15 04:34:30.000000000 +0900
(略)
@@ -591,7 +598,8 @@
   else
     {
 #if MBS_SUPPORT
-      if (wctob ((unsigned char)b) == b)
+      int b2 = wctob ((unsigned char) b);
+      if (b2 == EOF || b2 == b)
 #endif
         setbit (b, c);
     }
@@ -714,26 +722,8 @@
 
 #endif /* MBS_SUPPORT */
 
-static int
-in_coll_range (char ch, char from, char to)
-{
-  char c[6];
-  c[0] = from;
-  c[1] = 0;
-  c[2] = ch;
-  c[3] = 0;
-  c[4] = to;
-  c[5] = 0;
-  return strcoll (&c[0], &c[2]) <= 0 && strcoll (&c[2], &c[4]) <= 0;
-}
-
 typedef int predicate (int);
 
-#ifdef GAWK
-#define bool int
-#define true (1)
-#define false (0)
-#endif
 /* The following list maps the names of the Posix named character classes
    to predicate functions that determine whether a given character is in
    the class.  The leading [ has already been eaten by the lexical analyzer. */
@@ -1007,10 +997,24 @@
                 for (c = c1; c <= c2; c++)
                   setbit_case_fold (c, ccl);
               else
-                for (c = 0; c < NOTCHAR; ++c)
-                  if (!(case_fold && isupper (c))
-                      && in_coll_range (c, c1, c2))
-                    setbit_case_fold (c, ccl);
+                {
+                  /* Defer to the system regex library about the meaning
+                     of range expressions.  */
+                  regex_t re;
+                  char pattern[6] = { '[', 0, '-', 0, ']', 0 };
+                  char subject[2] = { 0, 0 };
+		  pattern[1] = c1;
+		  pattern[3] = c2;
+                  regcomp (&re, pattern, REG_NOSUB);
+                  for (c = 0; c < NOTCHAR; ++c)
+                    {
+                      subject[0] = c;
+                      if (!(case_fold && isupper (c))
+                          && regexec (&re, subject, 0, NULL, 0) != REG_NOMATCH)
+                        setbit_case_fold (c, ccl);
+                    }
+                  regfree (&re);
+                }
             }
 
           colon_warning_state |= 8;
@@ -1509,7 +1513,6 @@
       addtok(CAT);
     }
 }
-#endif
 
 static void
 add_utf8_anychar (void)

文字クラスの扱いに手を入れたようですね。 POSIX (やC)以外の locale でいろいろ「クレーム」があがってましたから。

■_ Ruby と Scala

スクリプト(プログラム)部分だけ抜き出し。

10 Scala One Liners to Impress Your Friends – @sologco

10 Scala One Liners to Impress Your Friends

Posted on May 31, 2011	

Here are 10 one-liners which show the power of scala, impress your friends and woo 
women; ok, maybe not. However, these one liners are a good set of examples using 
functional programming and scala syntax you may not be familiar with. I feel there is 
no better way to learn than to see real examples.

1. Multiple Each Item in a List by 2

	(1 to 10) map { _ * 2 }


2. Sum a List of Numbers

	(1 to 1000).reduceLeft( _ + _ )


3. Verify if Exists in a String

	val wordlist = List("scala", "akka", "play framework", "sbt", "typesafe")
	val tweet = "This is an example tweet talking about scala and sbt."
	 
	(words.foldLeft(false)( _ || tweet.contains(_) ))


4. Read in a File

	val fileText = io.Source.fromFile("data.txt").mkString
	 
	val fileLines = io.Source.fromFile("data.txt").getLines.toList


5. Happy Birthday to You!

	(1 to 4).map { i => "Happy Birthday " + (if (i == 3) "dear NAME" else "to You") }.foreach { println }

6. Filter list of numbers

	val (passed, failed) = List(49, 58, 76, 82, 88, 90) partition ( _ > 60 )


7. Fetch and Parse an XML web service

	val results = XML.load("http://search.twitter.com/search.atom?&q=scala")


8. Find minimum (or maximum) in a List

	List(14, 35, -7, 46, 98).reduceLeft ( _ min _ )
	List(14, 35, -7, 46, 98).reduceLeft ( _ max _ )


9. Parallel Processing

	val result = dataList.par.map(line => processItem(line))


10. Sieve of Eratosthenes

	(n: Int) => (2 to n) |> (r => r.foldLeft(r.toSet)((ps, x) => if (ps(x)) ps -- (x * x to n by x) else ps))

10 Ruby One Liners to Impress Your Friends

10 Ruby One Liners to Impress Your Friends

Posted on Jun 2nd, 2011 in Ruby, Scala

Multiply each item in a list by 2

(1..10).map { |n| n * 2 }

Sum a list of numbers

(1..1000).inject { |sum, n| sum + n }

Or using the (built in) Symbol#to_proc syntax that’s been available since Ruby 1.8.7:

(1..1000).inject(&:+)

Or even just passing a symbol directly:

(1..1000).inject(:+)

Verify if tokens exist in a string

words = ["scala", "akka", "play framework", "sbt", "typesafe"]
tweet = "This is an example tweet talking about scala and sbt."

words.any? { |word| tweet.include?(word) }

Reading a file

file_text = File.read("data.txt")
file_lines = File.readlines("data.txt")

File.read("data.txt").split(/\n/)

Happy Birthday

4.times { |n| puts "Happy Birthday #{n==2 ? "dear Tony" : "to You"}" }

Filter a list of numbers

[49, 58, 76, 82, 88, 90].partition { |n| n > 60 }

Fetch and parse an XML web service

require 'open-uri'
require 'hpricot'

results = Hpricot(open("http://search.twitter.com/search.atom?&q=scala"))

Find minimum (or maximum) in a list

[14, 35, -7, 46, 98].min
[14, 35, -7, 46, 98].max

Parallel Processing

require 'parallel'

Parallel.map(lots_of_data) do |chunk|
  heavy_computation(chunk)
end

Sieve of Eratosthenes

index = 0
while primes[index]**2 <= primes.last
      prime = primes[index]
      primes = primes.select { |x| x == prime || x % prime != 0 }
      index += 1
end
p primes

Copyright © 2005-2011 Antonio Cangiano. All rights reserved.

エラトステネスのふるいがだいぶ違うなあ。

■_

■_

じかんねー。的な。

2011年06月02日

■_

Scala Daysとか。

■_ call by

またそれか。と言われようとも :)

★★Java質問・相談スレッド145★★ 

55 デフォルトの名無しさん [sage] 2011/06/02(木) 11:25:28.31 ID: Be:
    javaの参照渡しについてど忘れして、ぐぐっても全く分からない…

    int a = 10;
    clearA(a);

    public void clearA(int a) {
    a = 0;
    }

    といった流れにしたいんだけど、これだと値渡しだから
    結局aは10のまま

    returnは使いたくないんだがどうしたらいいのだろうか?
    調べると大体がnew ウンタラしてるけどnewして削除用のオブジェクト作らないとだめなの?

    C++だったら
    public void clearA(int &a)
    で確かポインタ使わずに参照渡し出来て
    そのまま変更出来たと思うんだが… 

56 デフォルトの名無しさん [sage] 2011/06/02(木) 11:40:17.92 ID: Be:
    素直にC++をつかってdくさおえい 

57 デフォルトの名無しさん [sage] 2011/06/02(木) 11:41:55.87 ID: Be:
    そんなあなたにC# 

59 デフォルトの名無しさん [sage] 2011/06/02(木) 11:45:52.39 ID: Be:
    はいはい、参照の値渡し参照の値渡し 

60 デフォルトの名無しさん [] 2011/06/02(木) 11:47:10.75 ID: Be:
    >>55

    × a = 0;
    ○ this.a = 0;

    javaはポインターの意識が希薄だし、
    CやC++だとしても、同じ事やってもスコープが違うので値は変更できんでしょ。
    ポインターを渡せないんだから、上のような工夫で対応できないこともない場合もある。

    ただ、return を使いたくない、とか
    なんかオブジェクト指向を履き間違えてコードを書いているような予感。

    thisを使いまくるとデバッグが大変だよ 

61 デフォルトの名無しさん [sage] 2011/06/02(木) 12:22:38.93 ID: Be:
    >>60
    サンクス 

62 【東電 81.2 %】 忍法帖【Lv=3,xxxP】 [sage] 2011/06/02(木) 12:36:19.56 ID: Be:
    return(0);
    して
    a=cleara()
    しちゃえばいいのにと思った。

    ruby的にa.clearとしたくはなるけどw 

63 デフォルトの名無しさん [sage] 2011/06/02(木) 13:31:54.23 ID: Be:
    >>55
    そもそもreturn使いたくない理由ってなに?
    それによっては別の解決策を出せるかも知れない 

64 デフォルトの名無しさん [sage] 2011/06/02(木) 13:47:21.50 ID: Be:
    >>63
    あー、android(JAVA)勉強中でメモリ管理が厳しくて
    別関数で受け皿作ったのをリターンしてたら、容量食うかな?と
    実際out of memory多発で少しでも減らしたいなー…と

    取得してきたデータ画像が2560x1920とかいう超サイズだったから
    これを640x480にしたら、余裕再々になったっていうね…

    あとの処理は1行のものを態々関数にしようとしてたアホな感じだったんで…(returnシタクナイノハココ)
    ただのアホの子でした。
    呼び出し
    registerCompressBitmap(offBitmap, out, bos);

    関数
    private void registerCompressBitmap(Bitmap offBitmap, FileOutputStream out, ByteArrayOutputStream bos) {
    offBitmap.compress(CompressFormat.JPEG, 70, bos);
    try {
    out.write(bos.toByteArray());
    out.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    之に関してはobjなんで、out.closeでoutに関してはmainの方でも
    閉じられてるって感じでいいんですよね 

65 デフォルトの名無しさん [] 2011/06/02(木) 13:58:34.14 ID: Be:
    >>64
    むしろ、returnしたほうが、GCが勝手に掃除してくれてメモリの節約になると思うが、気のせいか? 

66 デフォルトの名無しさん [sage] 2011/06/02(木) 14:03:27.33 ID: Be:
    >>65
    なるほどー、イメージ的には
    ポットA&BをバケツAにいれた後に
    returnで、バケツAをBに入れるってイメージだったから
    その間AとBが両方存在して多いよなーと思ったけど
    よくよく考えて見れば、完全コピーじゃなくて、移動だったら 50 と 50になって全体量は変わらないですよね・・ 

67 デフォルトの名無しさん [sage] 2011/06/02(木) 14:08:04.23 ID: Be:
    >>66
    まず、ちゃんとプロファイラ使って実際の状況を確かめる事を勧める 

85 デフォルトの名無しさん [sage] 2011/06/02(木) 19:39:33.96 ID: Be:
    プリミティブ>値渡し
    プリミティブの配列>参照渡し
    オブジェクト型>参照渡し

    という理解であってますか? 

87 デフォルトの名無しさん [sage] 2011/06/02(木) 19:58:43.03 ID: Be:
    >>85
    プリミティブ>値渡し
    プリミティブの配列>値渡し
    オブジェクト型>値渡し 

Javaの入門書の中では売れてるほうであろうと思われるとある本 (特に名を秘す) でも 85 みたいなこと書いてたからなあ。

■_ 3 の

コンパイラー最適化入門: 第1回 SIMD 命令とプロセッサーの関係 | iSUS の中ほどにある SIMD 命令セットの歴史ってタイトルの画像ファイル ( http://www.isus.jp/wp-content/uploads/compiler_part1-1.jpg ) なんですが、 一番右にある AVX の説明文を見ると 「オペランドを256ビット幅に拡張。幾つかの命令は3のオペランドを持つ」 とあるんですけど、これ、「3オペランド」ですよね。 オペランド方式

Instruction set - Wikipedia, the free encyclopedia
3-operand, allowing better reuse of data:.[3]

    * CISC — It becomes either a single instruction: add a,b,c, or more typically:
      move a,reg1; add reg1,b,c as most machines are limited to two memory operands.

    * RISC — Due to the large number of bits needed to encode three registers, this
      scheme is typically not available in RISC processors using small 16-bit
      instructions; arithmetic instructions use registers only, so explicit 2-operand
      load/store instructions are needed: load a,reg1; load b,reg2; add reg1+reg2->reg3;
      store reg3,c;

日本語版にも同様の記述のものがありますね。

■_ gawk

4.0のパブリックベータってのを試す(3.1.84)。 3.1.76 ではちと引っかかったけど

>make
Enter make  target
 where 'target' is chosen from
  djgpp ... DOS 32-bit exe [GNU C, Delorie, v2]
  emx ..... OS/2 32-bit exe [emx/gcc; uses emxlibc.dll]
  emxnt ... NT exe [emx/gcc with RSXNT]
  emxbnd .. OS/2 and DOS 32-bit exe [emx/gcc]
  mingw32 . Windows32 exe [Mingw32 GNU C]
  -----------------------------------------------------
  test .... Perform tests (see README_d/README.pc)
  install . Install gawk under c:/gnu/

>make mingw32
make  all \
        CC=gcc O=.o CF="-O2 -gdwarf-2 -g3" OBJ=popen.o \
        LNK=LMINGW32 PLNK=PLMINGW32 DLNK=DLMINGW32 \
        LF="-gdwarf-2 -g3" LF2=-lmsvcp60 RSP=
make[1]: Entering directory `/cygdrive/c/Users/moge/work/gawk-3.1.84'
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  array.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  builtin.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  eval.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  field.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  floatcomp.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  gawkmisc.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  io.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  main.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  ext.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  msg.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  node.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  profile.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  re.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  replace.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  version.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  awkgram.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  getid.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  popen.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  getopt.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  getopt1.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  dfa.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  regex.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  random.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  hard-locale.c
gcc -gdwarf-2 -g3 -o gawk.exe array.o builtin.o eval.o field.o floatcomp.o gawkmisc.o io.o main.o ext.o msg.o node.o profile.o re.o replace.o version.o  awkgram.o getid.o popen.o getopt.o getopt1.o dfa.o regex.o random.o hard-locale.o -lmsvcp60
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  eval_p.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  profile_p.c
echo array.o builtin.o eval_p.o field.o floatcomp.o gawkmisc.o io.o main.o > pgawk.rsp
echo ext.o msg.o node.o profile_p.o re.o replace.o version.o  >> pgawk.rsp
echo awkgram.o getid.o popen.o getopt.o getopt1.o dfa.o regex.o random.o hard-locale.o >> pgawk.rsp
gcc -gdwarf-2 -g3 -o pgawk.exe array.o builtin.o eval_p.o field.o floatcomp.o gawkmisc.o io.o main.o ext.o msg.o node.o profile_p.o re.o replace.o version.o  getopt.o getopt1.o dfa.o regex.o random.o hard-locale.o awkgram.o getid.o popen.o -lmsvcp60
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  debug.c
debug.c: In function `restart':
debug.c:2863: warning: passing arg 2 of `execvp' from incompatible pointer type
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  eval_d.c
gcc -c -O2 -gdwarf-2 -g3 -DGAWK -I. -DHAVE_CONFIG_H  command.c
echo array.o builtin.o debug.o eval_d.o field.o floatcomp.o gawkmisc.o io.o main.o > dgawk.rsp
echo ext.o msg.o node.o profile.o re.o replace.o version.o command.o  >> dgawk.rsp
echo awkgram.o getid.o popen.o getopt.o getopt1.o dfa.o regex.o random.o hard-locale.o >> dgawk.rsp
gcc -gdwarf-2 -g3 -o dgawk.exe array.o builtin.o debug.o eval_d.o field.o floatcomp.o gawkmisc.o io.o main.o ext.o msg.o node.o profile.o re.o replace.o version.o command.o  getopt.o getopt1.o dfa.o regex.o random.o hard-locale.o awkgram.o getid.o popen.o -lmsvcp60
make[1]: Leaving directory `/cygdrive/c/Users/moge/work/gawk-3.1.84'

>gawk --ver
GNU Awk 3.1.84
Copyright (C) 1989, 1991-2011 Free Software Foundation.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.

あっけなく完了(まあうまくできたって報告はすでに出てたけど)。

とはいえ、メッセージの日本語化 (元データはあるので表示の問題) やらはどうにかしないとダメだな。 以前の作ったものがほぼほぼそのまま使えると思うけど。

■_ クリームつき

Sttawverry Perl にいろいろなモジュールをあらかじめ入れている物っぽい。

Strawberry Perl with Cream - 5.12.3 v3 released

Strawberry Perl with Cream - 5.12.3 v3 released

Published on 2011.05.29 at 23:01:39 Bookmark and Share

Strawberry Perl is great but for my recent Advanced Perl training class I needed a 
package that included the latest version of Padre, the Perl editor with the oversize 
ego and a number of other modules. Eg. Try::Tiny, Moose and Dancer.

So first I zipped all the files in the c:\Strawberry directory of my own Windows 
machine and posted about it: Padre 0.84 on Strawberry Perl 5.12.3 released. Then, 
based on the response of Curtis Jewell I further improved the package and now, with 
help from Mark Dootson, I managed to build a self installing package that already 
configures itself.

(略)

How to call the kid?

As for naming I am unsure. I started to call it Padre-on-Strawberry when it was mostly 
about making it easy to distribute Padre but now that so many other things are already 
packaged, Padre is just one component. So I started to consider calling it some other 
name. E.g. Strawberry with Cream but I am not sure if that would not cause confusion. 
I certainly don't want to pose as a replacement of Strawberry. In the best case it is 
a derivative of the official Strawberry Perl release.

Anyway. If you have an MS Windows box, please give it a try and let me know what do 
you think.

Last Update: Wed Sep 1 10:52:53 2010
© 2004-2010 Gabor Szabo

Strawberru Perl自体がまだ5.14にはなっていないのだっけ (5.14.0が出たばかりだものなあ)。

■_

2011年06月01日

■_

なんかね、七月の第一月曜日から始業時間が繰り上がるらしいんすよ。 どうしろと。

・近代麻雀
アカギは…w

■_

unicode - Why does modern Perl avoid UTF-8 by default? - Stack Overflow

                 Go Thou  and  Do  Likewise
                 (あなたも行って同じようにしなさい)

edit: simplest R: 7 Discrete  Recommendations

  1. Set your PERL_UNICODE envariable to AS. This makes all Perl scripts decode @ARGV as
     UTF-8 strings, and sets the encoding of all three of stdin, stdout, and stderr to
     UTF-8. Both these are global effects, not lexical ones.

     環境変数 PERL_UNICODE に AS をセットする。これはすべての Perl スクリプトが
     @ARGV を UTF-8 文字列であるかのようにデコードし、さらに stdin、stdout、stderr
     の三つすべてのエンコーディングを UTF-8 に設定する。これらの効果はどちらも
     グローバルなものであり、歴史駆るレキシカルなものではない。

  2. At the top of your source file (program, module, library, dohickey), prominently 
     assert that you are running perl version 5.12 or better via:

     ソースファイル (プログラム、モジュール、ライブラリ、dohickey) の先頭で
     perl version 5.12 以降のものを使用すると宣言する。

     use v5.12; # minimal for unicode string feature

     use v5.14; # optimal for unicode string feature

  3. Enable warnings, since the previous declaration only enables strictures and features,
     not warnings. I also suggest promoting Unicode warnings into exceptions, so use both
     these lines, not just one of them. Note however that under v5.14, the utf8 warning
     class comprises three other subwarnings which can all be separately enabled: 
     nonchar, surrogate, and non_unicode. These you may wish to exert greater control over.

     一つ前の宣言は strictures と features を有効にするが waranings は違うので warnings
     を有効にする。わたしは Unicode warnings を exceptions に promote することも提案する。
     であるから、どちらか片方ではなく両方の宣言を使おう。ただし、v5.14 よりも前の場合
     utf8 warning class  は nonchar, surrogate, non_unicode という
     別々に有効にできる三つの subwarnings を coomprises している。
     These you may wish to exert greater control over.

     use warnings;

     use warnings qw( FATAL utf8 );

  4. Declare that this source unit is encoded as UTF-8. Although once upon a time this pragma
     did other things, it now serves this one singular purpose alone and no other:

     そのソースユニットが UTF-8 でエンコードされていると宣言する。かつてこのプラグマは
     別の意味を持っていたが、現在は単一の用途のみ提供する。。

     use utf8;

  5. Declare that anything that opens a filehandles within this lexical scope but not 
     elsewhere is to assume that that stream is encoded in UTF-8 unless you tell it 
     otherwise. That way you do not affect other module's or other program's code.

     このレキシカルスコープ内にあるファイルハンドルのオープンを、それ以外のエンコードで
     あると指示しない限りはストリームが UTF-8 でエンコードされていると仮定して行うよう
     宣言する。この方法は別のモジュールやほかのプログラムのコードには影響を及ぼさない。

     use open qw( :encoding(UTF-8) :std );

  6. Enable named characters via \N{CHARNAME}.

     \N{CHARNAME} のような named characters を有効にする

     use charnames qw( :full :short );

  7. If you have a DATA handle, you must explicitly set its encoding. If you want this 
     to be UTF-8, then say:

     DATA ハンドルを使っているのなら、そのエンコーディングをはっきりとした形で設定
     しなければならない。もしエンコーディングを UTF-8 にしたいのなら次のように記述する

     binmode(DATA, ":encoding(UTF-8)");

These is of course no end of other matters with which you may eventually find yourself 
concerned with, but these will suffice to approximate the state goal to “make 
everything just work with UTF-8”, albeit for a somewhat weakened sense of those terms.



One other pragma, although it is not Unicode related, is:

Unicode とは関係ないがもう一つ大切なプラグマがあって、それは

     use autodie;

It is strongly recommended.

というものだ。このプラグマの使用を強くお勧めする。


                   N o   M a g i c   B u l l e t
                   魔法の弾丸なんてない

続く

■_

■_ 読んでる

Why Java folks should look forward to Scala | /var/log/mind

Why Java folks should look forward to Scala

There’s an interesting series of blog posts in progress: Why Java folks should stop looking down on C# : Part 1 and Part 2 (at the point of time of writing this post). It offers an interesting and detailed set of contrasts between Java and C#. It is a detailed analysis and makes for very worthwhile reading. What really intrigued me was this comment :

■_

java - help with regex - Stack Overflow

From the string [foo](bar) I want to extract the foo and the bar part:

Pattern p = Pattern.compile("\\[(.*)\\]\\((.*)\\)");
String input = "[foo](bar)";
assert p.matcher(input).matches();
String[] a = ???   // should be initialized to {"foo", "bar"}

What do I write in the fourth line to obtain foo and bar from the input?


I would say a regex like below is easier to handle and extend:

[\[\(](.*?)[\]\)]

いやいやいや、これはだめだろうw

■_

あともうちょいなんだけどねえ>#2


一つ前へ 2011年5月(下旬)
一つ後へ 2011年6月(中旬)

ホームへ


リンクはご自由にどうぞ

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