ときどきの雑記帖 i戦士篇

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

一つ前のページへ 2008年1月(中旬)
一つ後のページへ 2008年2月(上旬)

ホームへ

2008年01月31日

■_ PHPのマニュアルで一言

PHPのオンラインマニュアルは良くできているというのは認めますが、 ひとつ不満があります。

正規表現関連の関数群で、 どのグループ(ereg_*/preg_*/mb_ereg*)がどのようなメタ文字が使えるのかという情報がありません (わたしの探し方が悪いのかもしれないけど、少なくとも関数の説明のところからリンクがないのは 確か)。 また、preg_* がUTF-8の文字列をちゃんとマルチバイトエンコーディング の文字列として処理できるとか(フラグをつける)、mb_ereg*で、 あるマルチバイトエンコーディング(euc-jpとかsjisとか)文字列を 正しく処理させるにはどうすれば良いのかってのが説明不足でわかりづらい。

eregでの文字クラス内のエスケープの取り扱い方がすげー classic (というのはたぶん間違った表現)で、

  [ABC\]\-xyz]

のように文字クラス指定で特別な意味を持つキャラクタをエスケープできないなんて どこにも書いてないぞ(あったらごめん)。

それからあれだ、preg_* に喰わせるパターン文字列はPerlと同じで デリミタ部分は'/'以外の記号類を使うことができる(使えないキャラクタもあるというのも同じ) ということもマニュアルのどこにも書いていないんじゃないのかな?

2/1追記:
やはり探し方が悪かった模様。ご指摘に感謝。 → d.y.d.

んー、確かに関数名で検索して辿っていったのは確かですが、 上のレベルにも行ってるはずなんだけどなあ。

■_ RHG読書会

tmtm日記(2008-01-27)

次回はどれくらいの人数が参加するのかなぁ。当日いきなり指名されても講師ができるように予習を
しておくこと…という参加条件にしようかという話もあったけど (^^; どうなることやら。

うげっ。それはハードル高そうw

まああらかじめどの場所をやるのかわかっているのなら頑張れる…かな (どの部分をやるかにもよるか)?

■_ なんだこれ?

興味の赴くままに PCREのソースなんぞを眺めておりましたらば (なぜそんなことをしていたのかは問わないでおくんなまし :)

intern.h

  OP_CHAR,           /* 21 Match one character, casefully */
  OP_CHARNC,         /* 22 Match one character, caselessly */
  OP_NOT,            /* 23 Match anything but the following char */

なにこの OP_NOTって? コメントから推測するとハゲシク興味を惹かれるものがあるんだけど。

  /* The assertions must come before ONCE and COND */

  OP_ASSERT,         /* 69 Positive lookahead */
  OP_ASSERT_NOT,     /* 70 Negative lookahead */
  OP_ASSERTBACK,     /* 71 Positive lookbehind */
  OP_ASSERTBACK_NOT, /* 72 Negative lookbehind */
  OP_REVERSE,        /* 73 Move pointer back - used in lookbehind assertions */

ふむ。いずれ読んでみよう。 5.xの時代にざっと目を通したことはあるのだけど。

■_

コメント欄。 PHP - odz buffer

shiro 2008/01/31 12:39 

>> 全部安全側に倒しておいて、理解できる人は安全装置解除みたいな設計

これ、バランスが難しいです。使い込んでゆくにつれいちいち安全装置解除するのが煩わしくなって、
つい「一発で全部解除」みたいなものを書いて使いまわすんで安全装置の意味が無くなっちゃう。

Kahua を作った時に、アプリケーションコードは全部sandboxで走るようにして、危険な操作は
プラグインに書かせる (そしてプラグインやGaucheのモジュールのロードは設定ファイルで明示的に
許可されているもののみ許す) としたんですが、ものすごく面倒で、結局邪魔にしかならなかった
ような感じなので。

ふむ。確かに (注意。このコメントの後にもやり取りがあります)。

めも

from reddit

2008年01月30日

■_ reddit

なんか調べてみたらプログラミング関連だけでも結構細かく分かれてるんですな。 とりあえずこの辺を拾ってrssリーダーに登録してみた。

■_ from reddit ネタ: なぜ vim にはまともなLispのサポートがないのか(Why vim lacks good lisp support )

programming: Why vim lacks good lisp support [pic]


Because vim users are too busy being productive to use Lisp.

:-) どうなんでしょうか? > ebanさんとか

■_ Arc

リリースされたそうで。redditにいくつも関連ポストがあるんですけどw しかし、Unicodeサポートがないってだけでこれだけ盛り上がるってのも 不思議といえば不思議。

コメント欄炎上といえば

なんとなく集めてみた

めも

Monkey patch

なんかWikipediaにエントリがあるらしい。 すげーぞWikipedia(笑)

A monkey patch (also spelled monkey-patch, MonkeyPatch) is a way to extend or modify 
runtime code without altering the original source code for dynamic languages (e.g. 
Smalltalk, Javascript, Ruby, Perl, and Python).

モンキーパッチとは動的言語(Smalltalk、JavaScript, Ruby, Perl, Pythonなど)において
ランタイムコードをオリジナルのソースコードを変更することなしに拡張したり変更したり
する手段のことである。

  

以下ネタ元。

[Python-Dev] Monkeypatching idioms -- elegant or ugly?

I ran into the need of monkeypatching a large number of classes (for
what I think are very good reasons :-) and invented two new recipes.
These don't depend on Py3k, and the second one actually works all the
way back to Python 2.2. Neither of these allows monkeypatching
built-in types like list. If you don't know what monkeypatching is,
see seehttp://en.wikipedia.org/wiki/Monkey_patch.

I think it's useful to share these recipes, if only to to establish
whether they have been discovered before, or to decide whether they
are worthy of a place in the standard library. I didn't find any
relevant hits on the ASPN Python cookbook.

First, a decorator to add a single method to an existing class:

def monkeypatch_method(cls):
    def decorator(func):
        setattr(cls, func.__name__, func)
        return func
    return decorator

To use:

from <somewhere> import <someclass>

@monkeypatch_method(<someclass>)
def <newmethod>(self, args):
    return <whatever>

This adds <newmethod> to <someclass>

Second, a "metaclass" to add a number of methods (or other attributes)
to an existing class, using a convenient class notation:

def monkeypatch_class(name, bases, namespace):
    assert len(bases) == 1, "Exactly one base class required"
    base = bases[0]
    for name, value in namespace.iteritems():
        if name != "__metaclass__":
            setattr(base, name, value)
    return base

To use:

from <somewhere> import <someclass>

class <newclass>(<someclass>):
    __metaclass__ = monkeypatch_class
    def <method1>(...): ...
    def <method2>(...): ...
    ...

This adds <method1>, <method2>, etc. to <someclass>, and makes
<newclass> a local alias for <someclass>.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
  

