ときどきの雑記帖 ぴゅあ

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

一つ前へ 2011年12月(中旬)
一つ後へ 2012年1月(上旬)

ホームへ

2011年12月31日

■_

C81
幾ら使ったのかは確かめたくないw これでも二つばかりたどり着く前に完売になってしまって買えなかったものとか、 チェックしてたけどなぜかブースに行かなかった(作成したリストが使いづらなかったのが敗因) ところがそれぞれいくつかありました
その1 その2 その3

今回の収穫はこれの本でした→
クルタ計算機: gotcha@ぴっちぶれんどの実験室 (本を作成された方のサイト) このクルタ計算機、和田先生のblogか(アスキーのサイトの)遠藤さんのところで 知ったような覚えがあったんですがそれっぽいのがみつからない。はて? パラメトロン計算機: 古い計算機

こういうのもあったのねー。まるっきりノーマークで気がつかなかった rs6000の日記 : コミックマーケット81 冬コミにAS/400同人誌を頒布します

ワタクシが尊敬するプログラマーの一人であるたいにゃんさんが今回参加されてまして、 しっかり行ってきました。 あそこにいた人がたいにゃんさんだったんだろうか? 恐れ多くて確かめられませんでしたw バグ猫ソフト公式Page

■_

■_ 2012年に向けて

Alloy 本を先行販売(RubyKaigi会場)で買ったのにほとんど読み進んでないとかありますのでとっとと読み終えたい。

GitHub のアカウントをとったもののまだ何も入れてないのでこれもどうにか (とりあえず野良パッチバージョンの GNU grep, sed, gawk のコードをまとめておきたい)

Coq やら Agda2 やら

QE とかいうのをいなばさんから聞いたような覚えがある。

ちょこちょこいじってて気になっているのが PowerShell とか R とか。

正月にオススメ? こういう時期には普段自分の接しているものとは毛色の違ったものに手を出すのが良いと思います。
采配

2011年12月30日

■_

(アレの)準備中。

■_

ruby-dev で正規表現エンジンを入れ替えない?という話題が。