だふのわるだくみ (Duff's Device)

ひょっとしていそぴーとかid:puruhimeさんあたりの若い衆はこれを知らんかな? Duff's Deviceってのは

void
    send(short *to, short *from, int count)
    {
        int n=(count+7)/8;
        switch(count%8){
        case 0: do{ *to = *from++;
        case 7:     *to = *from++;
        case 6:     *to = *from++;
        case 5:     *to = *from++;
        case 4:     *to = *from++;
        case 3:     *to = *from++;
        case 2:     *to = *from++;
        case 1:     *to = *from++;
                }while(--n>0);
        }
    }

こういう switch caseと do whileの複合技。 効率よくメモリ領域の転送をするためのものだけど、 まあコンパイラが賢い昨今はこれも失われた技か喃w。

以下元記事。

research!rsc: On Duff's Device and Coroutines

Tom Duff first described Duff's Device in a November 1983 email to Ron Gomes, Dennis 
Ritchie, and Rob Pike. It spread to a larger group when he revised the note and posted 
it to net.lang.c in May 1984. The 1984 message is the less frequently reproduced but 
is the one in which Duff gave it a name: “I think I'll name it after myself — ‘
Duff's Device’ has a nice ring to it.” Bjarne Stroustroup used a variant as an 
example in The C++ Programming Language. Eventually Duff posted the 1983 message along 
with commentary to Usenet in 1988, in response to a heated debate about the merits of 
Duff's Device as an idiom.

Tom Duff は1983年の11月に、初めてのDuff's Deviceの説明をemailで Ron Gomes, Dennis Ritchie,
Rob Pike に説明を行った。1984年5月に彼が net.lang.c にこれを投稿したとき
この手法は広く知られることとなった。

Bjarne Stroustroupは The C++ Programming Language で使った例の中でこの手法の
バリエーションを使った。


Duff's Device is rarely worth reusing, but in the specific case that it was written 
for, it was an apt tool for the job. The more amazing thing about it is that it's 
valid C. Since a switch statement is just a computed goto and the case labels are just 
labels, switching into the middle of a while is just as legal as goto'ing there.

Duff's Deviceはほとんど再利用する価値もないものであるが、特定のケースにおいて
その仕事を果たすために適用されることがある。信じられないことだが、このコードは
Cとして正しいものなのだ。swtich文は単なる計算型 goto (computed goto)であり、case
ラベルも単なるラベルに過ぎない。そしてdo~whileループの途中に switchすることも
gotoでそこに飛び込むことと変わらないことなので、言語仕様的に違反しているところは
ないのである。
  

時間と財布の中身に余裕があったらこーゆーのを読んでみるといいと思うんだ。
エキスパートCプログラミング―知られざるCの深層 (Ascii books)
エキスパートCプログラミング―知られざるCの深層 (Ascii books)

2008年01月29日

コンピュータプログラミングの概念・技法・モデル
http://pc11.2ch.net/test/read.cgi/tech/1196257692/113


ギレン:「我が忠勇なるソフトウェア工学兵士達よ、今や形式主義者たちの半数が我がソーラレ
イによって宇宙に消えた。 この輝きこそ我等ソフトウェア工学の正義の証である。決定的打撃
を受けた形式主義者たちにいかほどの戦力が残っていようと、それは既に形骸である。 

あえて言おう、カスであると。 

それら軟弱の集団がこのア・バオア・クーをぬくことは出来ないと私は断言する。 人類は我等
選ばれた優良種たるソフトウェア工学者に管理運営されて初めて永久に生き延びることができる。 

これ以上戦い続けては、人類そのものの存亡に関わるのだ。 形式主義者たちの無能なる者ども
に思い知らせ、明日の未来の為に我がソフトウェア工学者は立たねばならんのである。 

ジーク、ジオン!」 
  

■_

preg_match のキャプチャ - odz buffer

<?php
$words = explode(' ', 'abc ab ac');
foreach ($words as $word) {
    preg_match('/\A (a) (b)? (c)? \z/x', $word, $match);
    print_r($match);
}
?>


% php test.php
Array
(
    [0] => abc
    [1] => a
    [2] => b
    [3] => c
)
Array
(
    [0] => ab
    [1] => a
    [2] => b
)
Array
(
    [0] => ac
    [1] => a
    [2] =>
    [3] => c
)
最後のキャプチャがない。null なり空文字なりが入るもんだと思っていたけど、こういうもの?

つーことでちとしらべてみますた。 まずは mb_eregで同じことを(ちょっと正規表現そのものの書き方は違いますが)。

<?php
foreach ($words as $word) {
    mb_ereg('(?x)\A (a) (b)? (c)? \z', $word, $match);
    print_r($match);
}


Array
(
    [0] => abc
    [1] => a
    [2] => b
    [3] => c
)
Array
(
    [0] => ab
    [1] => a
    [2] => b
    [3] =>
)
Array
(
    [0] => ac
    [1] => a
    [2] =>
    [3] => c
)

これはPerlのそれと同じと思われるので(二番目の例で配列要素が3まであり、 三番目の例では2が空)、preg_* のバグっぽいですね。

ということでちょっとソースを。

/* {{{ proto int preg_match(string pattern, string subject [, array subpatterns [, int flags [, int offset]]])
   Perform a Perl-style regular expression match */
PHP_FUNCTION(preg_match)
{
    php_pcre_match(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
}
/* }}} */

まず入り口。

/* {{{ php_pcre_match
 */
static void php_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global)
{

(ry

    /* Execute the regular expression. */
    count = pcre_exec(re, extra, subject, subject_len, start_offset,
              exoptions|g_notempty, offsets, size_offsets);

    /* Check for too many substrings condition. */    
    if (count == 0) {
        zend_error(E_NOTICE, "Matched, but too many substrings");
        count = size_offsets/3;
    }

    /* If something has matched */
    if (count >= 0) {

ここで PCREの関数(pcre_exec)を呼び出す。 今回は関係ないのでcompileの方は省略。 前後しましたがpcre_execのプロトタイプや戻り値の意味は以下の通り。

Returns:      > 0 => success; value is the number of elements filled in
      = 0 => success, but offsets is not big enough
       -1 => failed to match
     < -1 => some kind of unexpected problem
*/

PCRE_DATA_SCOPE int
pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,
  PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,
  int offsetcount)
{

pcre_exec を呼び出した後の判定

    /* If something has matched */
    if (count >= 0) {
        matched++;
        match = subject + offsets[0];

        /* If subpatterns array has been passed, fill it in with values. */
        if (subpats != NULL) {
        /* Try to get the list of substrings and display a warning if failed. */
        if (pcre_get_substring_list(subject, offsets, count, &stringlist) < 0) {
            efree(subpat_names);
            efree(offsets);
            efree(re);
            zend_error(E_WARNING, "Get subpatterns list failed");
            return;
        }

pcre_get_substring_list で実際に捕獲した部分文字列をコピーしてきます。 結果は char** の stringlist に返ってきます。

        if (global) {    /* global pattern matching */
            if (subpats_order == PREG_PATTERN_ORDER) {
            /* For each subpattern, insert it into the appropriate array. */
            for (i = 0; i < count; i++) {
                if (offset_capture) {
                    add_offset_pair(match_sets[i], (char *)stringlist[i],
                        offsets[(i<<1)+1] - offsets[i<<1], offsets[i<<1], NULL);
                } else {
                    add_next_index_stringl(match_sets[i], (char *)stringlist[i],
                        offsets[(i<<1)+1] - offsets[i<<1], 1);
                }
            }
            /*
             * If the number of captured subpatterns on this run is
             * less than the total possible number, pad the result
             * arrays with empty strings.
             */
            if (count < num_subpats) {
                for (; i < num_subpats; i++) {
                add_next_index_string(match_sets[i], "", 1);
                }
            }
            } else {
            /* Allocate the result set array */
            ALLOC_ZVAL(result_set);
            array_init(result_set);
            INIT_PZVAL(result_set);
            
            /* Add all the subpatterns to it */
            for (i = 0; i < count; i++) {
                if (offset_capture) {
                    add_offset_pair(result_set, (char *)stringlist[i],
                        offsets[(i<<1)+1] - offsets[i<<1], offsets[i<<1], subpat_names[i]);
                } else {
                if (subpat_names[i]) {
                    add_assoc_stringl(result_set, subpat_names[i], (char *)stringlist[i],
                               offsets[(i<<1)+1] - offsets[i<<1], 1);
                }
                add_next_index_stringl(result_set, (char *)stringlist[i],
                               offsets[(i<<1)+1] - offsets[i<<1], 1);
                }
            }
            /* And add it to the output array */
            zend_hash_next_index_insert(Z_ARRVAL_P(subpats), &result_set, sizeof(zval *), NULL);
            }

/g な関数でないのでたぶんこちら。

        } else {        /* single pattern matching */
            /* For each subpattern, insert it into the subpatterns array. */
            for (i = 0; i < count; i++) {
            if (offset_capture) {
                add_offset_pair(subpats, (char *)stringlist[i],
                        offsets[(i<<1)+1] - offsets[i<<1],
                        offsets[i<<1], subpat_names[i]);
            } else {
                if (subpat_names[i]) {
                    add_assoc_stringl(subpats, subpat_names[i], (char *)stringlist[i],
                          offsets[(i<<1)+1] - offsets[i<<1], 1);
                }
                add_next_index_stringl(subpats, (char *)stringlist[i],
                           offsets[(i<<1)+1] - offsets[i<<1], 1);
            }
        }
    }

三つの (char *)stringlist[i] のどれかですね。 最後のかなあ? というところで時間切れ。

■_ おおまかにいっちゃうとそれは

Ruby の論理演算子

Ruby のブール演算子には見慣れた &&, ||, ! の他に同じ意味で使用できる and, or, not なるものがある。
違いは優先度だけらしい。(and, or, ! のほうが低い)
また、and と or は優先度が同じだが、&& は || より優先度が高いらしい。
慣れているということもあって普段使う分には &&, ||, ! を使うつもりなので問題ないのだが、
以下のコードを試してみた。

f1 = true
f2 = true
f3 = false
f4 = false
r1 = f1 && f2 || f3 && f4
r2 = f1 and f2 or f3 and f4
puts r1
puts r2

実行してみると、どちらも true と表示された。
あれ?
and と or が優先度が同じということは r2 は false にならないとおかしくないか?
((f1 and f2) or f3) and f4 と同等になるのだと思ったんだが
なので、ためしに

r3 = ((f1 && f2) || f3) && f4
r4 = ((f1 and f2) or f3) and f4
puts r3
puts r4

を追加して実行してみると、r3 は false になり r4 は true になった。
何が起こってるのかさっぱりわからんorz
俺はどこをどう考え違いをしているんだろう?
とりあえず and, or は絶対使わないと心に固く決めた。
# 他にもメソッドの引数に渡すときに、and や or を使ってる場合は do_something((flag1 and flag2)) のように括弧を二重にしなければならないとかめんどくさいし。

and と &&、or と || との間の大きな違いはざっくりいうと expr1 && (||でも状況は一緒)の結果は なのに対して、 expr1 and expr2の結果は というところにあります。ですから、疑問に感じているr2を例にとると

r2 = f1and f2 or f3 and f4

r2 = f1 という文、f2、f3、f4という式文をand/orという演算子で繋いだものという解釈がされるので r2 に代入されるているのはf1の値だけです。 また、メソッドの引数に使えるのは式であって文ではないので and/or で繋いだ文を置くとエラーになるというわけです。 余計なカッコで括ることでエラーが解消されるのは、 その余計なカッコにより文が式になったからです。

今更ながら注意: 上記の文章で使った「式」だの「文」だの「式文」だのは 俺様用語であり、Ruby的に正しい(そういう文法定義になっている)かどうかは別の問題ですのであしからず。

■_ Attacking PHP

火種の元w 短いのでちょっと訳してみる。

Mindblind - making web development suck less » Attacking PHP

Attacking PHP
PHPを糾弾する

I am so tired of people defending PHP.
PHPを守ろうとする人たち(=信者とでもする?)にほとほと疲れました。


Note: this is good natured. The guy that wrote the original article - why can I never 
find names on these things? - makes a few good points. And, for full disclosure, I 
work with PHP full-time right now, and it’s still my go-to language for knocking out 
a web application because I’m so familiar with it. (And even then, only with Zend 
Framework and phpSprockets.)

#元の指摘をしていたのが良くできていたということ?> this is good natured
# these things って?
“why can I never find names on these things”という
元のアーティクルを書いた彼はいいところをついていたと思います。



But seriously, PHP is sickening. I’ve started using Ruby and Python for any tasks I 
can get away with and they’re really worlds apart. PHP’s got some good in it but it’
s all buried under deep layers of hate. That’s right, PHP hates you. PHP is terrible

率直に言って、PHPはむかつくような代物です(sikening)。
わたしはRubyやPythonですべての仕事を片付けるようになって、PHPからはおさらばすることが
できました。PHPはいくつかの良い点もありましたが、
短所は深い階層に隠されていただけだったのです。
PHPはあなたを嫌っています(PHP hates you)。
PHPは恐ろしいもの(酷いもの、のほうが良い?)です。


Need proof? Here it is, broken down by category:
根拠を出せ? よろしい。カテゴリ別に説明しましょう。


Language Features
言語仕様の部

    * So many things evaluate to boolean false or boolean true that there had to be a 
      new operator introduced (=== and !==) to do strict comparisons.
      厳密な比較を行うために boolean trueか boolean falseのいずれであるかを
      評価する新しい演算子(=== と !==)を導入しました。

    * You can’t differentiate between a hash or a list or anything. They’re all the 
      same. Even if you know you’ll never need a keyed index, you can’t turn it off.
      ハッシュとリストなど(たぶん、配列とかそういうデータ構造という意味)を区別することが
      できません。なぜならそれらは
      実際には同じものだからです。あなたがキーによる添え字付けを決してすることがない
      ということがわかっていたとしてもその機能を無効にすることができません。

   * It's Object Orientation is broken in places (late static binding).
      サポートしているオブジェクト指向はぶっ壊れている代物(late static binding)

    * It doesn't support lambas. create_function() is not a lambda.
      lambda をサポートしていません。create_function()が返すのは lambdaではありません。

    * You never know if short_open_tags is on, or if safe_mode is on, or if (ugh) 
      register_globals is on.
      short_open_tags がオンであるかどうかとか、safe_mode がオンであるかどうか、
      あるいは(あのひどい)register_globalがオンかどうかを
      知るすべがありません。

2008/2/1 追記:
知ることができないこともないそうです
  → あーありがち - まずダメなところを認めることから始まる

Built-in Functionalty
組み込み関数の部

    * It comes with a standard library that has no naming convention. You never know 
      in what order the words will come in or if they’re separated by underscores or not:
      標準ライブラリには命名規則といったものが存在しない。
      アンダースコアで分けられたりしている場合もある単語がどのような順番で関数名を
      組み立てているのかを理解することができません:
          o str_replace()  #string + replace アンダースコアあり
          o strlen()       #string + lenght アンダースコアなし
          o parse_str()    #parse + string (動詞が先にきている)

    * You never know what order the arguments are in:
      関数の引数の順番がどんなものかを決して覚えていられないでしょう
          o in_array($needle, $haystack)
          o strpos($haystack, $needle)  #この二つでorder が逆
          o You constantly have to check your output thanks to type restrictions:
            ありがたくも型を制約するために出力を常にチェックする必要があります:
          o strpos('abcd', 'a') will return 0. Don't test this with
            strpos('abcd', 'a') は0を返します。次のような検査をしてはいけません
           if (strpos('abcd', 'a')) { … }
            because 0 is secretly false!
            これは関数の戻り値 0 が false だからダメです
            You've got to use
            このようにしなければなりません
           if (strpos('abcd', 'a') !== false).

Common use

A lot of open source projects are written in it, such as Joomla, Wordpress, and 
MediaWiki. All of their code is hideous, and half of the time there’s random HTML in 
the middle of their scripts because, of course, we’re working with webpages and why 
would you ever want to abstract the output from the logic? 


たくさんのオープンソースプロジェクトがPHPを使って書かれている。たとえば
Joomla、Wordpress、MediaWikiなど。これらのコードは全てぞっとするような代物で、
スクリプトの中にぐちゃぐちゃなHTML(random HTML)があります。
もちろんそれは、わたしたちがwebページを作るために作業しているためです。
あなたはこれまでにロジックから出力を抽象的なものにしたいとおもったことはありませんか?

Irrelevant praise
見当違いな賞賛

Here are some common praises of PHP and why they don’t matter:
以下にいくつかのPHPに対する褒め言葉と、それが実は意味のないものであるかという理由を挙げる。

PHP is great because it allows the new user to pick it up quickly!
PHPは偉大だ。なぜなら、PHPは新しいユーザーが即座につかうことができるから!

Sure. And if the introductory material available covered good programming style we 
might not have a problem. In reality, every example PHP script is riddled with SQL 
Injection vulnerabilities, XSS vulnerabilities, and terrible programming. Most newbs 
never learn a better way of doing things because this gets them results that look good 
very quickly.

確かに。
ただし、わたしたちが問題を抱えないですむかもしれないような良いプログラミングスタイルを
利用できるようにしていてくれていたら。
実際には例に挙げられているPHPスクリプトは、SQLインジェクションや XSS脆弱性、
あるいはそのほかの防御的プログラミングのためにわかりづらいものになっている。
大部分の入門者はそういったことをもっと上手にやる方法を学ぶことは決してない。
なぜならそんなことをしないでも結果を得ることはできるのだから。

PHP has classes, it doesn’t need namespaces.
PHPには名前空間を必要としていないクラスがある。


Fail. Use a language with namespaces for a few months and come back to PHP. I did. It's 
sickening.

間違い。名前空間を持っている言語を数ヶ月使って、その後でPHPに戻ってみればいい。
わたしは実際にそれをやった。むかつくこと請け合いだ。

Globals are okay!
いいじゃんGlobals!

Whoever taught you that needs to be shot. Globals are not okay. They are tolerable in 
certain situations, but if you make blanket statements like “Globals pierce through 
all the layers of code and get right to the heart of the matter.” then you’re 
clearly using them too much.

自爆したい人はみんなそう考えるんだよね。Globalはよくない。
我慢できる状況もあるだろうけど、
“Globals pierce through all the layers of code and get right to the heart of the matter.”
のような blanket statementを作ってしまうとそれに頼り切ってしまうんだ。
Defending PHP - Jimbojw.com

Defending PHP
From Jimbojw.com
Jump to: navigation, search

Ugh. I am so tired of defending PHP - even from people I know and respect and who use 
it every day. So here I'm going to make my last stand. In all future arguments I get 
into, I will point back to this article as my sole defense.

Before you read further, you have to understand that "the curve is a circle", and 
those who appear to be beneath you may in fact be your superiors in a given field of 
expertise. Never forget this. PHP is awesome

ここから先に読み進めていく前に、"the curve is a circle"を理解しておく必要があります。

また、あなたを抑圧するために現れる人?(who appear to be beneath you)が
given field で

このことを決して忘れないでください。
PHPサイコー。



Need proof? Here it is, broken down by category:

Language Features

    * It's dynamically typed.
      動的な型付けがされます。
    * All arrays are associative (hashes)
      すべての配列は連想的なもの(ハッシュ)です。
    * It's object oriented with a reflection API.
      リフレクションAPIを使ったオブジェクト指向な言語です。
    * It uses different operators for numeric addition (+) and string concatenation (.)
      数値の加算と文字列の連結とで別々の演算子を使います。
    * It supports eval() and lambdas (somewhat)
      eval()とlambda(ぽいもの)をサポートしています。
    * Can execute system commands and read from local and remote files (all one-liners)
      システムコマンドを実行できますし、ローカルなファイルでもリモートのファイルでも
      読み込むことが(すべての一行野郎で?)できます。
    * Supports coercing scalars into boolean decisions (means you can just do if($x) 
      instead of if($x!=null && $x!=0 && $x!=false ... )
      スカラー値のbooleanへの coercing(変換)をサポートしています
      (つまり、if ($x!=null && $x!=0 && $x!=false ...) と書くのではなく
      すっきり if ($x)と書くことができます)
    * Usable in both web and command-line contexts 
      Web用にもコマンドライン上でのツールとしても使えます

Built-in Functionality
組み込み関数

    * It comes with a vast array of built-in functions to do all sorts of common tasks. 
      Here are a few off the top of my head:
      一般的なタスクすべてをこなすための組み込み関数があります。
      ちょっと考え付いただけでも
          o Base 64 encoding and decoding
            base64エンコーディングとデコーディング
          o URL encoding and decoding
            URLエンコーディングとデコーディング
          o HTML character encoding, decoding and tag stripping
            HTMLキャラクタエンコーディングとデコーディング、タグの取り除き
          o SAX style XML parsing
            SAX形式のXML解析
          o REGULAR EXPRESSIONS
            正規表現(なぜ大文字で強調?)
          o Array sorting, custom sorting
            配列のソート。
          o md5 and sha1 hashing
            md5やsha1を使ったハッシュ
    * It can natively connect to the most popular Database engines around.
      ほとんどのポピュラーなデータベースエンジンに対してnatively な接続ができます
    * It comes prepackaged with graphics manipulation capabilities (GD)
      グラフィックを扱うための能力(GD)が備え付けでついています

Community

    * It has an active community open to new ideas and ready to help noobs and experts 
      alike:
      新しいアイデアに対して開かれていて、新人やエキスパートをいつでも助けてくれるような
      活動的なコミュニティがあります:
          o mailing lists
          o IRC Channel: irc://irc.freenode.net/php 

    * Some of the most popular open-source projects in the world are written in it 
      including:
      非常にポピュラーなオープンソースプロジェクトがPHPで書かれています。
          o MediaWiki (which powers Wikipedia)
          o phpBB
          o WordPress
          o Joomla! (formerly known as Mambo) 

Irrelevant complaints
根拠レスな非難

Now, here are some common complaints about PHP, and why the don't matter:

I don't like PHP because it's not statically typed (like my beloved Java)

静的な型付けをする言語だからPHPは好きじゃない

News flash: static typing sucks - deal.

PHP doesn't have namespaces, so there can be naming collisions.

Oh noes! Seriously, this is a theoretical objection, not a practical problem. Use a 
class dude - makes for a nice way to wrap your functions.

I hate globals

Globals can save your life. Globals pierce through all the layers of code and get 
right to the heart of the matter. You say you don't like globals, so try to remember 
that the next time you grab a singleton from your static factory.

PHP allows/promotes poor programming practices

I call shenanigans on that one. PHP appeals to a broad audience, especially new coders, 
because it is ubiquitous. It's just as easy to write poor code in any other language 
(an Interface with exactly one Implementation anyone?)

In summary - I'm really tired of having to defend PHP. I feel like I'm the only one 
here. Even the developers I know that use it on a daily basis speak ill of it. 
Whatever.

There are plenty of reasons we all keep finding ourselves drinking from the PHP 
watering hole. If you don't like the taste, you're welcome to leave at any time. 

■_ なにいッ

イー・モバイル、EM・ONEのOS有償アップグレードを3月で終了

イー・モバイルは、同社のモバイル端末「EM・ONE」のOS有償アップグレードを3月で終了すると
発表した。

 EM・ONEは、Windows Mobile 5をOSに採用したモバイル端末。イー・モバイルでは本体スペッ
クは同等でOSをWindows Mobile 6に変更した「EM・ONE α」を10月5日より発売しており、EM・
ONEについては販売を終了していた。

 既存のEM・ONEユーザーに対しては、配送料を含め9,980円でEM・ONEをEM・ONE α相当に有償ア
ップグレードできるサービスを10月5日より実施していたが、3月10日必着分を持ってこのアップ
グレードサービスを終了。窓口での申し込みは3月5日までとなる。

むー、どうしたもんか喃。

めも

from reddit

え゛?

ファイルに書き込む時の負荷について -OKWave

その辺の処理を深く知るためにはCを学ぶと良いです。
phpもCで書かれて居ますから。


質問者様が上げたロジックはおそらく教本に載っていたものだと思いますが。
その二つのコードの違いは「メモリの使いかた」です。

$bufに追記しファイルを出力する方法だと
→$bufに溜め込む
 →ファイル出力用にメモリを確保
  →$bufをメモリへコピー
   →fclose()でファイルへ書き込み
となります。

frite()直書きだと
→ファイル出力用にメモリを確保
 →ループ
 →出力するデータをメモリに書き込み
 ←ループ
  →fclose()でファイルへ書き込み
となります。

どちらが良いかといえば。
「ケースバイケース」、または「文字列連結の方は駄目」です。

上で書きましたが、ファイルはfclose()が呼ばれた瞬間に物理的な書き込みを行います。

fopen()したあとにflose()をするまでの時間が開けば開くほど書き込むデータの競合が発生しや
すくなります。それを避けるために、fopen()を呼ぶ前にあらかじめ吐き出すデータをメモリに
用意しておき、書くときは一気に書くとしたほうが安全です。ゆえ、よく教本に載っている
fopen()とfclose()の間に文字列連結などのロジックを行うコードは悪質であるといえます。

上のロジックは以下のようにしたほうが良いでしょう。

$buf = "";
for ($i = 1; $i <= 3; $i++) {
 $buf .= "aaa$i\n";
}
$fp = fopen("data.txt", "w");
fwrite($fp, $buf);
fclose($fp);

上記のように書くのであれば、あとは環境と相談してどう書くか決めると良いでしょう。

ファイルはfclose()が呼ばれた瞬間に物理的な書き込みを行います ってどこのなんてOSとライブラリだよ、それw いくらfwriteしてもバッファに溜め込むだけって? それと、変数の内容を連結することによるメモリ領域の再確保とかはぜんぜん問題にならないと 思ってらっしゃるわけか、この専門家様は。 いやー参りましたw

2008年01月28日

■_ ふと思ったこと

/lang/scala/sandbox/src/jp/ne/cappuccino/keisuken/scl/util/regex/Regex.scala - CodeRepos::Share - Trac

Perl 6ではまたちょっと変わるみたいだけど、 クォートの記号('', "", ``)を一般化した演算子 (という扱いでいいんだっけ? q{}, qq{}, qx{}, qr{})を発明し実装したLarry Wallってのは偉大だなあと。 記号そのものの種類は限られているし、 あるものはすでにプログラミング言語の中で意味のあるものとして使われているのがほとんど。 そういったところに、先行した記号(演算子)の後ろにある記号をその場でのクォート記号と見なすとか、 カッコの類は同じ記号ではなく対応する記号([ と ] とか)を使えるようにするとか。 まあ全部が全部Larry一人のアイデアではないと思うけど。 応用形(?)としては、C#の @"" とか Pythonの r'' みたいのもありますね (Rubyの %Qとかもあるか)。

Pythonでも正規表現のリテラル欲しいとか、 ○○(言語)で××のリテラル欲しいとかいう意見や要望を 見かけるけど、'{' みたいにひとつの記号で文脈によって使い分けるよりはこういった prefixを使うのを考えても良いんじゃないかなあと。 もっとも、あまり長いprefixは使う気になれないだろうし、q + 一文字 なんかだと高々26文字(52文字)。 どうしたもんかいねえ。

■_ ××で○○

しょの1。

programming: Wiki engine written entirely in bash (seriously)

http://sdt.servers.csail.mit.edu/BashCGI


I have a feeling abuse is going to happen. The page is actually editable.

えーい、正気かこいつらw

しょの2。

わーい \(^o^)/ PL/0を JS で書いたよー! - ockeghem(徳丸浩)の日記

最近、JavaScriptで小さな処理系を書くのが流行っているらしい。

45歳を過ぎた私もやってみたいと思い、昔とった杵柄で、PL/0の処理系をJavaScriptで書いてみた。

JavaScirptの魔手がここにもっw

■_ PHPのeregを読む(だんだんタイトルが変わってる様な気がするけどいいや、もう(笑)

なんか以前見たことのある Henry Spencer のregexと微妙に違ってるような気がする…

smatcher で使用するバージョン
/* some abbreviations; note that some of these know variable names! */
/* do "if I'm here, I can also be there" etc without branches */
#define	FWD(dst, src, n)	((dst) |= ((unsigned)(src)&(here)) << (n))
#define	BACK(dst, src, n)	((dst) |= ((unsigned)(src)&(here)) >> (n))
#define	ISSETBACK(v, n)	((v) & ((unsigned)here >> (n)))


lmatcherで使用するバージョン
/* some abbreviations; note that some of these know variable names! */
/* do "if I'm here, I can also be there" etc without branches */
#define	FWD(dst, src, n)	((dst)[here+(n)] |= (src)[here])
#define	BACK(dst, src, n)	((dst)[here-(n)] |= (src)[here])
#define	ISSETBACK(v, n)	((v)[here - (n)])

FWDとかってこんなつくりだったかなあ? と思ってむかーしの Henry Spencer作のライブラリを見てみるが、 古すぎてこれはこれでまた違うつくりだったw (Perlのそれのベースになったものなのでそこかしこに遺伝的な特徴が :-)

■_ Perl 6

use Perl | Perl 6 Design Minutes for 23 January 2008

The Perl 6 design team met by phone on 23 January 2008. Larry, Allison, Patrick, Jerry, 
Will, Jesse, Nicholas, and chromatic attended.

Larry:

    * just fudging things
(ry
    * going to Japan in May for YAPC::Asia

Allison:

    * when?

Jesse:

    * the 15th through 17th


(ry

Jerry:

    * working to switch the name "Perl 6" to "Rakudo" in the source and documentation
    * made fudge work with Rakudo and am adding directives
    * there's a lot more work to do there
    * added more tests to Rakudo's spectest make target
    * it's a lot noisier
    * but it will hopefully inspire us to clean that up
    * applied a bunch of patches from various contributors
    * we've had three or four contributors over the past week, which is great to see
    * working on some Perl 6 rule syntax for PGE
    * also working on a grammar for serialized PAST
    * should let us read PAST in from the same or different implementations
    * finally trying to get more Rakudo tests passing


Nicholas:

    * how's Damian doing?

Patrick:

    * I've been communicating with him
    * I get the impression he's busy, but he's around some


この発言から見ると今年はLarry来るのかな?

■_ from reddit

The Most Essential Development Problem

Paul W. Homer has a post up discussing essential development problems. While this is a 
huge subject (somewhat reflected by the size Paul’s article,) I’d like to emphasise 
one of the things he touches: the lack of understanding the users’ problem domain.

    The biggest problem in most systems today is the total failure of the programmers 
    to have any empathy for their users.

I too have a similar perception, and I have many times been guilty as charged, 
although I’ve come to realize that I’d better take the Customer View if I want to 
succeed. Still, I fail from time to time in the analysis of the users’ situation. I 
don’t know why this keeps happening, but I think impatience and a strong wish to “
get going” is partly to blame.

興味深そうだがゆっくり読んでる暇がNEEE

それはぼくらが十数年前に通ってきた道だ(たぶん)

diff -y + UTF-8 = irregular columns
Hello.

While in an UTF-8 enviroment, comparing one or two UTF-8 files the
column widths seem to be miscalculated. It seems as if each byte of
multi-byte characters are counted as separate characters, giving a
slight skew on lines with such characters.

Steps to reproduce:
 1. diff -y test test2

Where test and test2 are attached files. test is UTF-8 and test2 not,
although the problem appears when both files are in UTF-8 as well.
  
Re: diff -y + UTF-8 = irregular columns


+ static size_t
+ PRINT_HALF_LINE (char const *const *line, size_t indent, size_t out_bound)
+ {
+   FILE *out = outfile;
+   register size_t in_position = 0;
+   register size_t out_position = 0;
+   char const *text_start = line[0];
+   char const *text_limit = line[1];
+   MBI_ITERATOR_T text_pointer;
+ 
+   for (MBI_INIT (text_pointer, text_start, text_limit - text_start);
+        MBI_AVAIL (text_pointer, text_limit);
+        MBI_ADVANCE (text_pointer))
+     {
+       if (MB_ISEQ (MBI_CUR (text_pointer), '\t'))
+       {
+         size_t spaces = tabsize - in_position % tabsize;

(ry

+ #define PRINT_HALF_LINE print_half_line_unibyte
+ #define MBI_ITERATOR_T const char *
+ #define MBI_INIT(iter,startptr,length) (void)(iter = (startptr))
+ #define MBI_AVAIL(iter,endptr) (iter) < (endptr)
+ #define MBI_ADVANCE(iter) (void)(iter)++
+ #define MBI_CUR(iter) (iter)
+ #define MB_ISEQ(mbc,sc) (*(mbc) == (sc))
+ #define MB_PTR(mbc) (mbc)
+ #define MB_LEN(mbc) 1
+ #define MB_WIDTH(mbc) (iscntrl ((unsigned char) *(mbc)) ? 0 : 1)
+ #include "side-half.h"
+ #undef MB_WIDTH
+ #undef MB_LEN
+ #undef MB_PTR
+ #undef MB_ISEQ
+ #undef MBI_CUR
+ #undef MBI_ADVANCE
+ #undef MBI_AVAIL
+ #undef MBI_INIT
+ #undef MBI_ITERATOR_T
+ #undef PRINT_HALF_LINE
+ 
+ #if HAVE_MBRTOWC
+ # include "mbchar.h"
+ # include "mbiter.h"
+ # define PRINT_HALF_LINE print_half_line_multibyte
+ # define MBI_ITERATOR_T mbi_iterator_t
+ # define MBI_INIT(iter,startptr,length) mbi_init (iter, startptr, length)
+ # define MBI_AVAIL(iter,endptr) mbi_avail (iter)
+ # define MBI_ADVANCE(iter) mbi_advance (iter)
+ # define MBI_CUR(iter) mbi_cur (iter)
+ # define MB_ISEQ(mbc,sc) mb_iseq (mbc, sc)
+ # define MB_PTR(mbc) mb_ptr (mbc)
+ # define MB_LEN(mbc) mb_len (mbc)
+ # define MB_WIDTH(mbc) mb_width (mbc)
+ # include "side-half.h"
+ # undef MB_WIDTH
+ # undef MB_LEN
+ # undef MB_PTR
+ # undef MB_ISEQ
+ # undef MBI_CUR
+ # undef MBI_ADVANCE
+ # undef MBI_AVAIL
+ # undef MBI_INIT
+ # undef MBI_ITERATOR_T
+ # undef PRINT_HALF_LINE
+ #endif
+ 

わかりやすいやり方ではあるんだろうけど、ちまちまちまちま一文字ずつ 片付けてくって効率落としてないかなあ? まーた、「俺の使ってるlocaleだと処理速度がた落ちだゴルァ」 とかレポートでそうな気がする。

Re: diff -y + UTF-8 = irregular columns


Thanks for fixing this bug. However, I don't see a test of HAVE_MBRTOWC.
According to gnulib/doc/posix-functions/mbrtowc.texi, the function
mbrtowc() is not available on
  HP-UX 11, IRIX 6.5, Solaris 2.6, mingw, Interix 3.5,
and gnulib provides no replacement. You may want to use the same
substitutes as in gnulib/lib/quotearg.c (which is known to work on all
platforms).

え゛。HP-UXってそんな代物だったの? ひねたOSだとは聞いていたが…

from reddit

めも

  • CSSレイアウト時のよくやる失敗と対処法|WEB制作(html,css(スタイルシート) )|プログラムメモ
  • だいじょうぶかとくしまだいがく

    
    http://mixi.jp/view_bbs.pl?id=27461396&comment_count=0&comm_id=602606
    http://mixi.jp/view_bbs.pl?id=27465564&comment_count=1&comm_id=602606
    
    ハッシュ(オープンアドレス法) C言語の課題 -OKWave
    
    努力はしてみたのですが、C言語の課題ができません。教えていただけないでしょうか。
    
    (ry
    
    内容を理解できないと困るので簡単なプログラムをお願いします。
    よろしくお願いします。
    

    探せば他の掲示板にも出てそうだなw

    2008年01月27日

    RHG 読書会

    何のかんので5:00amまでラジオ聴いてたw 寝坊するかと思ったが何とか回避。 しかし、営団東京メトロの新橋駅に12時ちょいすぎに到着していたのに、 会場であるミラクルリナックス社の入っているビルにたどり着いたのが12:30前後というのは なんという方向音痴w

    まあまとめ記事とかは他の人に任せるとして、 ミラクルリナックス会場で質問してたり発言してたのが 年かさの人ばかりというのはどうよ。 来てたのならいそぴーとかもっと積極的に発言せいw

    東大会場の方の質問してた人はどんなかんじだったんだろう?

    Yuguiさん、よしおかさん、ささださんはじめ読書会を開くのに尽力された方々に改めて感謝。

    む?(lvalue

    http://d.hatena.ne.jp/puruhime/20080127#1201439601
    ちゅるやさんが左辺値について学ぶようです 22:13 CommentsAdd Star
    
    
              , -‐ '´ ̄ ̄`ヽ、
             /:::::/" `ヽ ヽ:::::::\
            /:::::::::/     ヽ ヽ:::::::::ヽ
            l:::::::{:::l ,    ー-j从:ヽ::::.ヽ
            | ::i::ル{レ'     ●` li!:: ト、:::.',
            /⌒)i"●      l|:: ||ノ:::.l
          /   yi ヘ⊃   ,_,⊂⊃l|:: |:::::::::.l ・・・にょろ?
          (  /ス、,ゝ、_ `´   ィ<|:: |_:::::::.l   結局伊達?
           '</ |l:::: i "Tーイ'^ァレ'l_::::::.l
            \,,t|l:::: l'ヾ::|三/:://l/ ヽ、'i
             |::|l:::: l ヾ∨:::/ ヒ::::彡, | :ji
    
    なんていうか、不勉強すぎて駄目だ俺\(^o^)/
    

    不精こいて調べなかったのだけど確かに他のコンパイラでもそうなりますねえ。 確かに自分でクラス定義したものに対する++/--の後置演算子版を実装するときを考えると operator++(int) が返すのはインクリメント操作を行う前の状態なので、 参照を返すようには実装しないですよね。

    で、こんなのを発見。 規格書が検索しやすいといいのだけどねえ。

    Decrement --
    
    For example:
    
    play = --play1 + play2--;
    
    is similar to the following expressions; play2 is altered before play:
    
    int temp, temp1, temp2;
     
    temp1 = play1 - 1;
    temp2 = play2;
    play1 = temp1;
    temp = temp1 + temp2;
    play2 = play2 - 1;
    play = temp;
    
    The result has the same type as the operand after integral promotion, but is not an lvalue. 
    #結果は演算子を適用する前(ただしintegral promotionのあと)のオペランドの型と同じであるが
    #演算子適用後は(適用前のオペランドにはあった)lvalueが失われる。
      

    スモークチーズあげるのでゆるしてくだちい >ちゅるやさん

    で、前置演算子を適用した結果も lvalueを持てるようにしたわけは lvalue - odz buffer で odzさんが推察しているように

    ふむ。参照の導入だとか演算子オーバーロードとの関連もありそうな。
    

    すべては参照の導入から始まったんじゃないかなあと思いました。 いやまあデザイン的にどちらが先行してたのかは知らんのですが、 オーバーロードの方は初期には overload 宣言とかが必要だった様に 記憶しているので、参照が優先かなあと。

    D&Eをぱらぱらと探してみたら、どうも演算子オーバーロードのために 参照を導入したのではないかと読める部分あり。

    それは「Python」と呼べるのだろうか?

    茶々入れのようで申し訳ないのですが

    minipython - 西尾泰和のはてなダイアリー
    
    ■minipythonCommentsAdd Star
    
    id:hayamizにはぜひminipythonに「代入演算子」を入れて欲しい。代入が式になるやつ。
    
    きのうの晩それでだいぶもめたw
    

    そういった仕様が便利に使える場面が多いことは認めますが、 その拡張を施した言語は(サブセット+αということはとりあえず忘れて) Pythonと云えるのでしょうか? よく似た何かではないのではないかという気がします。 自分としてはプログラミング言語としての identity に関わってくる要素じゃないかと思うのですがどうでしょう。

    リリカルLispのパッケージと冊子持って行ったらサインしてくれるかなあ?w

    やる夫がgauche.nightの第1部座談会に出演するそうです (リリカル☆Lisp 開発日記)

          ____
         /⌒  ⌒\
       /( ●)  (●)\    はい、参加したいお!何をするか教えて欲しいお!
      /::::::⌒(__人__)⌒::::: \   (本来1500円のチケットがタダってのは魅力的だお!)
      |     |r┬-|     |
      \      `ー'´     /
    
      

    やる夫、交通費も出してもらえるんだよね?w

    from reddit

    ちょっとだけ eregのソース読み

    正規表現関数で使用する構造体とか。

    /*
     * The internal representation is a *strip*, a sequence of
     * operators ending with an endmarker.
    
    (ry
    
     * - OPLUS_ and O_PLUS are *inside* the loop they create.
     * - OQUEST_ and O_QUEST are *outside* the bypass they create.
     * - OCH_ and O_CH are *outside* the multi-way branch they create, while
     *   OOR1 and OOR2 are respectively the end and the beginning of one of
     *   the branches.  Note that there is an implicit OOR2 following OCH_
     *   and an implicit OOR1 preceding O_CH.
     *
     * In state representations, an operator's bit is on to signify a state
     * immediately *preceding* "execution" of that operator.
     */
    typedef long sop;		/* strip operator */
    typedef long sopno;
    #define	OPRMASK	0x7c000000
    #define	OPDMASK	0x03ffffff
    #define	OPSHIFT	(26)
    #define	OP(n)	((n)&OPRMASK)
    #define	OPND(n)	((n)&OPDMASK)
    #define	SOP(op, opnd)	((op)|(opnd))
    /* operators			   meaning	operand			*/
    /*						(back, fwd are offsets)	*/
    #define	OEND	(1<<OPSHIFT)	/* endmarker	-			*/
    #define	OCHAR	(2<<OPSHIFT)	/* character	unsigned char		*/
    #define	OBOL	(3<<OPSHIFT)	/* left anchor	-			*/
    #define	OEOL	(4<<OPSHIFT)	/* right anchor	-			*/
    #define	OANY	(5<<OPSHIFT)	/* .		-			*/
    #define	OANYOF	(6<<OPSHIFT)	/* [...]	set number		*/
    #define	OBACK_	(7<<OPSHIFT)	/* begin \d	paren number		*/
    #define	O_BACK	(8<<OPSHIFT)	/* end \d	paren number		*/
    #define	OPLUS_	(9<<OPSHIFT)	/* + prefix	fwd to suffix		*/
    #define	O_PLUS	(10<<OPSHIFT)	/* + suffix	back to prefix		*/
    #define	OQUEST_	(11<<OPSHIFT)	/* ? prefix	fwd to suffix		*/
    #define	O_QUEST	(12<<OPSHIFT)	/* ? suffix	back to prefix		*/
    #define	OLPAREN	(13<<OPSHIFT)	/* (		fwd to )		*/
    #define	ORPAREN	(14<<OPSHIFT)	/* )		back to (		*/
    #define	OCH_	(15<<OPSHIFT)	/* begin choice	fwd to OOR2		*/
    #define	OOR1	(16<<OPSHIFT)	/* | pt. 1	back to OOR1 or OCH_	*/
    #define	OOR2	(17<<OPSHIFT)	/* | pt. 2	fwd to OOR2 or O_CH	*/
    #define	O_CH	(18<<OPSHIFT)	/* end choice	back to OOR1		*/
    #define	OBOW	(19<<OPSHIFT)	/* begin word	-			*/
    #define	OEOW	(20<<OPSHIFT)	/* end word	-			*/
    

    内部コードでのオペコードの定義ですね。 シーケンシャルな番号じゃないんだ。

    /*
     * Structure for [] character-set representation.  Character sets are
     * done as bit vectors, grouped 8 to a byte vector for compactness.
     * The individual set therefore has both a pointer to the byte vector
     * and a mask to pick out the relevant bit of each byte.  A hash code
     * simplifies testing whether two sets could be identical.
    
    (ry
    
    typedef struct {
    	uch *ptr;		/* -> uch [csetsize] */
    	uch mask;		/* bit within array */
    	uch hash;		/* hash code */
    	size_t smultis;
    	unsigned char *multis;		/* -> char[smulti]  ab\0cd\0ef\0\0 */
    } cset;
    
    

    キャラクタクラスの実装で使用。 ASCIIの世界に限定できれば簡単なんですけどねえ。

    /*
     * main compiled-expression structure
     */
    struct re_guts {
    	int magic;
    #		define	MAGIC2	((('R'^0200)<<8)|'E')
    	sop *strip;		/* malloced area for strip */
    	int csetsize;		/* number of bits in a cset vector */
    	int ncsets;		/* number of csets in use */
    	cset *sets;		/* -> cset [ncsets] */
    	uch *setbits;		/* -> uch[csetsize][ncsets/CHAR_BIT] */
    	int cflags;		/* copy of regcomp() cflags argument */
    	sopno nstates;		/* = number of sops */
    	sopno firststate;	/* the initial OEND (normally 0) */
    	sopno laststate;	/* the final OEND */
    	int iflags;		/* internal flags */
    #		define	USEBOL	01	/* used ^ */
    #		define	USEEOL	02	/* used $ */
    #		define	BAD	04	/* something wrong */
    	int nbol;		/* number of ^ used */
    	int neol;		/* number of $ used */
    	int ncategories;	/* how many character categories */
    	cat_t *categories;	/* ->catspace[-UCHAR_MIN] */
    	unsigned char *must;		/* match must contain this string */
    	int mlen;		/* length of must */
    	size_t nsub;		/* copy of re_nsub */
    	int backrefs;		/* does it use back references? */
    	sopno nplus;		/* how deep does it nest +s? */
    	/* catspace must be last */
    	cat_t catspace[1];	/* actually [NC] */
    };
    

    正規表現を管理するための構造体。 これはユーザーの目には触れないはず。

    typedef off_t regoff_t;
    typedef struct {
    	int re_magic;
    	size_t re_nsub;		/* number of parenthesized subexpressions */
    	const char *re_endp;	/* end pointer for REG_PEND */
    	struct re_guts *re_g;	/* none of your business :-) */
    } regex_t;
    typedef struct {
    	regoff_t rm_so;		/* start of match */
    	regoff_t rm_eo;		/* end of match */
    } regmatch_t;
    

    regcompやらregexecでユーザーが触れる機会があるのはこっち。

    regexec
      matcher
         初期化とか
        /* this loop does only one repetition except for backrefs */
        for (;;) {
            endp = fast(m, start, stop, gf, gl); マッチする部分かどうかを判定
              マッチする部分がなかったら
                STATETEARDOWN(m);
                return(REG_NOMATCH);  matcher から抜ける
    
    	/* where? */ マッチする部分があるのなら詳しく調べる。
    
    	for (;;) {
    
    		endp = slow(m, m->coldp, stop, gf, gl);
    		if (endp != NULL)
    			break;
    		assert(m->coldp < m->endp);
    		m->coldp++;
    	}
    	if (nmatch == 1 && !g->backrefs)
    		break;		/* no further info needed */
    
    

    ということで次回は fastとslowを追いかけます。

    2008年01月26日

    mixi

    http://mixi.jp/view_bbs.pl?id=27217448&comment_count=8&comm_id=602606
    http://mixi.jp/view_bbs.pl?id=27217726&comment_count=44&comm_id=2880
    

    豪快なまる投げで、ロクに情報を出さないので色々つつかれた挙句に

        あんたらさ、いちいちうざいコメントはいらないから。
        なにをバカみたいにヘリクツばかり並べたような討論してんだか。
      

    まあ当事者そっちのけであさっての議論(雑談)で盛り上がるのは mixiのプログラミング関係のコミュでは良く見受けられる (あれとかあれとかあれとか)けど、なんつーか、 結局のところ留年を回避できたのかちょっと気になる :)

    買ってみた

    使ってみたい武士の日本語
    使ってみたい武士の日本語
    ほとんどが知っている言い回しでござった。にん。

    ちゅるやさんがそういう反応するなら説明せねばなるまい

    2008-01-24 - [´・[ェ]・] <もももっもっ
    ■[C++] 00:13
    
    ときどきの雑記帖 i戦士篇 すげーぜ C++!
    
              , -‐ '´ ̄ ̄`ヽ、
             /:::::/" `ヽ ヽ:::::::\
            /:::::::::/     ヽ ヽ:::::::::ヽ
            l:::::::{:::l ,    ー-j从:ヽ::::.ヽ
            | ::i::ル{レ'     ●` li!:: ト、:::.',
            /⌒)i"●      l|:: ||ノ:::.l
          /   yi ヘ⊃   ,_,⊂⊃l|:: |:::::::::.l ・・・にょろ?
          (  /ス、,ゝ、_ `´   ィ<|:: |_:::::::.l
           '</ |l:::: i "Tーイ'^ァレ'l_::::::.l
            \,,t|l:::: l'ヾ::|三/:://l/ ヽ、'i
             |::|l:::: l ヾ∨:::/ ヒ::::彡, | :ji
    
    何がなんだか分からない……
    
    

    どこから説明すればいいですかね? まず、lvalue(左辺値とも呼ばれますが、元の語の成立の経緯を考えると 「左辺値」という訳語を当てるのはあまり良くないと思います。 がそれは今回の本題ではないのでスルーします)というのは、 それを評価したときに代入可能なものであるかどうか、ということです。 たとえば

      int x;
      x = 4649;
    

    というときの、x = の xは lvalue を持っています。しかしたとえば

       int ary[100];
       void *p;
    
       ary = &main;
       p = stdin;
    

    というとき、ary = の ary はlvalueを持っていません。反対に p は持っています。

    そしてCにおいては前置/後置の増減演算子が適用された式は lvalue を持たないということになっていますから、

      ++i = 100;
    

    なんてのはエラーになるわけです。

       ((int *)p) += 2501;
    

    というのは昔のCでは許されていましたが、 現在ではキャストの結果は lvalue を持たないということになっていますので、 このような操作は規格上は許されません。 gcc が最近このあたりの動作を変更してLinuxのカーネルのコンパイルで 問題がでたとかでなかったとか(最近つってもン年前?)。

    ところがどうしたものが、C++の場合は前置/後置の増減演算子を適用した式も lvalueをもつということになっていますので、

      ++i = 100;
    

    があっさり通るよ。なんなんだC++って。 という話です。はい。 多分イテレータの実装がらみかなんかでこうなったんじゃないですかね。 面倒なので根拠を探すことはしませんが :)

    むー、すごなやる夫(それはちがう)

    【解説】
    
     サブプライム層とは?
    --------------------------------------------------------------------------------------------------
     サブプライム層とは、ローン会社にとって優良顧客ではない人のこと。
     収入がとても少ない人や、クレジットカードの延滞経験がある人などが該当します。
    --------------------------------------------------------------------------------------------------
    
      

    疑問に思ってましたが調べることはしなかったのでここで初めて知りました○| ̄|_ そーか、だからサブプライム問題なのね。

    あー

    [WSJ] 米IBM、技術者の基本給を15%カット - ITmedia News
    
     賃金や労働時間に関する法律は、労働法の中でもホットな分野だ。IBMのような非組合企業で
    も、米連邦厚生労働基準法では、時給制の従業員に、週40時間を超えた分は5割増しの時給を払
    うよう義務付けている。だが多くのIT企業は、ほとんどの社員を残業の対象外となる専門職とし
    て扱っている。以前月給制だったIBM技術者は、コンピュータやソフトの導入や修理で週に平均
    45時間働いていた。
    

    ホワイトカラーエグゼンプションか。> 残業の対象外となる専門職

    Perl 6

    WITCH / Perl 6
    
    The Perl6 WITCH is mostly a bunch of hyperlinks that allows one to find documentation 
    for operators, special variables and other features when there is a "mystery 
    character" whose usage is not understood.
    
    

    ということで数日前からこのシリーズが継続中。

    Start by clicking on the character you do not understand the usage of. You will be 
    brought to a page that tells how the character is used and/or can point you to 
    compound operators or other uses for the character.
    
        < left pointy
        > right pointy
        ~ squiggle
        ! bang
        * star
        \ backslash
        / slash
        _ underscore
        « left french
        » right french
        ^ hat
        f small f
        o small o
        x small x
    
      

    form reddit

    さて

    RHG 読書会 strikes backがあるので寝るか。 ということで今日は eregのソース読みはお休み。

    2008年01月25日

    ■_ PHP の eregを調べてみる(1)

    昨日の続き。

    -rw-r--r-- 1 070704 mkgroup_l_d   950 Apr  8  1999 COPYRIGHT
    -rw-r--r-- 1 070704 mkgroup_l_d  1219 Apr  8  1999 README
    -rw-r--r-- 1 070704 mkgroup_l_d  5296 Apr  8  1999 WHATSNEW
    -rw-r--r-- 1 070704 mkgroup_l_d   968 Sep 30  2003 cclass.h
    -rw-r--r-- 1 070704 mkgroup_l_d  2058 Dec 29  1999 cname.h
    -rw-r--r-- 1 070704 mkgroup_l_d  5130 Sep 30  2003 debug.c
    -rw-r--r-- 1 070704 mkgroup_l_d   329 Apr  8  1999 debug.ih
    -rw-r--r-- 1 070704 mkgroup_l_d 26223 Aug 13  2004 engine.c
    -rw-r--r-- 1 070704 mkgroup_l_d  1537 Sep 30  2003 engine.ih
    -rw-r--r-- 1 070704 mkgroup_l_d 11171 Apr  8  1999 main.c
    -rw-r--r-- 1 070704 mkgroup_l_d   500 Apr  8  1999 main.ih
    -rw-r--r-- 1 070704 mkgroup_l_d  1825 Apr  8  1999 mkh
    -rw-r--r-- 1 070704 mkgroup_l_d 37759 Sep 30  2003 regcomp.c
    -rw-r--r-- 1 070704 mkgroup_l_d  2795 Sep 30  2003 regcomp.ih
    -rw-r--r-- 1 070704 mkgroup_l_d  3195 Jul 30  2005 regerror.c
    -rw-r--r-- 1 070704 mkgroup_l_d   267 Jun 24  1999 regerror.ih
    -rw-r--r-- 1 070704 mkgroup_l_d 14712 Apr  8  1999 regex.3
    -rw-r--r-- 1 070704 mkgroup_l_d  9696 Apr  8  1999 regex.7
    -rw-r--r-- 1 070704 mkgroup_l_d  3748 Apr  8  1999 regex.dsp
    -rw-r--r-- 1 070704 mkgroup_l_d   533 Apr  8  1999 regex.dsw
    -rw-r--r-- 1 070704 mkgroup_l_d  2051 Nov 13  1999 regex.h
    -rw-r--r-- 1 070704 mkgroup_l_d  5840 Apr  8  1999 regex.mak
    -rw-r--r-- 1 070704 mkgroup_l_d  5536 Sep 30  2003 regex2.h
    -rw-r--r-- 1 070704 mkgroup_l_d   379 Oct 24  2002 regex_extra.h
    -rw-r--r-- 1 070704 mkgroup_l_d  4296 Aug 13  2004 regexec.c
    -rw-r--r-- 1 070704 mkgroup_l_d   738 Apr  8  1999 regfree.c
    -rw-r--r-- 1 070704 mkgroup_l_d  7061 Apr  8  1999 split.c
    -rw-r--r-- 1 070704 mkgroup_l_d 12255 Apr  8  1999 tests
    -rw-r--r-- 1 070704 mkgroup_l_d   527 Nov 14  1999 utils.h
    

    というのが regex ディレクトリにあるファイルの全部ですが、 とりあえず注目するのは regcomp.c regexec.c engine.c の三つです。

    正規表現の内部表現へのコンパイルの入り口はこんな感じ。

    	/* do it */
    	EMIT(OEND, 0);
    	g->firststate = THERE();
    	if (cflags&REG_EXTENDED)
    		p_ere(p, OUT);
    	else if (cflags&REG_NOSPEC)
    		p_str(p);
    	else
    		p_bre(p, OUT, OUT);
    	EMIT(OEND, 0);
    	g->laststate = THERE();
    
    

    今回は ERE を使うルーチンが対称なので p_ere へ。

    /*
     - p_ere - ERE parser top level, concatenation and alternation
     == static void p_ere(register struct parse *p, int stop);
     */
    static void
    p_ere(p, stop)
    register struct parse *p;
    int stop;			/* character this ERE should end at */
    {
    	register unsigned char c;
    	register sopno prevback = 0;
    	register sopno prevfwd = 0;
    	register sopno conc;
    	register int first = 1;		/* is this the first alternative? */
    
    	for (;;) {
    		/* do a bunch of concatenated expressions */
    		conc = HERE();
    		while (MORE() && (c = PEEK()) != '|' && c != stop)
    			p_ere_exp(p);
    		(void) REQUIRE(HERE() != conc, REG_EMPTY);	/* require nonempty */
    
    

    とまあ再帰下降な構文解析をしながら、内部表現コードへと落とし込んでいきます。

    /*
     - p_ere_exp - parse one subERE, an atom possibly followed by a repetition op
     == static void p_ere_exp(register struct parse *p);
     */
    static void
    p_ere_exp(p)
    register struct parse *p;
    {
    	register unsigned char c;
    	register sopno pos;
    	register int count;
    	register int count2;
    	register sopno subno;
    	int wascaret = 0;
    
    	assert(MORE());		/* caller should have ensured this */
    	c = GETNEXT();
    
    	pos = HERE();
    	switch (c) {
    	case '(':
    		REQUIRE(MORE(), REG_EPAREN);
    		p->g->nsub++;
    		subno = p->g->nsub;
    		if (subno < NPAREN)
    			p->pbegin[subno] = HERE();
    		EMIT(OLPAREN, subno);
    		if (!SEE(')'))
    			p_ere(p, ')');
    		if (subno < NPAREN) {
    			p->pend[subno] = HERE();
    			assert(p->pend[subno] != 0);
    		}
    		EMIT(ORPAREN, subno);
    		MUSTEAT(')', REG_EPAREN);
    		break;
    #ifndef POSIX_MISTAKE
    	case ')':		/* happens only if no current unmatched ( */
    		/*
    		 * You may ask, why the ifndef?  Because I didn't notice
    		 * this until slightly too late for 1003.2, and none of the
    		 * other 1003.2 regular-expression reviewers noticed it at
    		 * all.  So an unmatched ) is legal POSIX, at least until
    		 * we can get it fixed.
    		 */
    		SETERROR(REG_EPAREN);
    		break;
    #endif
    	case '^':
    		EMIT(OBOL, 0);
    		p->g->iflags |= USEBOL;
    		p->g->nbol++;
    		wascaret = 1;
    		break;
    	case '$':
    		EMIT(OEOL, 0);
    		p->g->iflags |= USEEOL;
    		p->g->neol++;
    		break;
    	case '|':
    		SETERROR(REG_EMPTY);
    		break;
    	case '*':
    	case '+':
    	case '?':
    		SETERROR(REG_BADRPT);
    		break;
    	case '.':
    		if (p->g->cflags&REG_NEWLINE)
    			nonnewline(p);
    		else
    			EMIT(OANY, 0);
    		break;
    	case '[':
    		p_bracket(p);
    		break;
    	case '\\':
    		REQUIRE(MORE(), REG_EESCAPE);
    		c = GETNEXT();
    		ordinary(p, c);
    		break;
    	case '{':		/* okay as ordinary except if digit follows */
    		REQUIRE(!MORE() || !isdigit(PEEK()), REG_BADRPT);
    		/* FALLTHROUGH */
    	default:
    		ordinary(p, c);
    		break;
    	}
    
    

    EMIT というのが実際に内部表現を吐き出しているマクロです。 EMITの第一引数がオペレータを表すコード、第二引数がオペレータに対するオペランド ということになります。

    /*
     - ordinary - emit an ordinary character
     == static void ordinary(register struct parse *p, register int ch);
     */
    static void
    ordinary(p, ch)
    register struct parse *p;
    register int ch;
    {
    	register cat_t *cap = p->g->categories;
    
    	if ((p->g->cflags&REG_ICASE) && isalpha(ch) && othercase(ch) != ch)
    		bothcases(p, ch);
    	else {
    		EMIT(OCHAR, (unsigned char)ch);
    		if (cap[ch] == 0)
    			cap[ch] = p->g->ncategories++;
    	}
    }
    

    通常のキャラクタは、OCHAR というコード + キャラクタコード という 内部表現になります。 Perlなんかではこの辺は文字が続く部分を特別の意味を持たない文字列を表すコード + その長さ + 実際の文字列 という表現にしてたりします。 Ruby 1.8まで使っていた GNU regex 0.12 でも exactn という同様の内部コードを使っています。

    で内部表現を使って実際にマッチングする方。 regexecというのはPOSIX的に決まっている名前ですね (コンパイルする方は regcomp)。

    /*
     - regexec - interface for matching
     = API_EXPORT(int) regexec(const regex_t *, const char *, size_t, \
     =					regmatch_t [], int);
     = #define	REG_NOTBOL	00001
     = #define	REG_NOTEOL	00002
     = #define	REG_STARTEND	00004
     = #define	REG_TRACE	00400	// tracing of execution
     = #define	REG_LARGE	01000	// force large representation
     = #define	REG_BACKR	02000	// force use of backref code
     *
     * We put this here so we can exploit knowledge of the state representation
     * when choosing which matcher to call.  Also, by this point the matchers
     * have been prototyped.
     */
    API_EXPORT(int)				/* 0 success, REG_NOMATCH failure */
    regexec(preg, string, nmatch, pmatch, eflags)
    const regex_t *preg;
    const char *string;
    size_t nmatch;
    regmatch_t pmatch[];
    int eflags;
    {
    	register struct re_guts *g = preg->re_g;
    #ifdef REDEBUG
    #	define	GOODFLAGS(f)	(f)
    #else
    #	define	GOODFLAGS(f)	((f)&(REG_NOTBOL|REG_NOTEOL|REG_STARTEND))
    #endif
    
    	if (preg->re_magic != MAGIC1 || g->magic != MAGIC2)
    		return(REG_BADPAT);
    	assert(!(g->iflags&BAD));
    	if (g->iflags&BAD)		/* backstop for no-debug case */
    		return(REG_BADPAT);
    	eflags = GOODFLAGS(eflags);
    
    	if (g->nstates <= CHAR_BIT*sizeof(states1) && !(eflags&REG_LARGE))
    		return(smatcher(g, (unsigned char *)string, nmatch, pmatch, eflags));
    	else
    		return(lmatcher(g, (unsigned char *)string, nmatch, pmatch, eflags));
    }
    

    で、昨日ちょっと触れた一つのソースで作った二つの実体が smacher と lmatcher です。

    うがあ、POSIX NFA 的動作の解析までいくつもりだったがダメだった○| ̄|_

    本日の購入

    バンブーブレード O.S.T.
    バンブーブレード O.S.T.
    ネットラジオで挿入歌を聴いてそのために購入。
    超・超・超・大魔法峠 (角川コミックス・エース 40-19)
    超・超・超・大魔法峠 (角川コミックス・エース 40-19)
    一巻とだいぶキャラの顔が変わって…w
    逆境無頼カイジ オリジナル・サウンドトラック
    逆境無頼カイジ オリジナル・サウンドトラック
    世界は僕らの手の中~♪のために購入。 シングルででるものと思ってたよ。
    梶原茂のイングリッシュ演歌
    梶原茂のイングリッシュ演歌
    新聞で紹介記事を見かけてでているのを知った。 いやなつかすぃw simijimi drinking simijimily~♪ only memory go on by♪
    逆方向の王様っすね。

    greenteaさんに私信w

    今秋発売のヤングサンデー(2008 Vol.8)の「絶望に効くクスリ」の インタビュー相手は趙治勲さんですよ。と。

    たぶんgreenteaさんが普段読んでいる雑誌には入ってないと思うので書いておきます。

    チケット購入

    昼休みに会社近くのローソンで購入。 整理番号をみると、 瞬殺といかないまでもいいペースで売れているような。

    redditに訊け!: 今まで自分のプログラミング言語を作ってみたいと夢想したことはありますか? もしあなたが理想のプログラミング言語を設計できたとしたら、何を含めますか? (Do you ever dream of making your own programming language? If you could design the perfect programming language, what would it include?)

    あれ? ひょっとして言いだしっぺは、うぉるたん? あー時間が違うな。

    programming: Ask Reddit: Do you ever dream of making your own programming language?
      If you could design the perfect programming language, what would it include?
      
    WalterBright
    
    Yes, for years, and I finally did something about it. The result is the D programming 
    language. It has lots of neat features like very fast compiles, true arrays, intuitive 
    strings, closures, modules, etc.
    
    うん。そのことは何年も考えていて、その結果がDというプログラミング言語だ。
    Dはイケてる機能がたくさんある。
    たとえば超高速コンパイルだとか、本物の配列、直感的に理解できる文字列、
    クロージャ、モジュール、などなど。
      
    setuid_w00t
    
    The perfect language already exists and it is Lolcode.
    
    完全言語はすでにある。Lolcodeってやつが。
      
    no-op
    
    My perfect language would include cats!
    
    僕の完全言語にはぬこがあるよ!
      
    procyon112
    
    I think I want:
    
    僕が欲しいもの:
    
    1) Full lambda cube type system including dependent typing.
    
    #lambda cube ?
    
    2) Pattern Matching
    
    パターンマッチング
    
    3) Lazy Evaluation with option for strict
    
    strictなオプションも可能な遅延評価
    
    4) Partial type inference where possible with optional type annotations. Compiler errors
       where inference is not possible, detailing the ambiguity,
    
    5) Automatic unboxing for single constructor data types.
    
    単一のコンストラクタを持つデータ型のための自動 unboxing
    
    6) Turing incomplete (no general recursion) except where inside some sort of Y Combinator
       Monad or the like, which would have to be defined primitively.
    
    Yコンビネータモナドなどの内側を除きチューリング不完全(?)
    
    7) No side effects, except in the IO monad.
    
    IOモナドを除き副作用がない
    
    8) Strongly typed module system, so that modules are actually an instance of a data type.
    
    強い型付けを施されたモジュールシステム。
    モジュールは実際にはデータ型のインスタンス。
    
    9) Multiparameter type classes.
    
    複数のパラメータを取れる型クラス。
    
    10) The ability to show higher order proofs, such as associativity or transitivity of a
        function through its type signature and have it guaranteed by the compiler.
    
    型シグネチャを利用した関数の associativity や transitivity のような
    show higher order proofsのための能力。
    
      
    enneff
    
    Python with macros. Or maybe I should just learn Lisp.
    
    マクロつきのPython。
    ひょっとしたら自分がLispを学ぶべきなのかもしれないけど。
      
    weavejester
    
    
    Like Logix, or Boo, maybe?
    
    それ、LogixとかBooみたいなもんじゃね?
      
    
        * Python-like syntax
    Pythonのような構文
        * Smalltalk's object model
    Smalltalkのオブジェクトモデル
        * Ruby's anonymous blocks for DSLs
    RubyのDSL向け無名ブロック
        * Squeak traits (google 'traits paper') as the best alternative to multiple
          inheritance (a.k.a. Perl6's Roles)
    多重継承の最善な代替としてのSqueakのtraits(とPerl6のRoles)。
        * Perl6 regexes (or whatever they're called now)
    Perl6の正規表現
        * Haskell's type-inference
    Haskellの型 inference
    
    I want my language to be pretty (like Python), solidly object-oriented (like Smalltalk), 
    good for building DSLs in (like Ruby), not require me to state the obvious (like 
    Haskell), and have multiple inheritance but without the complications it entails (i.e. 
    traits).
    
      
      
      

    「ブレースの使えるPython」ってのが複数人いるってのはどーよ?w

    本物のプログラマはどんな言語でだって(プログラムを)書ける

    A Real Programmer Can Write in Any Language (C, Java, Lisp, Ada)
    
    
    Why C Matters
    
    Cが重要である理由
    
    C is the low-level language that everyone must know. It can be seen as a portable 
    assembly language, and as such it exposes the underlying machine and forces the 
    student to understand clearly the relationship between software and hardware. 
    Performance analysis is more straightforward, because the cost of every software 
    statement is clear. Finally, compilers (GCC for example) make it easy to examine the 
    generated assembly code, which is an excellent tool for understanding machine language 
    and architecture.
    
    Cはハードウェアよりという意味での低レベルな言語であり、誰もが知っておかなければ
    ならいない言語である。Cは移植性のあるアセンブリ言語と見ることもでき、
    マシンの下層を目の当たりにさせた上で
    学生にソフトウェアとハードウェアとの関係を明確に理解することを強制するものである。
    パフォーマンスの解析はより直接的なものである。なぜならば、すべてのソフトウェアの
    文のコストというものが明確だからである。さらに、(たとえばgccのような)コンパイラ
    に生成したアセンブリコードを検査させることが容易である。
    機械語とアーキテクチャを理解するためのすばらしいツールがある。
    
    Why C++ Matters
    
    C++が重要なわけ
    
    C++ brings to C the fundamental concepts of modern software engineering: encapsulation 
    with classes and namespaces, information hiding through protected and private data and 
    operations, programming by extension through virtual methods and derived classes, etc. 
    C++ also pushes storage management as far as it can go without full-blown garbage 
    collection, with constructors and destructors.
    
    C++はCに現代的なソフトウェアエンジニアリングの考え方を持ち込んだ。
    クラスや名前空間を使ったカプセル化(encapsulation)、protectやprivateを使った
    データや操作のに関する情報の隠蔽、仮想メソッドや派生クラスを通じた拡張による
    プログラミングなどなど。
    C++はまた、コンストラクタとデストラクタを使って full-blown なガーベジコレクション
    を使わないようなメモリ管理をpushする。
    
    Why Lisp Matters
    
    Lispが重要なわけ
    
    Every programmer must be comfortable with functional programming and with the 
    important notion of referential transparency. Even though most programmers find 
    imperative programming more intuitive, they must recognize that in many contexts that 
    a functional, stateless style is clear, natural, easy to understand, and efficient to 
    boot.
    
    すべてのプログラマは関数型プログラミングやimportant notion of referential transparency
    (参照透明性についての重要な表記?)に対して comfortableでなければならない。
    ほとんどのプログラマは命令型プログラミングの方がより(自分にとっては)
    わかりやすいものだと認識していたとしても、関数的なコンテキストの多く、
    状態を用いないスタイルがclerarで、自然で、理解しやすく、efficient to boot
    ということを認識できなければならない
    
    An additional benefit of the practice of Lisp is that the program is written in what 
    amounts to abstract syntax, namely the internal representation that most compilers use 
    between parsing and code generation. Knowing Lisp is thus an excellent preparation for 
    any software work that involves language processing.
    
    Lispの経験をつむことの付加的な利点は、
    プログラムというものは抽象的な構文の集まりであり、
    大部分のコンパイラが解析とコード生成との間で使用する内部的な表現
    
    Lispを知るということはつまり、言語処理を行うようなソフトウェアのための
    優れた準備である。
    
    
    Finally, Lisp (at least in its lean Scheme incarnation) is amenable to a very compact 
    self-definition. Seeing a complete Lisp interpreter written in Lisp is an intellectual 
    revelation that all computer scientists should experience.
    
    
    Why Java Matters
    
    Javaが重要なわけ
    
    Despite our comments on Java as a first or only language, we think that Java has an 
    important role to play in CS instruction. We will mention only two aspects of the 
    language that must be part of the real programmer’s skill set:
    
    最初の言語もしくは唯一の言語として我々がコメントしたこととは関係なく、
    我々はCS instructionにおいてJavaが重要な役割を果たしていると考えています。
    本物のプログラマの skill set が持っていなければならない二つの言語要素だけ
    言及します。
    
       1. An understanding of concurrent programming (for which threads provide a basic 
          low-level model).
    
    並行プログラミングの理解
    
       2. Reflection, namely the understanding that a program can be instrumented to 
          examine its own state and to determine its own behavior in a dynamically changing 
          environment.
    
    リフレクション
    
    Why Ada Matters
    
    Adaが重要なわけ
    
    Ada is the language of software engineering par excellence. Even when it is not the 
    language of instruction in programming courses, it is the language chosen to teach 
    courses in software engineering. This is because the notions of strong typing, 
    encapsulation, information hiding, concurrency, generic programming, inheritance, and 
    so on, are embodied in specific features of the language. From our experience and that 
    of our customers, we can say that a real programmer writes Ada in any language. For 
    example, an Ada programmer accustomed to Ada’s package model, which strongly 
    separates specification from implementation, will tend to write C in a style where 
    well-commented header files act in somewhat the same way as package specs in Ada. The 
    programmer will include bounds checking and consistency checks when passing mutable 
    structures between subprograms to mimic the strong-typing checks that Ada mandates [6]. 
    She will organize concurrent programs into tasks and protected objects, with 
    well-defined synchronization and communication mechanisms.
    
    Adaはすばらしい水準のソフトウェアエンジニアリングのための言語である。
    プログラミングコースで使われる言語ではないとしても、Adaは
    ソフトウェアエンジニアリングのコースで教えるために選択された言語である。
    その理由は、強い型付け、カプセル化、情報隠蔽、並列性、ジェネリックプログラミング、
    継承などのための記法を持っているからである。
    我々や我々の顧客の経験から、我々は本物のプログラマはどんな言語でもAdaを書くと
    云えるだろう。たとえば、
    仕様と実装を明確に分離するAdaのパッケージモデルに慣れ親しんだプログラマは
    Cでプログラムを書くときにも質の良いコメントのついたヘッダファイルを
    Adaにおける package specs と同じ役目を担うものとして用意する傾向にある。
    そういったプログラマは変更可能な構造体を渡すときには
    境界チェックや一貫性のチェックを忘れないだろう。
    彼女はまた concurrent programをタスクとプロテクトされたオブジェクトとして
    シンクロや通信の機構をきちんと定義した上で構築するだろう。
    
    The concurrency features of Ada are particularly important in our age of multi-core 
    architectures. We find it surprising that these architectures should be presented as a 
    novel challenge to software design when Ada had well-designed mechanisms for writing 
    safe, concurrent software 30 years ago.
    

    力尽きた○| ̄|_

    from reddit

    めも

    2008年01月24日

    ■_ キターッ

    コンピュータアーキテクチャ 定量的アプローチ 第4版:SEshop.com/商品詳細
    		
    コンピュータアーキテクチャ 定量的アプローチ 第4版
    
    著:	David A. Patterson / John L. Hennessy
    添付:CD-ROM 1点
    ISBN:9784798114408
    サイズ:B5変
    ページ:768
    販売価格:\8,610(本体\8,200 消費税5%)
    発売日:2008/02/20
    出版社:株式会社翔泳社
    原出版社:Morgan Kaufmann Publishers
    原著タイトル:Computer Architecture : A Quantitative Approach
    
    コンピュータアーキテクチャの第一人者が執筆した世界的名著
    
    「RISC」育ての親、ヘネシー&パターソン両教授によるコンピュータアーキテクチャの定番書。初版は
    1994 年2 月、日経BP 社より刊行され、大ベストセラーになりました。本書はその改訂第4 版を翻訳し
    たものです。姉妹書「コンピュータの構成と設計第3版上巻・下巻」(日経BP社)はハードウェアから
    ソフトウェアまで網羅した書籍でベストセラーになっています。本書は、CPUアーキテクチャ設計中心に
    ハードウェアにおけるシステムアーキテクチャを詳細に解説。付録のCD-ROMも初邦訳され、さらに学習
    しやすくなりました。コンピュータの仕組みを学べる定番書として欠かせない一冊です。 
    

    ■_ NoScript (Firefox)

    うーむ。あまりにも重くなるんで外してしまって久しいが、 こういうのを見ると入れないわけにもいかんような気がするしどうしたもんか喃。 → Firefox chrome: URL Handling Directory Traversal

    このような例は多数あります。NoScriptは必須の拡張だと言えると思います。
    

    ■_ え?

    MS系で正規表現処理する時の不注意

    正規表現の文末の識別に "$"というコントロールCHARがあります。
    これを行末として動作させるオプションに  RegexOptions.Multilineがあります。
    素直に "lineEnd\s*$"  と 指定しても、行末を認識してくれません。行末の認識は
    lf(0x0A)で判断しているので、 lineEnd<行末> だと lineEnd(0x0D)(0x0A) となって
    いてパターンがマッチしません。
    

    「コントロールCHAR」ってどこの方言だよという突っ込みは自重しつつ、 \s は \r も含む文字クラスのはずだから、 マッチ対象データがたとえば"lineEnd\r\nhogehoge" という具合になっていても、 \s が \rを飲み込んでくれるので例示されているパターンならマッチに成功するはず。

    using System;
    using System.Text.RegularExpressions;
    
    class X 
    {
      public static void Main(string[] args)
      {
        string s = "\x0d\r\n";
        string p = @"\A\s+\z";
    
        if (Regex.IsMatch (s, p, RegexOptions.Multiline))
            Console.WriteLine("\\s includes 0x0d");
        if (Regex.IsMatch ("lineEnd\r\nline2", @"lineEnd\s*$", RegexOptions.Multiline))
            Console.WriteLine("match");
      }
    }
    
    
    実行結果:
    
    \s includes 0x0d
    match
    

    \r (0x0d)の扱いが悩ましいのには同意するけど、ことこのエントリの件に関しては どこかで勘違いが入っていると思う。

    あと、Perl 6の仕様で提案されてPerl 5.10.0に持ち込まれた \R (論理的な改行。\r \r\n \n などにマッチ) があるのでいずれは他の処理系にも 伝播するかもしれない(ししないかもしれない)。

    ■_ なぜ、2008年においてErlangじゅーよーなのか

    P16: Practical Progress: Why Erlang Matters in 2008

    Macro forces – Changes in the marketplace:
    マクロ的な要因 市場における変化
    
    
        * Amazon EC2 – Every new internet startup wants to use EC2. It's an inexpensive, outsourced 
          datacenter – but ONLY if your application can scale dynamically.
    
        * Intel Core 2 Duo – SMP in your laptop. Now developers can see the benefits of SMP-capable 
          applications first-hand, even during the prototype stage.
    
          SMPが今やあなたの膝の上にも乗る時代に。開発者はSMP対応のアプリケーションによる
          利益を目の当たりにするようになる。
    
        * Hadoop and Google's MapReduce – buzz is building about these parallel-computing systems for 
          tackling massive datasets using commodity hardware. But these are ONLY useful for batch 
          processing.
    
        * Ruby on Rails scaling woes – buzz started with an interview with a Twitter developer full 
          of great quotes
    
          Ruby on Rails がスケーリングという点で苦しんでいる
    
    Maybe more people are starting to think "SMP/parallel computing matters", especially for web 
    applications. People are wondering in the design phase how to utilize multiple "cores" 
    effectively. Erlang has answers to these questions.
    
    Micro forces – Changes in Erlang itself:
    ミクロな要因 Erlangそれ自身の変化
    
    
        * Open-sourced in 1998 – disqualified it from last dot-com boom, save for Bluetail which was 
          ex-Ericsson folks
    
        * Joe Armstrong's new book, published by Pragmatic Programmers who produced the famous Ruby 
          "Pickaxe Book"
    
          有名なRubyの“Pickaxe Book”(ピッケル本)をプロデュースした Pragmatic Programmers から
          出版される Joe Armstrongの新作本。
    
        * A new Ruby-inspired web framework, ErlyWeb
          
          Rubyに inspireされた新しい web フレームワークである ErlyWeb
    
    

    ■_ 素晴らしい試みw

    わーい \(^o^)/ LispをPostScriptで書いたLispで書いたよー! (リリカル☆Lisp 開発日記)

    最近、巷(*)ではLisp(Scheme?)を実装するのが流行っているようで。
    その流れにのっとって私も変なものをつくってみました。
    
    ***PostScriptで書いたlisp***
    
    
    
    名前はまだないのですが、仮にpslispと呼びます。
    このpslispはPostScriptで書いたLispインタプリタです。
    単に式を評価するだけではなく、その値を図示してくれる優れもの(?)です。
    

    いや実に素晴らしい :)

    つまり、目標はプリンタで動かすことなんですが、
    現状ではGhostscriptでしか動作を確認していません。
    レーザプリンタなどで動作確認をしてくれたら嬉しい……ですが、プリンタの安全は保障しかねます。
    

    PSプリンタに食わせるとがっしょんがっしょん(なんて音はLBPは出さないw)紙を吐き出すとか? あー、でも

    SetGlobalEnv
    gsave
    newpath
    
    input_string StringToLObject global_env Eval
    dup LObjectHeight
    1 dict begin
    	/height exch def
    	dup 60 height PAGE_MARGINE add DrawLObject
    	/Times-Roman findfont
    	20 scalefont setfont
    	60 height PAGE_MARGINE add 40 add moveto
    	(input : ) show
    	input_string show
    	60 height PAGE_MARGINE add 20 add moveto
    	(output: ) show
    	WriteLObject
    end
    
    showpage
    grestore
    

    showpageがいっこしかないから、出力は必ず1ページか。 PSってクリッピングどうすんだっけ? PSいじってたのははるか昔だから忘れちまったいw

    ■_ そろそろ宿題を片付けていかないとな(しょの1)

    第29回PHP勉強会に行ってきました - hnwの日記 のコメント欄に思わせぶりにコメントつけたはいいが、 どうも勘違いしていたのは自分のほうのような気配が濃くなる一方の今日この頃(笑)

    でまあご存知の方も多いかと思いますが、PHPには三種類の正規表現エンジンが積まれています。 実際にそれらを挙げてみると

    でまあ話はワタクシの勘違いへ。 hnwさんが昨年12月23日にあった第29回PHP勉強会で発表された内容なんですが (発表で使われたスライド→「PHPの正規表現と最長一致」(pdf))、 この中で ereg* のエンジンが詳説正規表現(Matering regular expressions)で云うところの POSIX NFA タイプの正規表現エンジンだとあるのですが、 それは違うだろうと思ってたんですね。が、調べてみると確かに POSIX NFA のような 振る舞いをするんですわw たとえば、

        [A-Z]+|[A-Z0-9]+
    

    という正規表現を考えます。

    $echo ABCDEFG123XYZ|perl -ne "print $& if /[A-Z]+|[A-Z0-9]+/;
    ABCDEFG
    
    echo ABCDEFG123XYZ|ruby -ne "print $& if /[A-Z]+|[A-Z0-9]+/;
    ABCDEFG
    

    とまあこれに驚く人は多分いないと思いますが、一方PHP(のereg)では

    cat m.php
    $<?php
        ereg("[A-Z]+|[A-Z0-9]+", "ABCDEFG123XYZ", $matches);
        print_r($matches);
    
    $php m.php
    Array
    (
        [0] => ABCDEFG123XYZ
    )
    

    と見事に違う結果となりました(ちなみにhnwさんの発表資料にあるように、 mb_eregやpregだとPerl/Rubyと同じ結果になります)。 この結果は正しく POSIX NFA の動作です(実はDFAでも結果は同じになるんですが DFAではないのでそれは置いときます)。

    ちなみに DFAを使っているものの例

    $echo ABCDEFG123XYZ|egrep -o -e "[A-Z]+|[A-Z0-9]+"
    ABCDEFG123XYZ
    
    $echo ABCDEFG123XYZ|gawk 'match($0, /[A-Z]+|[A-Z0-9]+/){print substr($0, RSTART, RLENGTH)}'
    ABCDEFG123XYZ
    

    後方参照をサポートしているという点からDFAというのはないわけで、 POSIX NFA で決まりかというと “aXXaaaaaaaaaaaaaaaaaaaaa”という文字列に対して“X(.+)+X”という パターンを適用しても即座に終了してしまいます。 NFAタイプのエンジンであればこれは大量のバックトラックを引き起こし、 結果として処理時間は文字列の長さに対応して指数的に長くなります。 まあ最適化してるんですかねえ。

    とここまで書いて時間切れの模様。つづく(多分)。

    めも

  • programming: As a Firefox user I feel somewhat offended by panasonic's favicon :(

    ぶははは、なに考えてんだパナのデザイナーさんは。

  • programming: Bit Twiddling Hacks
    Bit Twiddling Hacks
  • programming: Really strange quirk of Ruby and Perl regular expressions
    taw's blog: Really strange quirk of Ruby and Perl regular expressions

    正規表現の動作はわかりづらいよね。 って言語ごとで微妙に違う操作して混乱してるだけという気が。

  • programming: Beyond pair programming: web 2.0 pair users

  • Pexpect - a Pure Python Expect-like module
    Pexpect can be used for automating interactive applications such as ssh, ftp, passwd, 
    telnet, etc. It can be used to a automate setup scripts for duplicating software 
    package installations on different servers. It can be used for automated software 
    testing. Pexpect is in the spirit of Don Libes' Expect, but Pexpect is pure Python. 
    Unlike other Expect-like modules for Python, Pexpect does not require TCL or Expect 
    nor does it require C extensions to be compiled. It should work on any platform that 
    supports the standard Python pty module. The Pexpect interface was designed to be easy 
    to use.
    
  • programming: Playing with Scala 3: OO, Traits, and Views
    Gabriel's software development blog: Playing with Scala 3: OO, Traits, and Views
  • ここまで堂々としていると逆に清清しい

    PHPについて教えて下さい。
    
    次の要素を持つプログラムを作成して下さい。(PHPで)
    10個の要素を持つ内部のテーブル「TBLA」があります。
    変数「WA」の内容でこのテーブル内を検索し、TBLAの何個目の要素と一致するかを求め「ANS」
    に格納するロジックを記述しなさい。
    
    なお処理する際、他に変数が必要な場合は、「I、J、K、L、M、N」を使用して下さい。
    ※素人なので出来るだけわかりやすい簡単なやり方でお願いします。
    宜しくお願いします。
      

    「教えて欲しい」のか「作って欲しい」のかどっちだw なんかの課題っぽいけど、その手の授業なりでPHP使ってるところがあるってことか?

    2008年01月23日

    ■_ PLNews

    一体どの言語をチェックしていてどれが初登場なのか良くわからなくなってしまったので、 アーカイブページからここ三ヶ月位のデータを拾ってきて(wget でまとめてとろうとしたら 分けのワカランバイナリデータになってしまったので、 手作業で:)。 あとはいつも通りその筋のツールで整形。

    $>cat <moge.html | grep -P -o '^[A-Za-z].*[0-9].*(?=has been released)' | sortf -u
    

    ちと比較規則や抜き出し規則を考えるのが面倒だったので、 同じ言語のバージョン違いをまとめるとこまではやってない。

    AFNIX 1.6.0
    Algol 68 Genie Mark 11
    Allegro CL 8.1 (x86-64) for Mac OS X Leopard (10.5)
    AspeCt-oriented C V 0.8
    BBC BASIC for Windows 5.80a
    Berkeley Unified Parallel C 2.6.0
    Bigloo 3.0c
    Boo 0.8
    CHICKEN 2.74
    Cat 0.18.0
    Cat 0.18.2
    Cobra 0.6
    Ctalk 0.0.14a
    Ctalk 0.0.15a
    Ctalk 0.0.19a
    Ctalk 0.0.20a
    Ctalk 0.0.22a
    Ctalk 0.0.23a
    Ctalk 0.0.24a
    Ctalk 0.0.26a
    Ctalk 0.0.32a
    Ctalk 0.0.34a
    Ctalk 0.0.35a
    Ctpp 1.0.19
    Ctpp 1.0.26
    Ctpp 1.0.27
    Ctpp 1.0.28
    Digital Mars D 1.022
    Digital Mars D 1.024
    Digital Mars D 1.025
    Digital Mars D 2.005
    Digital Mars D 2.006
    Digital Mars D 2.008
    Digital Mars D 2.009
    Dolphin Smalltalk 6.1 Beta
    ECMAScript Edition 4 Reference Implementation M1
    EiffelStudio 6.1
    Erlang/OTP R12B-0
    Excelsior JET 6.0
    F# 1.9.3.7
    F-Script 2.0 (alpha)
    Factor 0.91
    FlashForth 3.0
    FreeBASIC 0.18.3b
    Frink 2007-11-28
    Frink 2007-12-04
    Frink 2007-12-09
    Frink 2008-01-11
    GCC UPC 4.0.3.4
    GNU CLISP 2.42
    GNU CLISP 2.43
    GNU Compiler Collection 4.2.2
    GNU Guile 1.8.3
    GNU Smalltalk 2.95e
    GNU Smalltalk 2.95f
    GNU Smalltalk 2.95g
    GNU Smalltalk 2.95h
    GNU Smalltalk 3.0
    Gambas 1.9.90
    Gambas 1.9.91
    Gambas 2.0 RC2
    Gambit-C 4.1.2
    Gambit-C v4.1.0
    Gambit-C v4.1.1
    Gauche 0.8.12
    Glasgow Haskell Compiler 6.8.1
    Glasgow Haskell Compiler 6.8.2
    Groovy 1.1-RC-1
    High Level Assembly v1.98
    Hop 1.8.0
    IBM Workstation APL2 for Multiplatforms Version 2.0 Service Level 11
    IKVM 0.36
    IKVM 0.36 Release Candidate 6
    IKVM 0.36 Update 1 Release Candidate 1
    IKVM 0.36 rc4
    IKVM 0.36 rc5
    Ikarus 0.0.1
    Ikarus 0.0.2
    Io 2008 01 07
    IronPython 1.1.1 RC 1
    IronPython 2.0 Alpha 5
    IronPython 2.0 Alpha 6
    JRuby 1.0.2
    JRuby 1.0.3
    JRuby 1.1 RC 1
    JRuby 1.1b1
    JamVM 1.5.0
    Jython 2.2.1
    Kent Retargettable Occam Compiler 1.5.0-pre3
    Kite 1.0a1
    LIOGO 0.4
    Larceny v0.95
    Logtalk 2.30.6
    Logtalk 2.30.8
    Logtalk 2.31.0
    Logtalk 2.31.2
    Lua 5.1.3-rc1
    Lua 5.1.3-rc3
    Lua 5.1.3-rc4
    MiniD 1.1
    Mono 1.2.6
    Mono 1.2.6 Preview 4
    Mono 1.2.6 preview 3
    NASM 0.99.05
    NASM 2.00
    NullLogic Embedded Scripting Language 0.9.1
    ORCA 498
    Objective Caml 3.10.1 release candidate 2
    Online Cat Interpreter 1.1
    PHP 4.4.8
    PHP 5.2.5
    PLT Scheme v372
    Parrot 0.4.17
    Parrot 0.5.1
    Parrot 0.5.2
    Perl 5.10.0
    Poet 2.1.0
    Python 3.0a2
    Qore 0.6.2.2
    R 2.6.1
    REBOL 3.0 Alpha
    Reva 7.0.1
    Roadsend Compiler for PHP 2.9.4
    Ruby 1.9.0
    Run BASIC Personal Server v1.0
    S-Lang 2.1.3
    SP-Forth 4.19
    STklos 0.97
    SWI-Prolog 5.6.45
    SWI-Prolog 5.6.47
    Scala 2.6.1-RC1
    Scala 2.6.1-RC2
    Scala 2.6.1-final
    Scheme2Js 20071005
    Scheme2Js 20071220
    Seed7 2007-10-10
    Seed7 2007-10-25
    Seed7 2007-11-10
    Seed7 2007-11-25
    Seed7 2007-12-10
    Seed7 2007-12-27
    Seed7 2008-01-06
    Seed7 2008-01-20
    Shed Skin 0.0.25
    Shed Skin 0.0.26
    Sleep 2.1-b19
    Sleep 2.1-b20
    Smalltalk YX 0.1.5
    Smalltalk YX 0.1.6
    Steel Bank Common Lisp 1.0.11
    Steel Bank Common Lisp 1.0.13
    StrongForth 1.3
    SuperWaba 5.84
    TOY 2.3.1
    Tcl/Tk 8.4.17
    Tcl/Tk 8.5.0 RC3
    Tcl/Tk 8.5b2
    Toka 1.2
    Vala 0.1.4
    Vala 0.1.5
    Vala 0.1.6
    Wraith Scheme 1.30
    XLOGO 0.9.90
    Zsh 4.2.7
    amforth 2.4
    amforth 2.5
    eTcl 1.0-rc25
    haXe 1.16
    haXe 1.17
    newLISP 9.2.10
    newLISP 9.2.12
    newLISP 9.2.13
    newLISP 9.2.16
    newLISP 9.2.4
    newLISP 9.2.7
    newLISP 9.2.8
    newLISP 9.2.9
    nwcc 0.7.4
    ocamljs 0.1
    ooRexx 3.2.0
    

    ■_ perl6 がいっぱい

    いつの間にかこんなになったのか。 Perl 6 implementations / Perl 6

    Perl 6 implementations
    
    Unlike previous versions of Perl, where the translator actually defined the language, 
    for Perl 6 the language is defined by its specification (the synopses). Thus, there 
    are several implementations of Perl 6, and none of them are designated as "The 
    Official Perl". As Synopsis 1 indicates, Perl 6 is anything that passes the official 
    test suite.
    
    translator が実際の言語を規定していたこれまでのバージョンのPerlとは異なり、
    Perl6は言語としての規格を(synopsesによって)規定されている。
    このため、いくつものPerl 6の実装が存在していて、それらのどれひとつとして
    “The Official Pel”として設計されたものではない。
    Synopsis 1が示すように、公式の test suite を通ったものであれば
    それはPerl 6なのだ。
    
    Here's a brief synopsis of the current implementations. View their individual pages 
    for more details.
    
    現時点で実装されているものの簡単な説明をする。
    詳細についてはそれぞれのページを参照して欲しい。
    
    Pugs
    
    As of this writing (2007-12-28), Pugs is the most complete of the available 
    implementations, but its development seems to have stalled somewhat. Pugs is written 
    in Haskell and currently hosts the official Perl 6 test suite.
    
    2007年12月28日に書いたように、Pugsは実装されているものの中で現時点で最も
    完成度の高いものであるが、その開発は停滞しているようである。
    PugsはHaskellを使って記述されていて、現在のところ公式の Perl 6 test suiteの
    ホストとなっている。
    
    
    Rakudo
    
    Rakudo is designed to run on Parrot, which is a virtual machine designed to support 
    dynamic languages. Rakudo is still fairly primitive at the moment, but it is rapidly 
    gaining new features. As of December 2007, Rakudo has been substantially rewritten so 
    that major components of the compiler are written in Perl 6 (using both itself as a 
    bootstrap and the "Not Quite Perl" language below). Rakudo was formerly known as 
    "perl6", but the name has been changed to better reflect the fact that there's no 
    "official" Perl 6 implementation, and to reduce confusion.
    
    Rakudoは動的言語をサポートするように設計された仮想マシンのParrot上で動作するよう設計された
    ものである。Rakudoはまだ非常に基本的な部分しかできていないが、新しい機能の実装は
    急速に行われている。2007年12月、Rakudoはコンパイラ部分の主要なコンポーネントがPerl 6
    で記述されたものに大幅に書き換えられた
    (ブートストラップとして自分自身と後述する "Not Quite Perl"が使われた)。
    Rakudoは形式的には“perl6”として知られていたが、“公式の”(official) Perl 6は
    存在しないという事実を反映し、混乱を少なくするために名前が変更された。
    
    
    KindaPerl6 (kp6)
    
    is a project which grew out of pugs and is aimed to run a subset of perl 6 on the 
    traditional perl interpreter. It's designed and headed by Flavio S. Glock.
    
    KindaPerl6 (kp6)は
    pugsから派生し(grew out of)、伝統的なperlインタープリタ(traditional perl interpreter)
    の上でperl 6のサブセットを実行しようというプロジェクトである。
    Flavio S. Glock が設計と開発の指揮が行っている。
    
    Not Quite Perl (NQP)
    
    "Not Quite Perl" (NQP) is not really a Perl 6 implementation, even though it uses Perl 
    6 syntax. NQP is a tool to help write compilers and libraries for Parrot, and is not 
    really intended as a complete end-user programming language. It uses only limited 
    forms of Perl 6 syntax, and provides only native Parrot runtime support (i.e., no 
    specialized Perl 6 libraries or functions).
    
    “Not Quite Perl”(NQP Perlではないもの)は、Perl 6の文法を使っているにもかかわらず
    実際には Perl 6の実装ではない。NQPはParrotのためのコンパイラやライブラリの
    記述を助けるためのツールであって、エンドユーザーがプログラムするのに使う
    ものとして作られているものではない。NQPはPerl 6の文法の限定された形式しか
    使っておらず、ネイティブのParrotランタイムサポートだけを提供している
    (Perl 6のライブラリや関数に特化したものではないということ)。
    
    Simplistic Meta Object Programming (SMOP)
    
    Also called "Simple Matter Of Programming", SMOP is an alternative runtime engine for 
    Perl 6 in C with a pragmatic approach. It's much like the perl5 interpreter and 
    feature a extremely polymorphic design which allows integration of about whatever 
    object system and even pluggin of other interpreters. It's supposed to become a target 
    for the KindaPerl6 compiler, until it bootstraps and finally supports the STD grammar.
    
    これは別名を“Simple Matter Of Programming”といい(略称SMOP)、Cを使った
    現実的なアプローチによるPerl 6のもう一つのランタイムエンジンである。
    そのエンジンはperl5インタープリターに似ており、
    オブジェクトシステムや他のインタープリタのプラグインすらも統合することのできる
    非常に polymorphic なデザインである。
    ブートストラップとSTD grammerの最終的なサポートがなされるまで
    KindaPerl6コンパイラのターゲットとなるようサポートされている。
    

    ■_ 良いプログラマの見分け方

    以前 redditネタで見つけて、英文貼り付けて中途半端に訳して逃げたヤツwですが Geekなぺーじ : 良いプログラマの見分け方 で紹介されていました(もちろん元記事の方)。

    見分け方をまとめると、以下のようになるそうです。流石に全ての項目を満たすような人は少な
    いそうですが、どれか一つでもあてはまる項目があれば、それは良いプログラマなのかも知れな
    いそうです。原文には、詳細な説明があるので興味のある方は是非ご覧下さい。
    
        * 技術に対して情熱がある。情熱が無く、プログラミングが賃金を得るための仕事でしかない
          人は駄目。
        * 家で趣味でコード書くぐらいが必要。
        * 技術的な話題を話し出したら止まらないような人が良い。促されても技術的な話題で眼を
          輝かす事ができない人は駄目。
        * 自分で勝手に最新技術を学び続ける。「ああ、それなら出来ますよ。会社の費用で研修を
          受けさせてくれれば、やれるようになります。」と言うタイプの人はアウト。
        * 目的を達成するために最適な技術を選べる。実現するための技術を選んでからやり方を考
          える人は駄目。
        * 自分が正しいと思わない技術によって実現することを不快に思う人が良い。
        * 多くの話題で会話が可能で、賢いように思える人が良い。
        * 大学/会社に入る前からプログラミングをやっている人が良い。
        * 履歴書に書かれていない経験が多い人が良い。良いプログラマは、履歴書に書ききれない
          ぐらいの経験や実績がある場合が多い。
        * 職務とは関係がない関連技術に関する知識が豊富にある。履歴書に書かれた技術以外のも
          のを全く習得していない人は駄目。
    
    

    やっぱ最後の項目のアレは履歴書みたいな感じになるんですね。 slashdotにもトピックが立ってたようで(さすがにスラドまで追いかけてる余裕はないんだよなあ)。 Slashdot | How to Recognize a Good Programmer

    鳥頭(忘れっぽいという意味で)って英語でなんて云うんだろう?

    あれ? - odz buffer

    うははは、完全に忘れてました。 滅多に使うものでもないのでGCにかかってしまったようです ○| ̄|_

    あと1,2回は同じことしそうだw

    本日の購入

    聖☆おにいさん (モーニングKC)
    以前増刊で読んだことがあるのだけど、 新刊台で平積みになっているのを発見したので購入。 なんか罰当たりな内容な気がしないでもないのだけどいいのだろうかw

    他の言語がLispからパクるべき機能

    Things I like about lisp that haven't crossed over into enough mainstream languages yet:
    
       1. "Bignum" support:
           多倍長数のサポート (RubyとPythonは拡張なしでサポートしている旨の記述あり)
    
       2. Optional type declarations (Common Lisp.)
          オプションでつけることのできる型の宣言
    
       3. Proper (unbounded) tail-recursion (Scheme.)
          末尾再帰
    
       4. Methods with multiple-dispatch (Common Lisp.)
          多重ディスパッチを行うメソッド
    
       5. Some Lisp implementations are fast. Unlike Ruby, Python, Perl, PHP, and 
          JavaScript, both Common Lisp and Scheme have good native compilers.
    
          Common LispとかSchemeにはネイティブコンパイラがあるぜこのヤロー
          RubyとかPython、…にはねーだろ。
    
       6. Syntactic simplicity (Scheme.) This is a positive view of "syntactic poverty," 
    
      

    それぞれの項目の詳しい理由は原文をあたっていただくということで。

    from reddit

    2008年01月22日

    ■_ (フリーウェア/自由ソフトウェアを書く人であっても)プログラマは只働きするのが好きなわけじゃない

    MSN相談箱 ソフト開発の提案
    ソフト開発の提案
    
    世の中には多くのフリーウェア/シェアウェアがあります。
    こんなソフトがあったら便利だなという提案を送れるサイトはありませんでしょうか。
    
    もちろん、困っている事象を解決するソフトが欲しいのに、自分には開発能力がない
    ので助けていただきたいのです。
    

    そういや先月辺りに reddit経由かなんかで、この手の要望を集めているサイトがあったような (無料でやってくれるわけではないけど)。

    でまあこういう → なぜ高額なadobeを使用するのか? -OKWave ご意見もまたあるわけでして。

    私は今大学で雑誌を作るサークルに入っており、そのサークルではadobeのイラストレーターや
    フォトショップやインデザインを使用しています。しかし、adobeのソフトはどれも高く、とて
    も購入できません。
    
    そこで調べてみたんですが、イラレやフォトショとほぼ同じ機能のフリーソフト(gimpなど)が
    あるんですよね?
    
    それならば、なぜ高いお金を払ってまでadobeを使用するのでしょうか?その何万円かの差ほど、
    機能にも差があるのでしょうか?
    
    質問をまとめると、
    
    1.なぜadobeを使うのか?
    2.フリーソフトを使うことでなにか問題があるか?
    
    やっぱり周りがadobeを使っている以上、私も使うべきなのかな?とは思うのですが・・・。パ
    ソコンやソフトのことは全然わからない初心者ですので、すごく初歩的なことを尋ねるかもしれ
    ませんが、ご容赦ください。
    
    ご回答よろしくおねがいします!
    
    2.
    
    IllustratorやPhotoshopに限らずフリーウェアがどういうものであるかという事を考えれば理解
    出来るのではないでしょうか。そもそもフリーウェアは、使い方の説明等一切しない、インスト
    ールしただけでシステムに重大な損傷を起こしても、使っているうちに不具合が出たとしても作
    者は一切の責任を取らないしサポートもしないという「フリー」も含まれているのです。言い換
    えればフリーウェアとは自己責任で使うものです。(だから私はWindowsユーザーがやたらとMac
    にはフリーソフトが無いとか少ないとか云う事にも、初心者に簡単にフリーウェアを勧める事に
    も多少の疑問を持っています。)一般の企業でサポートもバグフィックスもしないフリーソフト
    を使う事は或る意味自殺行為です。ある程度のスキルが有るとか、趣味でやる分には何ら問題の
    無いものですし、素晴らしいソフトを無償で提供してくれる作者の方には大変感謝ですけどね。
    (お礼のメールくらいは送ろう。)
    

    ■_ redditに訊け: なぜ railsは突如として2008年の whipping boy (負け犬?)に成り下がってしまったのか? (Ask Reddit: Why did rails suddenly become the whipping boy of 2008?)

    programming: Ask Reddit: Why did rails suddenly become the whipping boy of 2008?
    
    Because ROR almost became a cult. Many ROR advocates convinced just about every script kiddie 
    and his dog to join a bandwagon that replaced rational discourse with hype and smugness. Because 
    ROR advocates tried sell Rails as the ultimate computing panacea when in reality it is nothing 
    more than a nice web development system designed to do very little very well under very little 
    load scenarios.
    
    And people just got tired of it.
    
    because it's achieved that ideal mixture of enthusiastic community and poor design?
    
    because it sucks.
    
    Because Oreilly, Apress, the Pragmatic Programmers etc. need to start selling books about 
    the next new language/framework that will solve all of your problems.
    
    Zed started.
    
    Django?
    
    
    
    Rails is the best thing for doing web apps right now and probably will be for a few 
    years to come, it has a bright future.
    
    That being said, some of its users can be arrogant pricks but that's another story :)
    

    ■_ すげーぜ C++!

    MSN相談箱 左辺値の問題
    
    以下の問題がわかりそうでわかりません。
    回答をお願いします。
    
    C++ では、++i(iは整数型の変数とする)は左辺値をもつ式であるが、Javaではそうではない。
    このことを次の2行の文、
    
    j = ++i;
    ++i = j + 1;
    を使って説明しなさい。
    
    bash-3.2$ cat moge.c
    #include <stdio.h>
    int
    main(int argc, char *argv[])
    {
        int i=0;
        ++i = (argc==1 ? 100 : 1000);
    
        printf("i = %d\n", i);
        return 0;
    }
    bash-3.2$ gcc -o c.exe moge.c
    moge.c: In function 'main':
    moge.c:6: error: lvalue required as left operand of assignment
    bash-3.2$ g++ -o cpp.exe moge.c
    bash-3.2$ ./cpp
    i = 100
    bash-3.2$
    

    うぞっ 知らなかったw

    (条件演算子の戻り値(?)がlvalue持てるのは知ってたけど)

    from reddit

    めも

    今日のこれはひどい

    MSN相談箱 VCの描画について
    http://questionbox.msn.co.jp/qa3702466.html
    
    今回は、円についてお聞きしたいです。
    VCのAPI32が前提(MSNは使用しない)です。
    
    円は、 
    
     WM_PAINT
         hDC=BeginPaint(hWnd,&ps);
         Ellipse(hDC,100,100,400,400);
         Endpaint(hWnd,&ps);で書いています。
    
    問題点は、例えば、iの値が、2のときのみ実行したいという場合どうしたらいいですか?
    ifの位置を、hDCの前でいれると、ダイアログボックスが開きません
    Ellipseの一行でかますと、変な円になってしまいます。
    どうしたらいいんでしょう(;;)
    あと、野菜50%・肉30%・魚20%という円グラフにしたい場合、
    ラジアンで分割したあと、どういうふうに、円分割したらいいでしょうか?
    できればアドバイスおねがいします><
      
    第一の課題、円のやつは、できました(^^)
    視点を変えて、ダイアログボックス出てから、
    hDC = GetDC(hWnd);
    Ellipse(hDC,100,100,400,400);
    ReleaseDC(hWnd,hDC);
    でやりました。
    
    WM_PAINTは円では使わないようにしてみました。
    
    第二の課題、円の分割については、午後、アドバイス方法で試してみます。
    15時くらいに、合計が算出されるかな?といったくらいです。
    
    あと、もう一点、円の中に20%とか文字ってかけました?
    
    あと、今やってて思ったんですが、スピンボタンって、100までしかスピンしてくれないのですか?(;;)
    年数のところ、2050とかなったら、スピンしてないです。(><)
    これから、ファイルから割合だして、グラフつくるところです。
    
    回答ありがとうございます。
    
    本来なら自分で調べるべきですが、私の場合、仕事の課題なので、せっぱつまってるのです。(;;)
    
    規定以内に終わらないと、正社員になれなくなる(><)
    
    今、研修中なので・・・。
    
    正社員なったら、質問回数減らしますから、今だけ回答お願いします(><)
    
    #define UDM_SETRANGE 0x0465
     この一文がいました><
    
    30分以上ロスしたー(;;)
    
    円グラフ完成させられない(;;)
    
    というより、普通、#defineいるなんて、反則ですよね?
    あと、このスピン、カンマついてしまうのですが、(1000ごとに)
    これは、はずせないものですか?
    
    はずせないなら、仕方ないですけど。
      

    人事担当者はなにやってんだよッw

    本日のフラゲ

    空想ルンバ
    空想ルンバ
    なーんかOPのときと聴いた印象が違うんだよなあ。
    DJCD さよなら絶望放送(1)
    DJCD さよなら絶望放送(1)
    たった1つの想い
    たった1つの想い
    絶望先生よりこっちの歌の方が気に入った。 ただいまヘビーローテ中

    2008年01月21日

    ■_ Gauche Night

    Karetta|ローソンチケットから1/25前売り開始
    
    
    ローソンチケットでの発売が1/25に決定しました。 (Lコード: 38764)
    
    ローソンチケット: http://l-tike.com/
    
    前売り1,500円です。 
    

    何時開始なんだろう? 0:00? 土曜日発売のチケットだと10:00 AMがほとんどみたいだけど、 25日(金曜日)でも同じなのかな。

    考えてみたらりんかい線って乗ったことNEEEw アクセスマップ TOKYO CULTURE CULTURE:@nifty

    Karetta|書店でのトークイベント
    
    
    日程はまだ未定ですが、書店でトークイベントをやるかも知れません。出演は川合さんとえんどうです。
    
    正式に決まったらまたアナウンスします。 
    

    ■_ 若いって良いなあ(笑)

    Haskell Hackathonやりましょう - 西尾泰和のはてなダイアリー
    
    ちょっ、ご飯食べながらやろうって話していたのはamachangの「yacc作りたい」だったはずなのに、
    なぜかHaskellを作ることになってるっ!しかも場所がサイボウズラボになってる!
    

    わははは、どこで yacc → Haskell変換が起きたんだろうw

    大丈夫、僕の中では、Scheme も yacc も Haskell も区別ついていないから!
    同じような物だよ! (^^;;;
    

    ちょっw

    ■_ なーんか

    Ruby技術者認定試験が2月に国内200カ所で開始,4月から海外135カ国に英語版配信へ:ITpro

    伊藤忠テクノソリューションズ株式会社とプロメトリックは1月21日,Ruby技術者認定試験のコ
    ンピュータを利用したテスト(CBT:Computer Based Testing)配信に関し独占契約を締結した
    と発表した。2月25日から国内200カ所で試験を開始,4月からは海外135カ国に英語版の試験を配
    信する。
    
    

    山吹色のお菓子の匂いがぷんぷんするなあ(気のせい?)。

    ■_ もう○○か××かと

    ケータイソムリエ、今夏から登場…料金プランなど案内 : 経済ニュース : マネー・経済 : YOMIURI ONLINE(読売新聞)

    総務省は今年夏をめどに、携帯電話の販売員を対象に認定資格「ケータイソムリエ」を創設する。料理に
    応じたワインを勧めるソムリエに倣い、料金プランや、有害サイトに接続できなくする「フィルタリング(
    選別)サービス」などに詳しい販売員に「お墨付き」を与える。
    

    「ソムリエ」の語義の拡大解釈もいい加減にしろい。

    まあソムリエに限った話じゃないけどね。

    ■_

    【連載】人材育成の現場から - 組み込みエンジニア育成奮闘期 (1) 新人育成 - ものづくりの魅力ある世界に興味を持たせることから始めよう | エンタープライズ | マイコミジャーナル
    
    
    動くはずのプログラムが動かない - その苦労が大切
    
    新人の育成において、まず大切なことは『設計』『実装』『テスト』という一連のプロセスを身
    をもって体験してもらうことです。このプロセスは、今後何を開発するにあたっても役立つと思
    うからです。各プロセスにおよそどのくらいの工期が必要なのかという見積もりについても、ま
    ずは自分ひとりで考えてもらいます。最初からその工期どおりにうまくいくはずもなく、必ず途
    中で失敗することは分かっているのですが、最初は何も言いません。それは、みずから失敗を重
    ねてこそ、初めて体得できるものがあるからです。もちろん、開発現場を新人に任せるにはリス
    クが伴います。新人の業務進捗を把握し、遅れをリカバリーできる体制は整えています。
    

    D来るか?

    昨日書いたヤツの翻訳か?

      Open Tech Press | プログラマの生産性を高める新たな言語「D」
    
    CやC++が持つ性能の高さとRubyやPythonのような最近のプログラミング言語が持つプログラマの
    生産性の高さとを一つの言語が併せ持つことはできないのだろうか? Zortech C++コンパイラや
    Digital Mars C/C++コンパイラの作者であるWalter Bright氏は、正にその問いを自らに問いか
    けてC++の後継言語である Digital Mars D を作成した。Dは仕事を手早く片付けるために役立つ
    実用的なプログラミング言語で、ちょうど1年前に最初のリリース(バージョン1.0)が公開され
    た。
    
     なぜ新しいプログラミング言語が必要なのだろうか?その理由の一つは、C++があまりに複雑
    だからということだ。C++のすべての機能を覚えることはあまりに困難であるため、たいていの
    C++プログラマは特定の機能群を使用することが習慣となり、それ以外の機能には手を出さなく
    なる。このことはコンパイラにとっては特に問題ではないが、しかし別の機能群に慣れている他
    のプログラマがコードを読もうとしたときには問題になる可能性がある。Dは、重要な機能を省
    略することなく非常に単純化することによってこの問題を回避した。もちろんDの利点はこれだ
    けではない。
    

    昨日、今日で数件 redditにDネタを発見。 Loop Abstractions in D | www.hans-eric.com とか。

    めも

    from reddit


    一つ前のページへ 2008年1月(中旬)
    一つ後のページへ 2008年2月(上旬)

    ホームへ


    Copyright (C) 2007 KIMURA Koichi (木村浩一)
    この文書の無断転載はご遠慮ください(リンクはご自由にどうぞ)。

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