[ruby-dev:45057] [ruby-trunk - Feature #5820][Assigned] Merge Onigmo to Ruby 2.0
[ruby-dev:45058] [ruby-trunk - Feature #5820] Merge Onigmo to Ruby 2.0
[ruby-dev:45059] Re: [ruby-trunk - Feature #5820][Assigned] Merge Onigmo to Ruby 2.0
[ruby-dev:45062] [ruby-trunk - Feature #5820] Merge Onigmo to Ruby 2.0
[ruby-dev:45065] [ruby-trunk - Feature #5820] Merge Onigmo to Ruby 2.0
[ruby-dev:45066] [ruby-trunk - Feature #5820] Merge Onigmo to Ruby 2.0

■_ 帯

ああいうの好きな人いるんだなあ。自分の他にもw

【首桶持って】センゴク 宮下英樹・60番槍【鳥取へ】

675 名無しんぼ@お腹いっぱい [sage] 2011/12/29(木) 13:02:28.04 ID:grAj6LzOO Be:
    やっと無印センゴクの全巻帯付き手に入った
    若干の傷とかはあったけどやっぱあの台詞入った帯欲しかった
    大事にしよう 

676 名無しんぼ@お腹いっぱい [sage] 2011/12/29(木) 15:22:13.39 ID:1+gBQ70L0 Be:
    俺も単行本で唯一帯を取らずにおいてるのってセンゴク無印くらいだよ。
    「史上最も○○で、最も○○な男」ってフレーズと台詞が好き。 

677 名無しんぼ@お腹いっぱい [sage] 2011/12/29(木) 15:56:46.89 ID:grAj6LzOO Be:
    >>676
    だよな
    天正記は裏表紙に入ってるから拘らないけどね 

■_

なんとなく気に入ったのでぺたり。

【Perl,PHP】LLバトルロワイヤル19【Ruby,Python】

776 デフォルトの名無しさん [sage] 2011/12/30(金) 13:27:01.39 ID: Be:
    いまどきの動的型付け言語でももっと型付変数が流行っていいと思うんだ
    だからPerl6頑張れ、超頑張れ、使わないけど 

■_

三連発。

いくらなんでも一休を1休と書くのは勘弁して欲しいw

C言語なら俺に聞け(入門編)Part 94

337 デフォルトの名無しさん [sage] 2011/12/29(木) 23:42:56.45 ID: Be:
    int n = 1234;
    ↑のような数字の各桁を上から取り出す方法はあるでしょうか?
    最初に1を取り出し、次に2を取りだしていくような感じです。
    nの桁数は決まっていません。
    よろしくお願いします。 

338 デフォルトの名無しさん [sage] 2011/12/29(木) 23:44:53.84 ID: Be:
    >>337
    遅くても良いなら sprintf してから一文字ずつチェック 

339 デフォルトの名無しさん [sage] 2011/12/29(木) 23:56:00.70 ID: Be:
    むしろsprintfでいい 

340 デフォルトの名無しさん [sage] 2011/12/29(木) 23:58:20.03 ID: Be:
    桁数が決まってないなら無理。
    実装上の int や long の最大数を制限値とするならできる。

341 デフォルトの名無しさん [sage] 2011/12/30(金) 00:04:26.96 ID: Be:
    いやどっちにしろできるだろ。 

342 デフォルトの名無しさん [sage] 2011/12/30(金) 00:08:42.62 ID: Be:
    >>340
    どういう形であれロジック中で表現されているのに、それを取ることができないと断言するのはいかがなものか。 

343 デフォルトの名無しさん [sage] 2011/12/30(金) 00:16:50.59 ID: Be:
    >>337
    ほらよ。
    http://codepad.org/XhObtVpm 

344 デフォルトの名無しさん [sage] 2011/12/30(金) 00:17:59.15 ID: Be:
    皆さん意見ありがとうございます。
    桁数の方は2桁のときも4桁のときもありますが
    最高は6桁で抑えれそうです。
    引き続きsprintfを調査します。 

349 デフォルトの名無しさん [sage] 2011/12/30(金) 00:25:53.41 ID: Be:
    >>343
    凄いスマートなコードですね。
    ありがとうございます。 

350 デフォルトの名無しさん [sage] 2011/12/30(金) 00:26:13.53 ID: Be:
    http://codepad.org/Mr8A4yOo 

351 デフォルトの名無しさん [sage] 2011/12/30(金) 00:29:22.16 ID: Be:
    まぁsprintf()の中で同じことをやっているわけだが。
    >>350
    せめてlimits使え。 

354 デフォルトの名無しさん [sage] 2011/12/30(金) 00:42:33.87 ID: Be:
    >>348
    >>>343

    f()を呼び出すときに桁数決まってるじゃん。

355 デフォルトの名無しさん [sage] 2011/12/30(金) 00:49:09.72 ID: Be:
    じゃぁ桁数決まってない場合を書いてみろよ。 

376 デフォルトの名無しさん [sage] 2011/12/30(金) 02:53:38.46 ID: Be:
    >>355
    桁数の決まってない数字を出力するから、入力が終わっている状態を示してくれ 

377 デフォルトの名無しさん [sage] 2011/12/30(金) 11:21:47.78 ID: Be:
    >>376
    getchar()が-1を返したら終わり。 

378 デフォルトの名無しさん [sage] 2011/12/30(金) 12:30:43.88 ID: Be:
    1休さんかよw
    屏風の虎w 

379 デフォルトの名無しさん [sage] 2011/12/30(金) 12:32:30.81 ID: Be:
    >>377
    ttp://ideone.com/2jocf 

380 デフォルトの名無しさん [sage] 2011/12/30(金) 13:08:52.51 ID: Be:
    >>379
    それだとnがINT_MAX越えたらAUTO。 

381 デフォルトの名無しさん [sage] 2011/12/30(金) 13:12:14.92 ID: Be:
    INT_MAXを超える桁数ワロタ 

■_

良くある勘違い at stackoverflow

見出しに惹きつけられて本文見に行って、コードを見たところで(ry

php - Recursive regex with garbled text surrounding? Getting "ArrayArray" - Stack Overflow

I asked a similar question, but it was closed for being too broad. Basically, I have a 
bunch of questions like this. I'm hoping just asking one will be easier. I've tried 
some different ways to solve this, but none of them actually work.

I have a text file with a lot of data. The only data that I'm interested in falls 
between two brackets, "(" ")". I'm wondering how to get each 
instance of info that lies between brackets into an array.

The code I'm using right now returns ArrayArray:

  function get_between($startString, $endString, $myFile){
      preg_match_all('/\$startString([^$endString]+)\}/', $myFile, $matches);
      return $matches;
  }
  $myFile = file_get_contents('explode.txt');
  $list = get_between("&nbsp(", ")", $myFile);
  foreach($list as $list){
      echo $list;
  }

You say you want to capture text between brackets, then what are $startstring and 
$endstring in your example? What's more, as @Louis-PhilippeHuberdeau says, your regex 
is wrong anyway. Please expand.

<?php
function get_between($startString, $endString, $myFile){
  //Escape start and end strings.
  $startStringSafe = preg_quote($startString, '/');
  $endStringSafe = preg_quote($endString, '/');
  //non-greedy match any character between start and end strings. 
  //s modifier should make it also match newlines.
  preg_match_all("/$startStringSafe(.*?)$endStringSafe/s", $myFile, $matches);
  return $matches;
}
$myFile = 'fkdhkvdf(mat(((ch1)vdsf b(match2) dhdughfdgs (match3)';
$list = get_between("(", ")", $myFile);
foreach($list[1] as $list){
  echo $list."\n";
}

I did this and it seems to work. (Obviously, you'll need to replace my $myFile 
assignment line with your file_get_contents statement.) A few things:

A: Variable replacement won't occur with single-quotes. So your preg_replace_all 
regular expression won't work as a result. As it literally adds $startString to your 
expression instead of (. (I also removed the check for } at the end of the matched 
string. Add it back in if you need it with \\} just before the ending delimiter.)

B: $list will be an array of arrays. I believe by default, index zero will contain all 
full matches. index one will contain the first subpattern match.

C: This only works so long as $endString will not ever be found inside of a subpattern 
you are attempting to match. Say, if you expect (matc(fF)) to give you matc(fF), it 
won't. It'll give you match(fF. You'll need a more powerful parser if you want to get 
the former result in this case.

Edit: The get_between function here should work with &nbsp;( and )} as well, or 
whatever else you'd want.

preg_match_all('/\$startString([^$endString]+)\}/', $myFile, $matches); は勘弁して欲しかった

■_

■_ 日経ソフトウエアの新連載

call by value と call by reference (と call by object (sharing)) をきちんと説明しようとしてた

2011年12月29日

■_

三日連続。これまでちと色々無理しすぎたかも。 入力と出力について考えないといかんねえ。

久しぶりに焼肉を堪能。

池袋のジュンク堂に某イベントの参加登録をしたついでに先行販売されていたものを購入 (本当は順序は逆) ANSI C/ISO C99対応と表紙にあるのだけど、C11が決まった後だけにちと残念な気がしないでもない。 まあC11がどうなるか(普及するか)はわかんないけど
[標準] C言語重要用語解説 <ANSI C/ISO C99対応>

一通り読んだあとでまた何か書くかも。

■_

以前と比べればそれなりに読む速度も上がってるとは思うんだけど、 まだまだ日本語に比べるときついですねえ。 というわけで目をつけたけど時間がなくて本文はまだ見てないもの。

■_ Can you explain why ++[[]][+[]]+[+[]] = 10

例によって先越されてますが

javascript - Can you explain why ++[[]][+[]]+[+[]] = 10 - Stack Overflow


++[[]][+[]]+[+[]]

is valid and return "10" in JavaScript (more example here: http://sla.ckers.org/forum/read.php?24,33349,33405 ).

これは JavaScript として vaild なもので、「10」を返します

Can you explain why? I don't understand what's happening here.

なぜそうなるのかを説明できますか?
わたしは何が起こっているのか理解できませんでした。


Start by understanding that +[] casts an empty array to 0... then waste an afternoon... ;)

+[] が空の配列を 0 にキャストしているのを理解することから始めましょう。
そのあとは、午後の時間を使って潰して… :)

Related stackoverflow.com/questions/4170978/explain-why-this-works .

If we split it up, the mess is equal to:

そのへんてこなものを分割できるなら次のものと等価です

++[[]][+[]]
+
[+[]]

In JavaScript, it is true that +[] === 0. + converts something into a number, and in 
this case it will come down to +"" or 0 (see specification details below).

JavaScript では +[] === 0 は真であり、+ はなにか (something) を数値へと変換します。
そして今回の例の場合、+"" か 0  になります

Therefore, we can simplify it (++ has precendence over +):
したがって、このように単純化できます(++ は + よりも優先順位が高い):

++[[]][0]
+
[0]

Because [[]][0] means: get the first element from [[]], it is true that:
[[]][0]  は [[]] の先頭の要素を得ることを意味しますから、以下のことが成り立ちます


    [[]][0] returns the inner array ([]). Due to references it's wrong to say [[]][0] === [],
    but let's call the inner array A to avoid wrong notation.
    [[]][0] は内側にある配列 [] を返します。
    [[]][0] === [] とすることは間違っていますが、この内部配列を間違った記法を使わずに
    A と呼ぶことにしましょう。

    ++[[]][0] == A + 1, since ++ means 'increment by one'.
    ++ は "1増やす"ことなので、 ++[[]][0] == A + 1 です。

    ++[[]][0] === +(A + 1); in other words, it will always be a number (+1 does not necessarily
    return a number, whereas ++ always does - thanks to Tim Down for pointing this out).
    別の表現をすると ++[[]][0] === +(A + 1) です。
    これは常に数値となります
    (+1 は数値を返すのに必須ではありませんが、++ は常に必要です
    これを指摘してくれた Tim Down に感謝)

Again, we can simplify the mess into something more legible. Let's substitute [] back for A:

繰り返しますが、例のコードはより legible な単純なものにできます。
A を [] に戻してみましょう

+([] + 1)
+
[0]

In JavaScript, this is true as well: [] + 1 === "1", because [] == "" (joining an empty array), so:
JavaScript では [] == "" (空配列の join) なので [] + 1 は "1" となります。


    +([] + 1) === +("" + 1), and
    +("" + 1) === +("1"), and
    +("1") === 1

Let's simplify it even more:
さらに単純にしましょう

1
+
[0]

Also, this is true in JavaScript: [0] == "0", because it's joining an array 
with 1 element. Joining will concatenate the elements separated by ,. With one element, 
you can deduce that this logic will result in the first element itself.

JavaScript では [0] == "0" が真です。なぜならひとつの要素を持った配列の join だからです。
join は , で区切って複数の要素を連結するものです。
要素がひとつの場合、これは第一要素それ自身となるロジックを deduce できます。

So, in the end we obtain (number + string = string):
ですから最終的にはこうなります (数値 + 文字列 = 文字列)

1
+
"0"

=== "10" // Yay!

Specification details for +[]:
+[] に関する仕様の詳細

This is quite a maze, but to do +[], first it is being converted to a string because that's what + says:


    11.4.6 Unary + Operator (単項の+演算子)

    The unary + operator converts its operand to Number type.

    The production UnaryExpression : + UnaryExpression is evaluated as follows:

        Let expr be the result of evaluating UnaryExpression.

        Return ToNumber(GetValue(expr)).

ToNumber() says:

    Object

    Apply the following steps:
    以下の手順を適用します:

        Let primValue be ToPrimitive(input argument, hint String).

        Return ToString(primValue).

ToPrimitive() says:

    Object

    Return a default value for the Object. The default value of an object is retrieved by
    calling the [[DefaultValue]] internal method of the object, passing the optional hint
    PreferredType. The behaviour of the [[DefaultValue]] internal method is defined by this
    specification for all native ECMAScript objects in 8.12.8.

[[DefaultValue]] says:

    8.12.8 [[DefaultValue]] (hint)

    When the [[DefaultValue]] internal method of O is called with hint String, the following
    steps are taken:

        Let toString be the result of calling the [[Get]] internal method of object O with
        argument "toString".

        If IsCallable(toString) is true then,

    a. Let str be the result of calling the [[Call]] internal method of toString, with O as
       the this value and an empty argument list.

    b. If str is a primitive value, return str.

The .toString of an array says:

    15.4.4.2 Array.prototype.toString ( )

    When the toString method is called, the following steps are taken:

        Let array be the result of calling ToObject on the this value.

            Let func be the result of calling the [[Get]] internal method of array with
            argument "join".

        If IsCallable(func) is false, then let func be the standard built-in method 
        Object.prototype.toString (15.2.4.2).

        Return the result of calling the [[Call]] internal method of func providing array
        as the this value and an empty arguments list.

So +[] comes down to +"", because [].join() === "".

Again, the + is defined as:

    11.4.6 Unary + Operator

    The unary + operator converts its operand to Number type.

    The production UnaryExpression : + UnaryExpression is evaluated as follows:

        Let expr be the result of evaluating UnaryExpression.

        Return ToNumber(GetValue(expr)).

ToNumber is defined for "" as:

    The MV of StringNumericLiteral ::: [empty] is 0.

So +"" === 0, and thus +[] === 0.
>jsshell
js> +[]
0
js> ++[[]][+[]]+[+[]]
10
js>

おー、本当だ。

■_ Effective DoS attacks against Web Application Plattforms

これもすぐにいろいろなところが詳しく解説したりするでしょう

Cryptanalysis » Effective DoS attacks against Web Application Plattforms – #hashDoS [UPDATE2]


Effective DoS attacks against Web Application Plattforms – #hashDoS [UPDATE2]
December 28th, 2011 Erik Tews	Leave a comment Go to comments

Julian Wälde (zeri) and Alexander Klink (alech) presented a very nice way how to bring 
down many popular websites at 28C3. The idea is quiet simple, effective and general. 
Many programming languages, especially scripting languages, frequently use hash tables 
to store all kinds of data.

略
Copyright © 2007-2011 Cryptanalysis

■_

■_

さて二日目はどうするか

2011年12月28日

■_

二日連続で撃沈。 んで今年のオツトメも今日までと。

TV が年末な番組編成になってたりで夜起きているキリョクが(ry。 ってまあ入力過多なんだよなあ。どうにかしないと

■_

■_ 浮動小数点数

いつものごとく。

くだすれFORTRAN(超初心者用)その5 

681 デフォルトの名無しさん [sage] 2011/12/09(金) 23:14:31.80 ID: Be:
    小数点以下の数字の量を増やすと関わった覚えのない数字が出てきます
    1.0000000038
    こんな感じに出力されます
    どうすれば改善できますか? 

682 デフォルトの名無しさん [sage] 2011/12/10(土) 00:22:53.11 ID: Be:
    >>681
    それは単精度なら、本来有効桁が7~8しかないから。
    無理に桁数多く書かせることはできるが、それには意味がない。

    どうしても意味ある数字を出したければ倍精度にすれば、14~15桁有効桁でおk。 

683 デフォルトの名無しさん [sage] 2011/12/10(土) 13:53:49.16 ID: Be:
    a=1.0
    write(*,*) a
    a=1.0d0
    write(*,*) a

    で微妙に違う値が出る時があるよね。 

684 デフォルトの名無しさん [sage] 2011/12/10(土) 14:59:00.93 ID: Be:
    IBMの16進浮動小数の時代を思いだすんだ。 

685 デフォルトの名無しさん [] 2011/12/18(日) 01:18:57.88 ID: Be:
    >>683
    なんで?このテーマで卒論書けるかな?! 

686 デフォルトの名無しさん [sage] 2011/12/18(日) 10:42:25.00 ID: Be:
    「浮動小数点のCPU内部でのとりまわしの現状について」
    ・・・まじめにやれば、ハード・ソフトそれぞれで
    いろいろする事・知っておかないといけない事があるから、卒論ならいいんじゃない?
    学科にもよるけど、文献調査+基礎的な試行錯誤を一人でできる事、ができれば
    大学院に行く前の基礎技術習得なり就職前に大学で経験しておくべき経験としての
    卒論なら万々歳。

    博士課程まで行くつもりで学振を年頭に修士一年目に論文出したい子が
    学部4年から論文になりそうな事をせっかちに始める人が多いけど、
    業界の基本・基礎的な部分にじっくり思考や文献調査に時間かけたことが無い子が多い。
    よくない。 

687 デフォルトの名無しさん [sage] 2011/12/18(日) 15:16:23.25 ID: Be:
    >>685
    単精度と倍精度の差でしょ?
    何をテーマに研究するの? 

688 デフォルトの名無しさん [] 2011/12/19(月) 23:18:59.58 ID: Be:
    ウィキペディアに乗ってそうだな 

689 デフォルトの名無しさん [sage] 2011/12/25(日) 15:57:41.78 ID: Be:
    数値フォーマットはめんどい。

    今は IEEE754 で統一されたから見えにくいが、Fortran90にやたらと精度絡みの関数が入っているのも、
    かつて数値フォーマットが機種依存で千差万別だった頃(66,77時代)に数値フォーマット問題で散々苦労したから。
    66,77 の頃広く使われた数値フォーマットの必要な情報を得るための MACHAR というサブルーチンは、今でも
    LAPACK、Numerical Recipes、IMSL とかあちこちに残っている。
    それで求めていた値を Fortran90 では組み込み関数で取れるようになった。


    Kahanの数値フォーマット策定思い出話論文を読んで、もうちょっと調べて
    http://www.dr-chuck.com/dr-chuck/papers/columns/r3114.pdf
    変な例としてこの辺をまとめれば卒論くらいにはなるのでは。
    http://software.intel.com/en-us/forums/showpost.php?p=12904
    http://software.intel.com/en-us/forums/showpost.php?p=12907
    http://software.intel.com/en-us/forums/showpost.php?p=12908
    http://software.intel.com/en-us/forums/showpost.php?p=12911
    記憶がはっきりしないが、同じような話題が数年前にスクリプト言語方面で話題になっていた気がするし。

    非正規数とアンダーフローの問題も数年前に話題になったので、まとめにいいかも。 

690 デフォルトの名無しさん [sage] 2011/12/25(日) 16:02:46.56 ID: Be:
    >Kahanの数値フォーマット策定思い出話や論文を読んで、もうちょっと調べて
                             ~~
    Kahanのサイト
    http://www.cs.berkeley.edu/~wkahan/ 

691 デフォルトの名無しさん [sage] 2011/12/25(日) 17:27:18.26 ID: Be:
    大学でFORTRANを習っています。
    プログラミング界だとどんな位置付けですか? 

692 デフォルトの名無しさん [] 2011/12/25(日) 18:00:07.19 ID: Be:
    >>691
    fortranは総理大臣
    c++は校長先生
    phpは地方公務員
    htmlは乞食 

693 デフォルトの名無しさん [sage] 2011/12/25(日) 18:55:11.43 ID: Be:
    FORTRAN教えるようなとこなら真面目にやっといて損はないよ 

694 デフォルトの名無しさん [sage] 2011/12/25(日) 23:52:44.69 ID: Be:
    693に同意。 

Kahanの数値フォーマット策定思い出話論文はあらかた訳したんだけど なかなかフィニッシュにもっていけない(その手のものが他にもいくつか○| ̄|_)んで いいかげんどうにかしたいなあ。 やる気を起こすために寄付を募るとか(マテ

■_

後で埋めるかもしれない

2011年12月27日

■_

ねむいのよー

■_

Kidsruby.com

■_ ruby-core

面白そうな話題が。

[ruby-core:41799] Best way to separate implementation specific code?
[ruby-core:41800] Re: Best way to separate implementation specific code?
[ruby-core:41801] Re: Best way to separate implementation specific code?
[ruby-core:41811] Re: Best way to separate implementation specific code?
[ruby-core:41817] Re: Best way to separate implementation specific code?

[ruby-core:41813] [ruby-trunk - Feature #5474] keyword argument
[ruby-core:41818] Re: [ruby-trunk - Feature #5474][Assigned] keyword argument
[ruby-core:41822] Re: [ruby-trunk - Feature #5474][Assigned] keyword argument

■_

■_

2011年12月26日

■_

あれとかこれとか

■_

InfoQ: Javaの未来についてのNeal Gafter氏とのディスカッション なんか見覚えがあまりないなあと思ってよく見たら 原文(投稿日:2011/09/14)へのリンク 元記事は9月のだった。

んでちと気になったところが

InfoQ: Javaの未来についてのNeal Gafter氏とのディスカッション

動的言語をサポートするために期待していることはたくさんあります。末尾再帰もその一つです。
それは大きな変化ではありませんが、いつくかのプログラミング言語にとっては大きな違いを生
み出すでしょう。

セグメンテッドスタックもそうです。現在、これはJavaとC#両方の問題です。これらのプラット
フォームは、CやC++といったネイティブプラットフォーム上の多くの信頼性に関する問題を取り
除いています。インデックスの境界外アクセスエラーが起こることはありません。なぜなら、そ
れはチェックされ、例外がスローされるからです。メモリ管理を自分自身で行わないため、解放
済みのメモリ領域や未確保のメモリ領域に書き込んでしまうこともありません。メモリ管理はガ
ベージコレクタの仕事です。しかし、これらのプラットフォームが今のところ行わないことの一
つが、スタックオーバーフローの処理です。スタックオーバーフローはエラーがあるからといっ
て常に発生するわけではありません。想定していなかった無限再帰がプログラムに含まれていた
からといって、常に起こるわけではないのです。

自然と再帰になるような箇所があるため、スタックオーバーフローは時々発生します。
int i = 1+1+1+1と数千回繰り返すと、Javaコンパイラは簡単にクラッシュします。セマンティック
アナライザがそれを解析しようとしている時、もしくはパーサがそれをパースしようとしている時に、
それはスタックを破壊するでしょう。そしてプロセスがクラッシュします。

ご存知の通り、そこからリカバリできません。"もっとスタックを確保してもう一度やり直
そう"と言いながら、対処することになります。問題は、確保すべきスタックの量を事前に
知ることができないということです。

InfoQ: A Discussion With Neal Gafter on the Future of Java

And so that I think is a very useful direction, to have a dynamic meta-object protocol.

There are a lot of things I'd love to see in the VM to support dynamic language, and yes
tail recursion is one of them. It's not a big one, but for some programming languages it
makes a big difference.

Also segmented stacks. Right now, this is a problem both for Java and C#. These platforms
remove a lot of the reliability issues with native languages like C and C++. You don't have
index out of bounds errors occurring because your indices are checked and you get an
exception. You can't write over memory that's been freed, or write into unallocated memory
and so on, because you can't manage the memory yourself; the garbage collector does it for
you. But one of the things that these platforms don't do very well right now is deal with
stack overflow. And stack overflow doesn't always occur because of errors; it doesn't always
occur because you have some infinite recursion that you didn't intend to have.

Stack overflow sometimes occurs because you have something that is naturally recursive. I
work with compilers and it's easy to crash the Java compiler just by writing, you know,
int i = 1+1+1+1 and just do that a few thousand times. And the semantic analyzer will be
trying to analyze that, or the parser will be trying to parse it and it will just blow the
stack. And what happens is, the process crashes.

You know, there's no good recovery from that. And you can fix it by [saying], 
"Well, we start over again but I'll just allocate more stack". The problem 
is, you can't necessarily know ahead of time how much stack to allocate to any given 
thread.

int i = 1+1+1+1と数千回繰り返すと というのは末尾のセミコロンがないし、 この後にも + 1 がずーーーっと連なったものを言ってるのだと思うけど …がないのですぐにはそうとわからなかった(^^; 原文からしてint i = 1+1+1+1 and just do that a few thousand times. なんだけど and just do that ~ をどう解釈するのかよくわからん。

■_ バッファオーバーフロー

Classic Buffer Overflow in FreeBSD Telnetd | TheXploit | Security Blog

A Textbook Buffer Overflow: A Look at the FreeBSD telnetd Code

Wow, I feel real sorry for the FreeBSD guys having to announce a remotely exploitable 
vulnerability in their Telnet Daemon on Christmas Eve! Let's just hope that nobody 
uses Telnet anymore.

クリスマスイブに (FreeBSD の)telnet デーモンの remotoly exploitable vulnerbility
(外部からexploit可能な脆弱性)を FreeBSD guys へお知らせしなければならないことを
まことにもって申し訳なく思う。
telnet を使っている人なんてもういないことを願うばかりだ。

The Classic, Oh So Classic, Overflow


The buffer overflow occurs in encrypt.c and really is your textbook example of a buffer overflow.
The interesting part is that this code hasn't been touched in over 3 years! As Colin Percival
pointed out in the comments, this bug has been in telnetd for over 20 years!

telnetd.c & state.c

It all starts in telnetd.c which receives input from the network and passes it to state.c which
is a little “state machine” that directs the input to the proper method call by pulling a
character from the data received and walking through a huge case statement.

ネットワークから入力を受け取って、受け取ったデータからキャラクター一つを pull して巨大なcase 文
を walking through し適切なメソッド呼び出しへ入力を direct する 小さな“状態機械”である state.c
に渡している telnetd.c ですべては始まります。

In the case of encryption negotiation, the case TELOPT_ENCRYPT is reached and eventually the
subcase ENCRYPT_ENC_KEYID is reached. ‘subpointer’ is data supplied by the client minus the
2 bytes used for control flow of the state machine. encrypt_enc_keyid passes the ‘subpointer’
data directly to the encrypt_keyid function

encryption negotiation の場合、case TELOPT_ENCRYPT に到達してさらに eventually に
subcase ENCRYPT_ENC_KEYID に到達します。“サブポインター”はクライアントから渡されたものより
状態機械の制御フローに使われた分の二バイト短いデータです。
encrypt_enc_keyid はこの“サブポインター”データを encrypt_keyid 関数に直接 pass します。

  ...
  case ENCRYPT_ENC_KEYID:
      encrypt_enc_keyid(subpointer, SB_LEN());
      break;
  ...

encrypt.c

encrypt.c defines a key_info struct with a fixed length buffer of 64 bytes to hold the 
key id passed by the client.

encrypt.c ではクライアントから渡された key id を保持するための
64バイトの固定長バッファーをもった key_info 構造体を定義しています。

  #define MAXKEYLEN 64
 
  static struct key_info {
      unsigned char keyid[MAXKEYLEN];
      int keylen;
      int dir;
      int *modep;
      Encryptions *(*getcrypt)();
  } ki[2] = {
      { { 0 }, 0, DIR_ENCRYPT, &encrypt_mode, findencryption },
      { { 0 }, 0, DIR_DECRYPT, &decrypt_mode, finddecryption },
  };

However, the encrypt_keyid method happily copies the passed data into the key_info 
struct using memcpy without any restriction on the length specified by MAXKEYLEN

しかしこの encrypt_keyid メソッドは、渡されたデータを memcpy を使って
key_info 構造体に MAXKEYLEN で指定された長さによる制限なしに
happily にコピーしてしまいます。

  static void
  encrypt_keyid(struct key_info *kp, unsigned char *keyid, int len)
  {
      ...
      } else if ((len != kp->keylen) || (memcmp(keyid,kp->keyid,len) != 0)) {
      /*
       * Length or contents are different
       */
      kp->keylen = len;
      memcpy(kp->keyid,keyid, len);
      if (ep->keyid)
          (void)(*ep->keyid)(dir, kp->keyid, &kp->keylen);
      ...
  }

It's a bit surprising that this code has been around for 3 years 20 years without 
anyone noticing. You'd think that a simple buffer overflow like this could easily be 
spotted with automated tools. The sad thing too is that Mac OS X is also remotely 
exploitable according to their posted source.

二十年もの間誰もこのコードに気づかずにいたということには驚かされます。
あなたはこのような単純なオーバーフローは
自動化されたツールを使えば簡単に指摘できるだろうと思うことでしょう。
sad すぎるのは彼らのポストしたソースに従えば
Mac OS X も remotely exploitable だということです。


■_

泳ぐやる夫シアター やる夫で学ぶ第一次世界大戦  第二十四夜「第三次イープル戦」

あとでこの辺もチェックしておこう。 歴史群像アーカイブの内容は雑誌連載のときに読んでいるはずだけど○| ̄|_
第一次世界大戦 下 (歴史群像アーカイブVol.21) 第一次世界大戦 上巻 (歴史群像アーカイブVol.20)
第一次世界大戦 上巻 (歴史群像アーカイブVol.20) 第一次世界大戦〈上〉 第一次世界大戦〈下〉

■_

■_

2012年に向けていろいろと考えていたり。

2011年12月25日

■_

なんでもかんでも「面白い」にしちゃうのは自分のことながらボキャブラリ貧困じゃ喃。

新聞の書評欄が年末ということだからか今年印象に残ったもの3点てな感じの企画を複数の新聞でやっていた。 技術書でそれやると何がいいかなあと考えたが、 今年出版されたのを調べるのが面倒くさいのでボツ。

[レポ] シリコンバレーのCEOたちが明かす「日本の技術屋が世界で通用する」理由 -Innovation Weekend Grand Finale 2011 |エンジニアtype のスライド 4.にある 「Have a purple cow (Seth Golden)」ってのが気になったんだけど Purple Cow: Transform Your Business by Being Remarkable - Wikipedia, the free encyclopedia よくわからんな。

いなばさんの

■_

Five Tips for Floating Point Programming - CodeProject® reddit で取り上げられてたので見てみたけど元記事は何年か前のだった。 いやまあ新しいものでなきゃだめだということはないのだけど ちと興が削がれた。

■_ コードレビュー

こういうのが(公開されて)見られる(読める)ってのはいい時代だなあ "Another World" source code review と思ったら The source code of "Another World' was never officially released nor leaked. って?

"Another World" source code review

Fabien Sanglard's non-blog

"Another World" Code Review

December, 23rd 2011

Introduction

I spent two weeks reading and reverse engineering further the source code of Another World
("Out Of This World" in North America). I based my work on Gregory Montoir's
"binary to C++" initial reverse engineering from the DOS executable.

I was amazed to discover an elegant system based on a virtual machine interpreting 
bytecode in realtime and generating fullscreen vectorial cinematic in order to produce 
one of the best game of all time.

All this shipping on a 1.44MB floppy disk and running within 600KB of RAM: Not bad for 
1991 ! As usual I cleaned up my notes, it may save a few hours to someone.

But...What source code ?!

The source code of "Another World" was never officially released nor leaked. Some 
people were so passionate about this groundbreaking game that they reverse engineered 
the DOS executable.

"Another World" のソースコードは公式に公開されたこともリークしたこともありません。
一部の人がこの groudbreaking game にとても熱心でした
DOSの実行ファイルのリバースエンジニアリング


This was possible partly because the binary was small (20KB). Why so small? Because 
ANOTHER.EXE was not the game itself but just a virtual machine:

これが可能だったのはそのバイナリーが小さかった(20KB)からですが、なぜそんなに
小さかったのでしょうか?
それは、ANOTHER.EXE がゲームそのものではなくて単なる仮想機械であったからです。

    Hosting bytecode.
    Providing system calls.

The bytecode performs all the game logic with its own opcodes but uses syscalls for 
"heavy" stuff like drawing, playing music, sound and managing assets.

To implement only the virtual machine for the target OS reduced the effort and the 
game was broadly ported to more than a dozen platforms:

    1991 Amiga, Atari ST
    1992 Apple IIGS, DOS, SNES, Mega Drive
    1993 3DO
    2004 GameBoy Advanced
    2005 Windows XP, Symbia OS, Windows Mobile
    2011 iOS

Every time only the virtual machine had to be compiled to the target OS: The bytecode 
remained the same !

毎回必要なのはターゲットOS用にコンパイルされた仮想機械だけで、バイトコードは同じものでした!

Architecture

The executable is 20KB. It can be summarized as:
実行ファイルは20KBで、次のようにまとめられます:

We can see four modules:

    Virtual Machine: Maestro of the entire system.
                     システム全体の maestro (ここでは指揮者?)

    Resource Manager: Loads resources from the floppy disk when the vm request them.
                      vm がリクエストしたときにフロッピーディスクからリソースをロードする

    Sound/Music mixer: Makes noises upon request from the vm.
                       vm からのリクエストに応じてノイズを生成する

    Renderer: Reads and Renders vertices upon request from the vm. Read vertices
              from the memory segments.

reddit での反応から。

"Another World" code review : programming

This guy has been putting out some fantastic articles as of late.


Thanks :) !


Damn, I felt so stupid after reading this... I really am a mediocre programmer :(


How long have you been writing software? Compare with the length of time the guy 
writing the article has been doing this...

Software development is a very strange skill, in that really significant amounts of 
experience are woefully under-appreciated.

Wow, that's awesome.

I'm totally creating a VM for my next game.

Famous. Last. Words.


(psst: LUA!)


Apple ][ users will also probably remember Pascal UCSD, which was built on a VM called 
the P System in 1978, and which gave us the Wizardry series (on top of being a pretty 
cool development environment for its time).

The early Wizardries were also ported to NES and SNES. Now, I'm not sure but I think I 
have read about them porting the UCSD Pascal to Nintendo devices to make the ports. 
Which, of course would make sense but it sounds kinda cool anyway.

■_

Beginner's Guide to Linkers

Beginner's Guide to Linkers
リンカーのビギナー向けガイド

This article is intended to help C & C++ programmers understand the essentials of what
the linker does. I've explained this to a number of colleagues over the years, so I
decided it was time to write it down so that it's more widely available (and so that I
don't have to explain it again). [Updated March 2009 to include more information on the
pecularities of linking on Windows, plus some clarification on the one definition rule.]

本 article はリンカーが行っていることの essentials を
C や C++ のプログラマーが理解するのを助けることを目指しています。
わたしは何年もの間それをたくさんの学生たちに説明してきました。
ですからそれを書き下してより広く availabe にしようとわたしは決心したのです
(そうすればわたしは再度説明する必要がなくなります)。
2009年3月更新
Windows におけるリンクの pecularities についてのさらなる情報



A typical example of what triggers this explanation is when I help someone who has a link
error like:

この explanation の引き金となる典型的な例は
次のようなリンクエラーを抱えた誰かを助けたときです


    g++ -o test1 test1a.o test1b.o
    test1a.o(.text+0x18): In function `main':
    : undefined reference to `findmax(int, int)'
    collect2: ld returned 1 exit status

If your reaction to this is 'almost certainly missing extern "C"' then you 
probably already know everything in this article.

Table of Contents

    Naming of Parts: What's in a C File
    What The C Compiler Does (C コンパイラーが行っていること)
        Dissecting An Object File 
    What The Linker Does: Part 1 (リンカーが行っていること パート1)
        Duplicate Symbols  (重複したシンボル)
    What The Operating System Does (OSが行っていること)
    What The Linker Does: Part 2 (リンカーが行っていること パート2)
        Static Libraries
        Shared Libraries
        Windows DLLs
            Exporting Symbols
            .LIB and Other Library-Related Files
            Importing Symbols
            Circular Dependencies
    Adding C++ To The Picture
        Function Overloading & Name Mangling (関数のオーバーロードと名前のマングリング)
        Initialization of Statics
        Templates
    Dynamically Loaded Libraries
        Interaction with C++ Features
    More Details

Naming of Parts: What's in a C File

■_

■_

メモ的に。

関数型プログラミング言語Haskell Part16
789 デフォルトの名無しさん [] 2011/12/22(木) 22:55:08.11 ID: Be: 
 モナドって大した概念なの? 
 
790 デフォルトの名無しさん [sage] 2011/12/22(木) 22:59:36.72 ID: Be: 
 ものごとを抽象化するための仕組みとしては大したもんだよ 
 
791 デフォルトの名無しさん [] 2011/12/23(金) 10:28:44.71 ID: Be: 
 >>790 
 なんかいい例希望 
 モナドはものごと全部を抽象化するんじゃないよね? 
 
793 デフォルトの名無しさん [] 2011/12/23(金) 12:02:29.11 ID: Be: 
 >>790 >>791 
 そうだな。なんでも抽象化できるんならこれまた意味不明になるし。 
 だいたい、何なんだよ抽象化って。 
 
794 デフォルトの名無しさん [sage] 2011/12/23(金) 17:44:45.43 ID: Be: 
 モナドによる抽象化ってのは、だいたい(Monad m) =>で始まる型のある関数を書くこと 
 具体例はControl.Monadとか見れば 
 
795 デフォルトの名無しさん [sage] 2011/12/23(金) 17:52:14.34 ID: Be: 
 それで、何をどう抽象できて、何は抽象できないの? 
 モナドで抽象する前と後とで何が変わるの? 
 
797 デフォルトの名無しさん [sage] 2011/12/23(金) 18:16:45.13 ID: Be: 
 >>795 
 Control.Monadにあるようなものは抽象化できるし、 
 (Monad m) =>で書けなさそうなものは抽象化できない 
 言葉で言われて分かる類の問題じゃないから具体例を見たり書いたりして慣れるしかないよ 
 
 >モナドで抽象する前と後とで何が変わるの? 
 関数の型が変わって任意のモナドに対して使えるようになる。たとえば、 
 foreach :: [a] -> (a -> IO ()) -> IO () -- foreach xs f はxsの各要素に対してfを実行 
 をモナドに関して抽象化すれば、 
 forM_ :: (Monad m) => [a] -> (a -> m b) -> m () 
 になって、IO以外でも使えるようになる 
 
799 デフォルトの名無しさん [sage] 2011/12/23(金) 18:22:51.88 ID: Be: 
 いい例かどうか分からないが 
 http://blog.sigfpe.com/2006/08/you-could-have-invented-monads-and.html 
 http://www.haskell.org/haskellwiki/Monads_as_containers 
 http://www.haskell.org/haskellwiki/Monads_as_computation 
 
800 デフォルトの名無しさん [sage] 2011/12/23(金) 18:24:52.49 ID: Be: 
 コードが書いてあるあたりだけでもざっと見ればいいよ 
 
801 デフォルトの名無しさん [] 2011/12/23(金) 18:26:57.57 ID: Be: 
 >>797 
 サンクス 
 
802 デフォルトの名無しさん [sage] 2011/12/23(金) 18:32:22.82 ID: Be: 
 >>797 
 それってオブジェクト指向でメソッドの引数の型を 
 IO型からObject型にするのと、どう違うの? 
 
803 デフォルトの名無しさん [sage] 2011/12/23(金) 18:47:13.75 ID: Be: 
 メソッドの引数に限定する意味が良くわからないが 
 bindとかreturnというメソッドを持ったIO型を一般化して、 
 Monadという抽象クラスから派生するようにしたら便利なのと一緒。 
 
804 デフォルトの名無しさん [sage] 2011/12/23(金) 18:53:48.59 ID: Be: 
 >>802 
 色んなものの「共通する性質」や「共通する関係」を抜き出し、 
 具体的な実態では無くその性質や関係のみで以て語るのが「抽象化」だから、 
 抽象化するという意味は同じ 
 
 どう抽象化するかという点で、IO型からObject型へとMonadへとで違いがでる 
 
 Haskell のモナドは (m を Monad クラスのインスタンスとして) 
 forall a b. m a -> (a -> m b) -> m b 
 forall a b. m a -> m b -> m b 
 a -> m a 
 String -> m a 
 という4つの「演算で抽象化」してる(うち2つだけで十分だが) 
 
 特にモナド同士の演算がまたモナドになるという性質と、 
 モナドの外からはモナドの具体的な実態は見えないという性質が特徴的だから、 
 そういう性質が活かせるところでもてはやされる 
 
 オブジェクト指向のObject型がどういう性質の抽象化なのかは忘れた 
 
806 デフォルトの名無しさん [] 2011/12/23(金) 19:27:53.45 ID: Be: 
 >>799 
 ありがとう。読んでみる。 
 
807 デフォルトの名無しさん [sage] 2011/12/23(金) 19:37:49.40 ID: Be: 
 >>802 
 その例だと、内部でやってることもだいたい同じ 
 実際の型に応じて実装が選ばれる 
 実装を選ぶタイミングがコンパイル時か実行時かは違う 
 
 型クラスは ad-hoc polymorphism を使いやすくしたものでオーバーロードの親戚 
 OOPのほうはsubtype polymorphismといって、部分かなり違う部分がある 
 例えばsubtype relationが推移律をみたすみたいな強い性質がある 
 subtypeがあるとどうなるかは、Scalaが壮大な社会実験中 
 
811 デフォルトの名無しさん [] 2011/12/23(金) 21:51:38.33 ID: Be: 
 モナドって、ひょっとしてHaskellにおけるデザインパターンのことかい? 
 
813 デフォルトの名無しさん [sage] 2011/12/23(金) 21:58:23.43 ID: Be: 
 >>811 
 モナドの方が抽象度高いけど似たようなもん(だと思ってる) 
 
826 デフォルトの名無しさん [sage] 2011/12/24(土) 05:44:34.49 ID: Be: 
 >>804 , >>807 
 ありがとう。 
 でも、その理屈でIO()をモナドに抽象できるのだとすると、 
 
 「IO()で提供されていた種々の関数は全て、 
 モナドで提供されている演算子に置き換え可能である」 
 
 という前提条件が存在すると思うのだけど、どうだろう? 
 
 この条件が成立しないと、結局forallはIO()型の値を必要とするよね。 
 IO()をMonad m=>mで置き換え可能であるためには、forallを使っている 
 コードも含めて、IO()型に関連する「全ての関数」のモナド版を 
 用意してあげなくちゃいけないと思うのだけど。 
 
827 デフォルトの名無しさん [sage] 2011/12/24(土) 08:41:32.68 ID: Be: 
 >>=, returnとそれと対応するIO版の関数の範囲に限ってその前提条件は成立する。 
 それが型クラスとそのインスタンス宣言の意味するところで、 
 この前提条件の表明がMonad m =>みたいな型シグニチャのコンテキスト。 
 
828 デフォルトの名無しさん [sage] 2011/12/24(土) 08:55:33.85 ID: Be: 
 >827の翻訳 
 
 一般にその前提条件は成立しない。 
 
839 デフォルトの名無しさん [] 2011/12/25(日) 18:31:48.82 ID: Be: 
 いろいろ見てみたけどモナドってやっぱおれには難しいわ。 
 なんか純粋な関数型言語にふつうのプログラミング言語ならふつうにできることを 
 組み込みたいという空気かなと思うが、あまりそう強調されてもいないようだし、 
 まず目的がようわからんわ。 
 抽象化とか言うけど、それはモナドに限らん関数型の特徴だと思うし。 
 だれかこういうのちょっと教えてくれんかなスマンが。 
 
840 デフォルトの名無しさん [sage] 2011/12/25(日) 18:41:00.60 ID: Be: 
 「こういうの」って何だ? 
 具体的に訊いてくれ 
 
841 [―{}@{}@{}-] デフォルトの名無しさん [sage] 2011/12/25(日) 18:48:48.79 ID: Be: 
 まずモナドとIOモナドを区別してくれ 
 純粋さを保ったまま入出力をする仕組みがHaskellにはあって、IOという名前の型が使われる 
 モナドというのはある種の型を抽象的に扱う枠組み 
 (どういう型をどうやって扱うのかは一言では説明できない) 
 で、IOはたまたまモナドの枠組に適合する(ので、IOモナドと呼ばれる) 
 
 で、モナドが知りたいの?IOが知りたいの? 
 
842 デフォルトの名無しさん [sage] 2011/12/25(日) 18:51:02.48 ID: Be: 
 関数に副作用があるかどうかが型を見るだけで解るのは利点 
 
844 デフォルトの名無しさん [] 2011/12/25(日) 19:03:59.38 ID: Be: 
 すぐ反応してくれてうれしいな 
 >>840 
 モナドでやりたいことは何なの?ってことなんだが。 
 関数型にどうのこうのって書いたんだが、そういう「目的」っていうの? 
 そういうのが知りたいんだが。 
 いろんなモナドがあるようなんで、それがわかいにくいんだが。 
 >>841 
 IOモナドはモナドのひとつじゃないん? 
 その「純粋さを保ったまま入出力をする仕組み」がモナドなんやろ? 
 純粋さって関数型のってこと?もしそうなら、どの程度保てるものなの? 
 知りたいのはモナド。IOがその代表ならそれも知りたい。 
 >>842 
 それは型指定を工夫したらできるんじゃないん? 
 こんな質問じゃったんじゃが、みなスマンのう 
 
845 デフォルトの名無しさん [sage] 2011/12/25(日) 19:04:09.30 ID: Be: 
 IO がモナドで表現されるようになった経緯は、 
 「A History of Haskell」の Section 7 に詳しく書かれている 
 
 http://research.microsoft.com/en-us/um/people/simonpj/papers/history-of-haskell/ 
 
846 デフォルトの名無しさん [sage] 2011/12/25(日) 19:05:37.16 ID: Be: 
 >>841 
 > で、IOはたまたまモナドの枠組に適合する(ので、IOモナドと呼ばれる) 
 
 なるほど。 
 いつまでもIOモナドは難しいと言われ続ける理由がわかったよ。 
 
 本当にIOモナドは「たまたま」モナドの枠組みに適合してるの? 
 わざわざモナドとしての宣言をしているのを「たまたま」というの? 
 
 わざわざ色々なIOをモナド則にあわせて整理して宣言しているのを 
 「たまたま」とか言って誤魔化しているわけでしょ。 
 学ぶ人達の能力を信用していないから、そうやって誤魔化すわけだ。 
 
 そうやって学ぶ人達を信用せずに、ありのままを伝えず、 
 取って着けたようなすぐバレるデッチアゲばかり言うから、 
 学ぶ人達はどの言葉を信用すればいいかわからなくなって、 
 「Haskellは難しい」という結論になっているんじゃないの? 
 
847 [―{}@{}@{}-] デフォルトの名無しさん [sage] 2011/12/25(日) 19:10:26.88 ID: Be: 
 >>844 
 >IOモナドはモナドのひとつじゃないん? 
 そうだよ 
 >その「純粋さを保ったまま入出力をする仕組み」がモナドなんやろ? 
 IOモナドがその仕組み。それ以外のモナドは全然別のことをする(構文解析とか) 
 >純粋さって関数型のってこと?もしそうなら、どの程度保てるものなの? 
 副作用のある関数を一切使わずに入出力のあるプログラムが書ける 
 
848 デフォルトの名無しさん [sage] 2011/12/25(日) 19:10:45.98 ID: Be: 
 モナド則が 
 { 
 nop 
 foo 
 bar 
 baz 
 nop 
 } 
 みたいなのを正しく扱うのに都合がいいということはわかる 
 
850 デフォルトの名無しさん [sage] 2011/12/25(日) 19:16:51.65 ID: Be: 
 >>846 
 モナドは副作用を保証してくれないから、 
 モナドだけではI/Oは不可能。 
 副作用をうまく取り扱うための枠組みを、 
 モナドは提供できているというだけの関係。 
 
851 デフォルトの名無しさん [sage] 2011/12/25(日) 19:16:52.65 ID: Be: 
 厳密には何を以て副作用と言うかを(ここだけでも)統一されて議論すべきだが、 
 「Haskell上の値としては副作用はない」というのを副作用が無いと認識している 
 Haskell プログラマは多いし、暗黙の了解になっていたりもする 
 
852 [―{}@{}@{}-] デフォルトの名無しさん [sage] 2011/12/25(日) 19:16:53.25 ID: Be: 
 >>846 
 なんか誤解してるような気がする 
 1. IOは、純粋さを保ったまま入出力するための型である 
 2. IOはMonadのインスタンスである 
 この二つの事実が両方成り立つのは別に必然ではないという意味で「たまたま」と言った 
 モナドにならない型で入出力を表現することはできる(ストリームIOとか)し、 
 入出力と関係ないモナドももちろんある 
 
 つまりHaskellの入出力を理解するのにモナドを知っている必要はないし、(助けにはなるが) 
 モナドを理解するのにIOを知っている必要もない(助けにはなるが) 
 
856 デフォルトの名無しさん [] 2011/12/25(日) 19:21:55.56 ID: Be: 
 >>845 
 ありがと。ちょっと見てみるけどおれにはわからんだろな 
 >>846 
 怒らんで 
 >>847 
 >それ以外のモナドは全然別のことをする 
 うん。そのときの共通性っていうの?それが知りたいんやが 
 >副作用のある関数を一切使わずに入出力のあるプログラムが書ける 
 ほんま?そんなことできるわけないやろ。なんかトリックなんやろ? 
 
858 [―{}@{}@{}-] デフォルトの名無しさん [sage] 2011/12/25(日) 19:30:01.84 ID: Be: 
 >>856 
 >うん。そのときの共通性っていうの?それが知りたいんやが 
 モナドの具体例(2~3個)を知らない人に説明するのは難しい。俺にはできない 
 
 >ほんま?そんなことできるわけないやろ。なんかトリックなんやろ? 
 うん。おおさっぱに言うと、入出力をする関数がない代わりに、入出力をする変なもの(アクション)がある 
 関数とアクションは型が違うから、関数を見たらそれが入出力をしないことは保証されてる 
 
859 デフォルトの名無しさん [] 2011/12/25(日) 19:32:00.64 ID: Be: 
 >>850 
 >副作用をうまく取り扱うための枠組みを、モナドは提供できている 
 どこで、なんで、それができてるんや?ちゅうのが知りたいんやな 
 
864 デフォルトの名無しさん [sage] 2011/12/25(日) 19:48:09.17 ID: Be: 
 Moggiが表示的意味論(もちろんI/O、状態、並列などが扱われている)で 
 使われている技法に共通構造を見出した。 
 それがどんな構造かってのは、数学分からない人には、絶対に演繹的に理解できないです。 
 数々のMonadを体得することで帰納的に理解してください。 
 帰納的な理解だから身体動かさないと無理です。 
 頑張ってMonad入門を読みこなして、さらにプログラムを書いてください。 
 
866 デフォルトの名無しさん [sage] 2011/12/25(日) 20:21:29.09 ID: Be: 
 継続やストリームを使ったIOの表現よりも、 
 モナドを使ったIOの表現の方がシンプルで、処理を追いやすい 
 
 IOモナドが作られた理由はこれに尽きるだろ 
 
867 デフォルトの名無しさん [] 2011/12/25(日) 20:21:39.10 ID: Be: 
 >>858 >>864 
 ああ、また見捨てられてしもた。いっつもこうや。わしに学がないばっかりに。 
 ふつうのプログラムはやってるから、あのIOやエラーは知ってるし、 
 Maybeなんちゅうのがあるらしいのも知ってるけど、そんなんじゃ 
 話がわからんちゅうこっちゃろな。 
 Monad入門ってどこにあるんですか? 
 今日は冷えるわ。 
 
869 デフォルトの名無しさん [sage] 2011/12/25(日) 20:36:19.03 ID: Be: 
 IOモナドに関してはこれがいい。 
 特にボトムアップで理解したい人。実装について触れられてる。 
 http://haskell.org/haskellwiki/IO_inside 
 
870 デフォルトの名無しさん [] 2011/12/25(日) 20:50:43.45 ID: Be: 
 >>867 
 俺も学の無い人間だけど、モナドはOOPでいうインターフェースに当たる型クラスって機能を使って構築されてるって言えば何をしたいものか大体わかる? 
 
876 デフォルトの名無しさん [sage] 2011/12/25(日) 23:39:17.99 ID: Be: 
 ちゃんと教えてあげなよ。 
 >>867 
 Schemeになるが、Semantic Lego 
 http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.31.2885 
 
878 デフォルトの名無しさん [sage] 2011/12/26(月) 01:50:40.57 ID: Be: 
 >>867じゃないけど>>876面白いな 
 モナドとモナド変換子を使ってプログラミング言語の意味を表現しておけば 
 そこからその言語のインタプリタを自動生成してくれるのか

もうちょっと削っても良かったか? ともかくも貼られたリンク先は追ってみることにしよう。

なんとなく自分が知っている人の発言があるような気がするんだよな。 どれが誰のというわけではないんだけど。

2011年12月24日

■_

クリスマスに見つかるとは! ちと値がはったけども○| ̄|_

こっちも見つかった!

今月号の日経ソフトウエアなんだけど……
日経ソフトウエア2012年12月号表紙
この雑誌はどこへ向かおうとしているのだろうか?

2011年12月23日

■_

訳したり引用したりはしないけど、この記事は面白かった → The Lives They Lived

こっちはこれから読む。 Thoughtful Programming and Forth Philosophy, Essay by Michael Misamore

■_ [/]

無駄なエスケープは好かんのよね。

Pythonのお勉強 Part45

592 デフォルトの名無しさん [sage] 2011/12/21(水) 02:18:14.52 ID: Be:
    djangoで日本語urlを使ってアクセスすると
    urlの正規表現でキャッチ出来ません。

    内部でデコードされてるのが原因ぽい感じなんですが、
    止めるにはどうしたらいいですかね? 

593 デフォルトの名無しさん [sage] 2011/12/21(水) 05:07:50.73 ID: Be:
    >>592
    Punycode表記を考慮して正規表現書けばいいんじゃね?

    http://日本語.jp/about/

    と思っただけなので外してたらスマン。 

595 592 [sage] 2011/12/21(水) 21:04:57.09 ID: Be:
    済みません説明が悪かったです。

    例えば、下のようなurlを受け取る場合
    domain.com/path/%e4%bb%8a%e6%97%a5%e3%81%ae%e5%87%ba%e6%9d%a5%e4%ba%8b/
    (ブラウザで domain.com/path/今日の出来事/ と表示)
    url(r'^path/(?P<category>[%a-zA-Z0-9]+)/$', viewname)
    だと取れないんですよね

    どうやらデコードされた状態で渡るっぽいようで
    url(r'^sitename/(?P<category>.+)/$', viewname)
    なら取れるんですが、これはやりたくなくて。

    エンコードされた文字列を含むurlの、
    djangoでの受け取り方を教えて頂きたいんですが。 

599 デフォルトの名無しさん [sage] 2011/12/22(木) 01:53:14.53 ID: Be:

    url(ur'^sitename/(?P<category>今日の出来事)/$', viewname)
      

600 592 [sage] 2011/12/22(木) 03:45:03.84 ID: Be:
    >>599
    それだと汎用性がなくてちょっとキツイんですが


    いい方法ないですかね 

601 デフォルトの名無しさん [sage] 2011/12/22(木) 06:51:36.84 ID: Be:
    url(r'^sitename/(?P<category>.+)/$', viewname) 

602 デフォルトの名無しさん [sage] 2011/12/22(木) 08:54:29.54 ID: Be:
    せめて [^\/]+

    unicode(補助漢字は含まない)の場合、

    [\u0800-\u0FFF\u1000-\uCFFF\uD000-\uD7FF\uF9000-\uFFFF]+

    他の文字コードでも同様に \x00-\xff みたいに 16進で範囲指定可能なので、日本語の範囲を調べて。

620 592 [] 2011/12/22(木) 21:55:12.57 ID: Be:
    >>602
    うーん
    そのパターンでもマッチ出来ないんですが、やり方間違えてるのかな

    ちなみに
    %e4%bb%8a%e6%97%a5%e3%81%ae%e5%87%ba%e6%9d%a5%e4%ba%8b(今日の出来事)
    もマッチしますでしょうか? 

621 デフォルトの名無しさん [sage] 2011/12/22(木) 21:59:44.72 ID: Be:
    django知らんけど、URLエンコードがデコードされてるだけで
    その例だとUTF8エンコーディングのただのバイト列なんじゃねーの
    ならunicodeに変換してunicodeの正規表現で比較汁

622 デフォルトの名無しさん [sage] 2011/12/22(木) 22:58:39.00 ID: Be:
    ヒント: djangoを捨てる 

623 デフォルトの名無しさん [sage] 2011/12/23(金) 02:47:04.82 ID: Be:
    そして Flaskを手に取る 

624 602 [sage] 2011/12/23(金) 03:28:36.92 ID: Be:
    >>622
    PATH_INFO の unquote は WSGI のハンドラで処理されるので、django以外でも同じ。

    >>620

    unicodeの例を出したのは一番簡単そうだったからで、
    utf-8であればutf-8の日本語にマッチする正規表現を作る事になります。

    でも、複雑な正規表現のコストを考えると、 [^\/]+ が一番手軽な対策

    /今日の出来事/hoge みたいなURLを想定して .+ にしたくないのかなと思ったんだけど
    他に理由があるなら、まずは [^\/]+ で駄目な理由を熟考してみて。


    他は、別の方法だけど、RegexURLResolver等のサブクラスで pathを加工してから
    正規表現とのパターンマッチへ渡すって手もある。 

625 デフォルトの名無しさん [sage] 2011/12/23(金) 07:15:19.90 ID: Be:
    >>623
    Flaskでやってみた。何の問題もない。
    http://codepad.org/ZLDGVaep 

626 デフォルトの名無しさん [sage] 2011/12/23(金) 07:18:29.03 ID: Be:
    もう環境変数から直接読めよ 

627 デフォルトの名無しさん [sage] 2011/12/23(金) 07:27:06.54 ID: Be:
    >>625
    ちょっと変えた
    http://codepad.org/pBbMuPwV 

628 デフォルトの名無しさん [sage] 2011/12/23(金) 07:38:32.59 ID: Be:
    >>618
    WSGIはプロセス常駐型Webアプリケーションのための仕組みです。
    古典的なCGIとはちがって、リクエスト毎にプロセスを起動するものではないので、
Webページ毎に.pyとか.wsgiとか.phpを用意するということはしませんし、できません。 

629 デフォルトの名無しさん [sage] 2011/12/23(金) 08:03:20.82 ID: Be:
    >>628
    WSGIは・・・というより、アパッチ・モジュール(もしくは mod_wsgi) は・・・ではないかな。 

630 デフォルトの名無しさん [sage] 2011/12/23(金) 10:42:08.85 ID: Be:
    >>616
    抽象化してるから覚えやすいでしょ 

633 592 [sage] 2011/12/23(金) 12:41:55.40 ID: Be:
    >>621
    >>624
    ありがとうございます。

    [\u0800-\u0FFF\u1000-\uCFFF\uD000-\uD7FF\uF9000-\uFFFF]+
    はunicodeで、マッチするはずありませんですね失礼しました。
    (ちゃんとunicodeって書いてありますよね)

    .+を使いたくなかったのは、無闇にマッチする範囲を広げたく
    無かったからなんですが、厳密な正規表現はコスト増なだけで
    意味なさげですかね。

    となれば[^\/]で問題ないので、これで行こうと思います。

なんか DSL っぽいのを経由しているみたいだけど、 ブラケットの中の / をエスケープしなきゃならないんだろうか。

■_ A-F

C (や C++) の規格ではラテンアルファベット (A から Zまで)は コードが連続しているということを保証(というか要求というか)していないわけだけど、 実際のところそれはこいつのせいだよね? → EBCDIC - Wikipedia

A B C D E F あたりは連続していると仮定しちゃってもいーんじゃないのー と黒いことを考えてみる。

さらに変態的なコードがあって、ここも連続していないという状況だったら そもそもコードのほかの部分もただではすまないと思うんだよね。

■_

■_ GitHub 革命

Apache considered harmful の The GitHub Revolution のあたり。

GitHub 革命

For a moment, let's put the git part of GitHub on the back burner and talk about the hub.

Github 上にある言語とはコードではなく、characterize された contribution (貢献) です。
Github は contribution のための人と人とのコミュニケーションシステムを提供しています。
ドキュメントと issues と、そしてもちろんコードが個人のリポジトリの間を巡るのです。


(GitHub 上で行われている) コミュニケーションのメディアは contribution それ自身です。
contribution の価値、メリット、意図といったものすべてが世界に対して開けっぴろげになっています。
そのシステムには階級も politic embedded (政治的に埋め込まれたもの?) もありません。
プロジェクトの creator は明白な first mover advantage (先行者優位)を持ちますが、
常に fork によって取って代わられる可能性があり、creator のコミュニティにとって十分に
manor な状況での contributions を manage するための social imperative を create していました。

# supplant 取って代わる


GitHub は本当に anarchism のシステムです。most classic sence of the term において GitHub は
コミュニケーションのシステムであり、contribution のシステムです。中心となる組織 (central
organization) も 統治のための制度や慣習 (insutitution of governance) もありません。
もちろん誰かの手によって host され、開発 (develope) され保守 (maintain) されてはいますが、
その人たちはシステムのユーザーの上になんらかの管理 (governance) や手続き (process) 
があることを enforce しません。


わたしたちはまさに今、オープンソースの生態系における非常に大きな進化の只中にいるのだという
ことがわたしの見解 (my belief) です。language of contribution はオープンソース contributors
の新しい世代に影響を及ぼしました。オープンソースの pioneer たちによる potential first imagined
の大半は、かつて要求されていたよりも少ない労力でもって効率的に contribute する
high school kids on a daily basis によって現実のものとなりました


わたしがその変化の重要性をそれほどに信じている (convinced) 理由はとても単純で、それ(変化の
重要性)を identify するまでに一年近くかかったからです。Apache の ethos が
"Community over Code" (コミュニケーションはコミュニティに優る) となった一方で、
それはコミュニティにおける ethos for it to be fully realized に対する理解と internalize
とを要求していました。その ethos は institution によって enforce しなければならなかったので、
social な問題は political な問題になったのでした。


新しい era である "GitHub Era" ではそのような ethos の internalization は要求され
ません。People と その contributions は as transparent as we can imagine で、そういった人た
ち同士の direct connection は socail problems を political problems から social problems に
戻しました。どこであれ meaningful な contribution を得るための barrier は完全に social なも
のとなったのです。言葉を換えれば、その規模が二人であれ二千人であれコミュニティの
responsibility が障壁となるようになったということです。


その principles (原理・原則) を intervention (介在、干渉) 抜きに enforce するシステムは
tremendous な achievement であり、GitHub の adoption trend は誰も驚かせません。

2011年12月22日

■_

ゆず湯に入った。

戦略戦術

■_ Ceylon

M ってのはマイルストーン?

Ceylon: First official release of Ceylon

Ceylon

First official release of Ceylon
by Gavin King
20 Dec 2011

release progress M1

Today, we're proud to announce the release of Ceylon M1 "Newton". This is the first
official release of the Ceylon command line compiler, documentation compiler, language module,
and runtime, and a major step down the roadmap toward Ceylon 1.0.

You can get it here:

http://ceylon-lang.org/download

We plan a compatible M1 release of Ceylon IDE later this week.

Language features

In terms of the language itself, M1 has essentially all the features of Java except enumerated
types, user-defined annotations, and reflection. It even incorporates a number of improvements
over Java, including:

言語自身という意味合いにおいて、M1 は列挙型、ユーザー定義アノテーション、リフレクション
を除き Java のすべての機能を本質的に備えています。
そこには、Javaに対する数々の改良も含まれています

    JVM-level primitive types are ordinary classes in Ceylon
    Ceylon では JVMレベルのプリミティブ型は普通のクラスです

    type inference and type argument inference based on analysis of principal types
    型インターフェースと型引数インタフェースは analysis of principal types に基づいています

    streamlined class definitions via elimination of getters, setters, and constructors
    

    optional parameters with default values
    デフォルト値を持った省略可能パラメーター

    named arguments and the "object builder" syntax
    名前つき引数と「オブジェクトビルダー」構文

    intersection types, union types, and the bottom type

    static typing of the null value and empty sequences
    null 値と空シーケンスの静的型付け

    declaration-site covariance and contravariance instead of wildcard types
    ワイルドカードに替わる declaration-site の covariance と contravariance

    more elegant syntax for type constraints
    型制約のためのより洗練された構文

    top-level function and value declarations instead of static members
    static メソッドに替わるトップレベルの関数や変数の宣言

    nested functions
    ネストした関数

    richer set of operators
    より豊富な演算子群

    more elegant syntax for annotations
    より洗練されたアノテーション構文

    immutability by default
    

Support for the following language features is not yet available:
以下の言語機能のサポートはまだ利用可能になっていません

    first-class and higher-order functions
    first-class 関数や高階関数

    comprehensions
    内包

    algebraic types, enumerated types, and switch/case
    代数型、列挙型、switch/case

    mixin inheritance

    member class refinement

    reified generics

    user-defined annotations and the type safe metamodel
    ユーザー定義アノテーションと型安全なメタモデル

Furthermore, numeric operators are not currently optimized by the compiler, so numeric 
code is expected to perform poorly.

(略)

コメント欄でのやりとりがちょっと面白かった

    Somebody
    i come from Ceylon. Any reason why you couldn't pick another name? :D
    van geir
    Sri Lanka is the name of the country; Ceylon is the name of the island. Just as Java is
    an island shared by 3 different countries. It seems OK to name programming languages
    after geographic features but not countries.
    mackie
    I have no objections you naming this language, Ceylon. In fact, I like that. But to get
    the facts straight, Ceylon was the name of the island during British colonial times and
    for a several years after independence in 1948. Now, the name is Sri Lanka. And no it is
    not like Java, and it is not shared by any country. Some companies still use Ceylon for
    their marketing as western countries are used to things like 'Ceylon tea' and not
    'Sri Lankan tea' and so forth. Hence, probably your confusion on this.

    PS: I'm Sri Lankan and no hard feelings :)
    Emmanuel Bernard, See http://emmanuelbernard.com
    Hi @Somebody and @mackie,

    We used the name in part as a pun to Java (coffee, island). We were aware of the name history
    if only because a few people at JBoss come from Sri Lanka :)


Copyright © 2010-2011, Red Hat, Inc. or third-party contributors
- Ceylon is a trademark of Red Hat, Inc. - terms of Use - Privacy policy

■_ Good variable naming is context dependent

煮込みが足りないけどいいやもうw

Your Community is NOT Your Tools. @ iBanjo

Your Community is NOT Your Tools.
あなたのコミュニティはあなたのツールではない

This entry was posted by Ben Collins-Sussman on Wednesday, 30 November, 2011 at

(Disclaimer: I'm one of the ‘old guard' open source guys. I co-founded the Subversion 
project back in 2000 and am a proud member of the ASF. These opinions are my own.)

(お断り: わたしは 'old guard' open source guys の一人です。2000 年に Subversion
プロジェクトを co-found しましたし、ASF の一員であることに誇りを持っています)


A very popular blog post has been going around lately called Apache Considered Harmful, 
which criticizes the Apache Software Foundation (ASF) for being impossible to work 
with. On the surface, it looks a bit like a culture war between older and younger 
generations of open source hackers: the older generation is portrayed as stodgy and 
skeptical of distributed version control systems, making the ASF inhospitable to a 
younger generation used to the fast-and-freewheeling world of git and Github.

Apache Considered Harmful (Apache は有害であると思われる) と呼ばれる非常に popular な
blog post が最近話題となりましたが、それは Apache Software Foundation (ASF)とは共に働
くことができないと非難するものでした。表面的にはこれはオープンソースハッカーの古い世代
と新しい世代との間の culture war のように見えます。その記事では、
旧世代は旧態依然としていて distributed version control systems を認めず、
新しい世代が使っている fast-and-freewheeling world of git や Github を ASF
に不適切なものにしている人たちとして描写されていました。


One of the ASF's leaders, Jim Jagielski, then wrote a blog response which seems to say, 
“We're not irrelevant; we just have high integrity. We care about long-term health of 
open source projects, not passing fads or hip popularity contests.”

ASF のリーダーの一人である Jim Jagielski は
“我々は irrelevant ではない。
我々には high inegrity がある。
我々はオープンソースプロジェクトの long-term health を care している”
という主張をブログに書きました。


But I think Jim is truly missing the main complaint.
しかしわたしは  Jim が main complaint を missing していると考えています。


Backing up a bit:
what is the mission of the ASF? Why does it exist? My understanding is simple:

Backing up a bit:
ASF の使命 (mission) とはなんでしょうか? ASF はなぜ存在するのでしょうか?
わたしの理解は単純です


   1. to be a legal umbrella of protection
      防衛のための法的な傘となること

   2. to foster long-term, healthy open-source communities
      健全なオープンソースコミュニティの長期間にわたる育成のために


The first goal is achieved by putting all of a project's code under the Apache license, 
and getting all code contributors to grant nonexclusive IP rights to the ASF. This 
guarantees that the ASF “owns” the code, and thus can legally defend it.

第一の目標はプロジェクトのすべてのコードを Apache ライセンスの下に置き、すべての
code contributors に対して nonexclusive IP rigths を ASF へ grant させることを促進
(achive) することです。これは ASF がそのコードを“所有する”ことと、それにより法的
に守られることをもたらします


The second goal is about encouraging and preserving healthy culture. The ASF has a famous
saying: “community over code”. In other words, the ASF doesn't accept donations of code
(or code thrown over walls), it only accepts communities that happen to work on a common
codebase. The community is the main asset, not the source code.

第二の目標は健全な文化 (healthy culture) の促進 (encouraging) と保存 (preserving) です。
ASF には有名な言葉 “community over code”(コミュニティはコードに優る) があります。
言い換えると、ASF はコードの寄付を受け付けておらず、
唯一受け付けるのは共通のコードベースで働くコミュニティです。
そのコミュニティが main asset なのであってソースコードがそうなのではありません。


The ASF has a great set of cultural norms that it pushes on its communities via 
political means and lightweight processes. For example, the ASF requires that each 
community have a set of stewards (“committers”), which they call a “project 
management committee”; that communities use consensus-based discussions to resolve 
disputes; that they use a standardized voting system to resolve questions when 
discussion fails; that certain standards of humility and respect are used between 
members of a project, and so on. These cultural traditions are fantastic, and are the 
reason the ASF provides true long-term sustainability to open source projects. It's 
the reason I pushed so hard to get the Subversion project into ASF.

ASF は political means と lightweight processes を通じてそのコミュニティへ push する
といったすぐれた set of cultural norms を持っています。たとえば、ASF は彼らが
“project management committee” と呼ぶ steawards ("committers") の集まりを各コミュ
ニティが持つことを要求しています。
その コミュニティでは disputes を解決するために consensus-based discussions を使い、
議論がまとまらなかったときに questions を解決するための標準化された投票システムを使い、
that certain standards of humility and respect are used between members of a project,
and so on.
そういった cultural traditions は fantastic であり、そしてそれは ASF がオープンソース
プロジェクトに対する true long-term sustainability を与えている理由です。それこそが
ASF に対して Subversion プロジェクトを get するようにわたしが非常に強く push している
理由です。


Let's go back to the original “Apache Considered Harmful” post again. Yes, the blog 
post rambled a bit about the ASF becoming “irrelevant”, but I think that's just 
random grumbling around the actual issue at stake: the ASF's insistence on forcing 
their hosting infrastructure onto projects. We have repeated examples of mature open 
source communities trying to join the ASF, which already use git as their version 
control system — and the ASF is insisting that they convert to Subversion and store 
their code in the ASF's One Big Subversion Repository.

もう一度元の “Apache Considered Harmful” のポストに戻りましょう。確かに問題のブロ
グ記事は ASF が "irrevant" (今日的な意義を持たない) になっていると ramble していま
したが、わたしはそれが、本当の問題点、つまりプロジェクトが使用するインフラのホスティ
ングを ASF が強制するということの周辺にあるような単なる random grumbling に過ぎない
と考えているのです。
わたしたちは、すでに git を自分たちのバージョン管理システムとして使っている
mature な open source コミュニティが ASF に join しようとしたときに、
ASF はそれを Subversion に変換して彼らのコードを ASF の One Big Subversion
リポジトリに格納することに固執するということを繰り返しています。


I fear what's happening here is that the ASF elders have tragically confused “be part 
of our community” with “you must use our infrastructure”. There is no reason for 
these things to be entangled.

わたしがここで恐れているのは、ASF の elder たちが
“be part of our community” with “you must use our infrastructure”.
(わたしたちのコミュニティの一部になれ
君たちはわたしたちのインフラを使わなければならない)
と tragically に confuse してしまうことです。
これらのことが entagle になる理由はありません。


The ASF has teams of people dedicated to running servers for Subversion, SSH, QA 
testing, email lists, and so on. Ten years ago, infrastructure hosting was a Hard 
Thing. Getting to use the ASF's hosting services was considered an attractive perk. 
These days, project hosting is utterly commoditized: we have Sourceforge, Google Code, 
Github, and other sites. In a matter of minutes, any two people can conjure up a 
hosted source repository, bugtracker, wiki, etc. So is it really a surprise that newer 
communities, ready to join the ASF, already have functional (and possibly superior) 
tools and infrastructure?

ASF には Subversion や SSH、QAテスト、メーリングリストといったもののためのサーバーを
動かすことを dedicate した人たちのチームがあります、十年前には、インフラのホスティン
グは難しいもの (Hard Thing) でした。ASF のホスティングサービスを使うようになることは
attractive perk とかつては考えられていました。最近では、プロジェクトのホスティングは
いたってふつうのものとなっています。わたしたちには Sourceforge や GoogleCode、Github
等々のサイトがあります。
In a matter of minutes,
any two people can conjure up a hosted source repository, bugtracker, wiki, etc.
ですから、ASF に ready to join な新たなコミュニティがすでに (ASF のそれよりもより優れ
ている可能性がある) functional tools や infurastructure を持っていることは本当に驚く
ようなことなのでしょうか?


So why oh why does the ASF demand everyone use their Subversion service? They don't 
force every project to use the same bugtracker; I wonder if source code is different 
because it's the “special” asset being protected. Perhaps the ASF elders think it 
has to all be in one place in order for it to be protectable and controlled? A simple 
solution here is to simply require that at least one canonical copy of source code be 
stored on ASF servers. If that means doing an “hg pull” or “git pull” via cron job 
every hour, so be it. Who cares where the real coding is happening, or in how many 
repositories it's happening in? Irrelevant. As long as a community has blessed a 
central repository as Official, and the ASF is keeping a synced copy of that somewhere, 
we should be all set. The ASF's job is to shepherd communities, not force everyone to 
use the same software tools.

ではなぜ、ASF は彼らの Subversion サービスを使うようにすべての人に要求するのでしょうか?
彼らはすべてのプロジェクトに対して同じバグトラッカーを使えと強制はしていません。わたしは
ソースコードが別になっていれば良いなあと思っています。なぜならそれが保護されている
“special” asset であるからです。おそらく ASF の elder たちは防御したり制御したりするた
めにすべてが一箇所になければならないと考えているのでしょう。ここでの simple な solution
は、少なくともソースコードの canonical なコピーを ASF のサーバーに置くように要求すること
です。もしそれが一時間おきの cron job を通じて “hg pull” だとか “git pull”を行うこと
であればそうします。コーディングが実際にはどこで行われているかとか、どのくらいのリポジト
リーがあるのかということなど誰が気にかけるでしょうか?
Irrelevant.
コミュニティが公式なものとして祝福された中央リポジトリを持つと同時に
ASF はどこかにあるもののコピーと同期し続ける。
わたしたちは all set であるべきです。
ASF の仕事はコミュニティを shepherd することであって、
同一のソフトウェアツールの使用を強制することではありません。


Ironically, years ago I too was suspicious of distributed version control, and wrote 
an article about how it tended to discourage ASF-style project cohesion. But in this 
case, we have examples of communities that are already cohesive and high-functioning, 
despite using git. They don't need ASF's tools; they just need a nice place to park 
their community. If they ain't broke, stay out of their development processes.

皮肉なことに、何年も前にわたしもそれがどのように ASF スタイルのプロジェクトの cohesion
を discourage するのかについての article を書いていました。しかしこの場合、わたしたちに
は git を使ってはいるけれどもすでに cohesive かつ high-fuctioning なコミュニティの例が
あります。そういったコミュニティは ASF のツールを必要としません。
そのコミュニティの人たちは自分たちのコミュニティが
park するための nice な場所だけが必要なのです。
If they ain't broke, stay out of their development processes.


(Note the ASF isn't alone in this insanity. Others have told me that FSF projects are 
forced to use the Savannah collaborative platform, whether they want to or not. Crazy! 
Repeat after me, folks: your community is not your tools.)

(注意: ASF だけがこの insanity にあるわけではありません:
ある人が、FSF のプロジェクトでは、望むと望まぬとに関わらず
Savannah collaborative platform の使用を強制されると教えてくれました。
Crazy! Repeat after me, folks: your community is not your tools.)

■_

■_

enum type check in C/gcc - Stack Overflow

See the simple example below. When a function returning one enum is assigned to a 
variable of a different enum I don't get any warning even with gcc -Wall -pedantic. 
Why is it not possible for a C compiler to do type checking on enums? Or is it gcc 
specific? I don't have access to any other compiler right now to try it out..

意外にこの辺の事情を知らない人って多いのだろうか。

正規表現で文字を抜き出したい | OKWave
"ファイルの総数:[^バイトの空き領域]*バイトの空き領域(?=\r)"
という正規表現を作成したのですが、うまく動作しません。

ああ、またここに文字クラスの compliment を勘違いしている人が

2011年12月21日

■_

今年も最後のファイルに。

英語コミュニティに発信しよう - 川口耕介の日記

この辺に手を出している時間的余裕がなかった ISO C is increasingly moronic : programming OOP vs type classes : programming

■_

また一部の電書の安売りをやってて、 ちと気になって近刊予定をずっと眺めていったらまあ面白そうなのがたくさん。 自分基準で勝手にいくつか選んだのがこの辺。 紙の本の値段しかないのもあるけど。

まともに買っていったらいくらあっても足りなくなりそうな気配

■_ 機能追加

[bug-gawk] Gawk Enhancement Suggestion こーゆー組み込み関数増やしてくれない? というお願いがあったのですが

[bug-gawk] Gawk Enhancement Suggestion
[bug-gawk] Gawk Enhancement Suggestion 
From: Ed Morton 
Subject: [bug-gawk] Gawk Enhancement Suggestion 
Date: Fri, 02 Dec 2011 07:36:50 -0600 

Arnold - could we get a "cut()" function for gawk similar to the UNIX one of 
the same name that just lets people select specific fields or ranges of fields? Below 
is some details (copied from something I posted at comp.lang.awk). 
 
 
Regards, 
 
 Ed. 
 
A function that returns a string of selected fields is very often all we need. 
e.g.: 
 
print cut($0,3) # print from the 3rd field to the end of the record using FS as 
separator print cut($0,3,",") # print from the 3rd field to the end of the 
record using "," as separator 
 
print cut($0,"3-7") # print from the 3rd field to the 7th field 
print cut($0,"3,5,7") # print the 3rd, 5th, and 7th fields 
 
The separating substring between the fields would just be whatever separator preceeded 
the trailing fields. So, with this input (with leading blanks): 
 
 
 a b c d 
 
the following code snippets would produce the output that follows them: 
 
print cut($0,"1,3") 
a c 
 
print cut($0,"1,3",/[[:blank:]]+/) 
 b 
 
print cut($0,"1-3") 
a b c 
 
print cut($0,"2,4") 
b d 
 
print cut($0,"1-4") 
a b c d 
 
Obviously $0 can be replaced by any string and cut() should take an optional 4th arg 
to specify the separator in it's returned string: 
 
 
print cut($0,"1,3",FS,OFS) 
a c 
 
print cut($0,"1,3",/[[:blank:]]+/,"#") 
#b 
 
print cut($0,"1-3",FS,OFS) 
a b c 
 
print cut($0,"2,4",FS,":") 
b:d 
 
print cut($0,"1-4",FS,"|") 
a|b|c|d

すげなく断られてしまった。というお話。

Re: [bug-gawk] Gawk Enhancement Suggestion
Hi Ed. Re the below. See the node "Cut Program" in the gawk manual.
Adaptation into a function should be straightforward.

A diff to redo that section as a function + code to call it will
be cheerily reviewed and most likely accepted. Thanks, Arnold

Re: [bug-gawk] Gawk Enhancement Suggestion

Arnold - I'll take a look and get back to you. I expect I can code up what I have in 
mind (which isn't quite what's in that example) as an awk function that people could 
copy/paste but I was really hoping to get a new builtin string function out of this. 
 
 
Thanks, 
 
 Ed.
Re: [bug-gawk] Gawk Enhancement Suggestion
Arnold - in case it's a useful reference, below is an awk function that'd implement 
the functionality I'd like us to have in a built in gawk cut() function along with a 
sample "body" just to show how it behaves. In reality I wouldn't expect 
people to be passing the cut() arguments in as awk variables, they'd probably be 
hard-coded. 
 
 Ed.
(以下略) 
Re: [bug-gawk] Gawk Enhancement Suggestion

Hi Ed. I don't see this as being enough useful to require making it a builtin. It's 
just more code to maintain and document that won't get a lot of use.

I think an awk function is the best way to go, but if you want to contribute a 
loadable function written in C that would work too. Thanks, Arnold

Re: [bug-gawk] Gawk Enhancement Suggestion
Hi Ed. Per my earlier mail, I have no plans to write this in C to make it a gawk built-in.
I am happy to add it to the doc, but I will need from you:

1. Some prose giving a blow-by-blow description of how the function works, similar in 
   style to what's in the gawk manual. I can handle adding the texinfo markup if you'll 
   write the text.

2. Signed paperwork assigning copyright to the FSF.

If you're willing to do both, let's continue working offline.

Similarly, if you wish to contribute such a function as a loadable builtin, I will add 
it to the dist, but you'll still need to write the C code and sign paperwork. Thanks, 

Arnold

予想通りの流れ。

■_ スコア計算

TDDBC 札幌 2.3 で遊びで書いてみたボウリングスコア集計 - Smalltalkのtは小文字です @snoozer05 のボウリングスコア集計 Ruby 写経版を Squeak Smalltalk に逆翻訳 - Smalltalkのtは小文字です sumim さんのボウリング集計のコード(http://d.hatena.ne.jp/sumim/20111214/p1)を Ruby で — Gist

むかーし、FORTAN で書かされた(なんかの課題だったと思う)なあ。 と遠い目モード。

■_

これ、JSON形式のデータじゃないかと思うのだけど違うかなあ、 であれば直接正規表現でどうこうじゃなくてそれ向けのモジュール使わせた方がいいと思うけど。

Perlを使った正規表現について | OKWave
Perlを使った正規表現について 
 
テキストファイルを読み込んで、以下のルールに従った文字列だけを.txtで出力するプログラムを書いています。 
具体的にはテキストファイル中の 
"text":"★★★","to_user" 
で囲まれている★★★の部分のみを抽出したいです。 
そこで正規表現に触りだしたのですが、表現がうまくいっていないようで1週間ほどはまっています。。うまく出力できるように直しをいただけないでしょうか。 
打ち明けてしまうと、★★★の部分はtwitterの呟き(日本語)になります。 
以下がそのソースになります。よろしくお願いします。 
 
 
print "Input file name: "; 
$ifname = <STDIN>; 
 
open(IN, $ifname); 
open(OUT, "> out.txt"); #出力ファイル 
while(<IN>){ 
if($ifname =" m/"test":(.*?),"to_user"/; 
next if($_ eq ""); 
print OUT "$_\n"; #書き出し 
} 
close(OUT); 
close(IN); 
 
ANo.2 

 
正規表現で無く、プログラムの問題です。 
 
初心者であれば、すこしずつ確かめながらプログラムを書くのがいいでしょう。 
 
ステップ1: 
ファイルから読み込んだデータを無条件に全件書き出す。 
(ファイルの入出力の仕方を学ぶ) 
 
ステップ2: 
正規表現を /(.*)/ つまり「すべてにマッチする」 にした状態で、マッチした部分を書き出す。 
結果的には全件書き出しですが。 
(正規表現のプログラムの中での使い方を学ぶ) 
 
ステップ3: 
望みの処理。 
(正規表現を学ぶ) 
 
今のプログラムは、ステップ1の直前くらいでしょうか。 
 
ANo.1 
 
> if($ifname =" m/"test":(.*?),"to_user"/; 
 
なんか文法的にむちゃくちゃなんですけど。 
・正規表現の対象にするには =~ です。 
・if ( $ifname = "XXXX") みたいになっていたのをコピーするとき間違えたようにも見えます。 
しかし、$ifname = "XXXX"は $ifnameに"XXXX"を代入する(そして全体で"XXXX"をという値になる)というものです。 
比較はしません。また、文字列との比較に==は使えません。 
 
> next if($_ eq ""); 
$_はここでは<IN>で読み込んだ文字列になっています。 
<>では改行がそのまま残ります。よって、$_ eq ""にはなりません。 
 
> print OUT "$_\n"; #書き出し 
$_については上記のとおり 
m//は単に正規表現と一致するかどうかをチェックするだけのものです。 
元の文字列の変更はしません。よって、入力がそのまま出力されます。上記の通り改行文字込みなので、1行おきに表示されることでしょう。 
正規表現内()で括った部分を参照するには$1,$2...を使います。 
 

■_


一つ前へ 2011年12月(中旬)
一つ後へ 2012年1月(上旬)

ホームへ


リンクはご自由にどうぞ

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