ときどきの雑記帖無名編

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

一つ前へ 2011年6月(中旬)
一つ後へ 2011年7月(上旬)

ホームへ

2011年06月30日

■_

上半期も今日で終了と。

■_ 自腹ですが何か

まあとある映画監督ではありませんが、自腹切って買ったものでないと書くものも書けなかったりするわけで (いやまて、実践F#は本をいただいたけど結構遠慮なく書いたぞw)。

コンピュータープログラミング入門以前
を買ったのですが、ちょっと気になる箇所が。 p 114 にこうあるのですが

(パターンマッチング手法としての)正規表現では、以下のような記法で文字列のパターンマッチングを行います。

・abcというように、文字列をそのまま書くと、これと同じ文字列とマッチします
・a|bというように、|(縦棒)記号を用いることで、「aまたはb」というように2つのうちどちらか一方とマッチします
  ・例えば、gre|ay で grey または gray とマッチします
・文字クラス
  ・\w(アルファベットなど、単語に使われる文字)や\s(空白やタブ、改行などの空白文字)というように、
\から始まる記号で、特定のカテゴリーに含まれる文字とマッチします
  ・.(ドット)記号で、任意の1文字とマッチします
・()でグループ化することができます
  ・例えば、(abc)|(def) で、abcまたはdefのどちらかにマッチします
・量指定
  ・?記号で「0個または1個」を表します
    ◆例えばab?でaまたはabとマッチします
  ・*記号で「0個以上」を表します
    ◆ab*でa,ab,abb,abbbなどとマッチします
  ・+記号で「1個以上」を表します
    ◆ab+でab,abb,abbbなどとマッチします

正規表現にはその他にもさまざまな記法があります。また、結構「方言」があり、ひとくちに正規表現と
言ってもいろいろな種類のものがあります(上述の例のような基本的な部分に関しては、どの方言でもほ
ぼ同じ記法です)。
  

| の優先順位が間違っているように思います。 たとえば例にある gre|ay であれば、 gre または ay にマッチ。ではないでしょうか。 (abc)|(def)については、カッコのあるなしで結果は変わらないと思います。

とりあえず opengroup のページから、メタ文字の優先順位の辺りを引用してみます。

Regular Expressions
ERE Precedence
The order of precedence will be as shown in the following table:

ERE Precedence (from high to low)
collation-related bracket symbols 	[= =] [: :] [. .]
escaped characters 	\<special character>
bracket expression 	[ ]
grouping 	( )
single-character-ERE duplication 	* + ? {m,n}
concatenation 	 
anchoring 	^ $
alternation 	| 

alternation は concatnation よりも低い優先順位なので、 abc|def は abc と def が alternation の対象になるというわけです。

>grep -o -E -e"gra|ey"
gray
gra
grey
ey
^Z

まだざっと見ただけなので全体を通してどうかというのはわかりませんが、 上記の箇所を除けば意欲的で良く書けているのではないかと思います (偉そう)。

■_ メッセージ多言語化

何のことはない。マニュアルにファイルフォーマットが記載されてました。 文章の部分を全部読んでいないので、一部不明なところは残ってるのですが まあ大体は把握できました。

GNU `gettext' utilities
"10.3 The Format of GNU MO Files

The format of the generated MO files is best described by a picture, which appears below. "
http://www.gnu.org/software/gettext/manual/gettext.html#MO-Files

あたりを参照して、gawk の ja.gmo を調べてみました。

00000000  de 12 04 95 00 00 00 00  b9 01 00 00 1c 00 00 00  |................|
00000010  e4 0d 00 00 51 02 00 00  ac 1b 00 00 00 00 00 00  |....Q...........|
00000020  f0 24 00 00 10 00 00 00  f1 24 00 00 0c 00 00 00  |.$.......$......|
00000030  02 25 00 00 1c 00 00 00  0f 25 00 00 12 00 00 00  |.%.......%......|
00000040  2c 25 00 00 17 00 00 00  3f 25 00 00 1e 00 00 00  |,%......?%......|
00000050  57 25 00 00 1c 00 00 00  76 25 00 00 17 00 00 00  |W%......v%......|
00000060  93 25 00 00 11 00 00 00  ab 25 00 00 0e 00 00 00  |.%.......%......|
00000070  bd 25 00 00 1a 00 00 00  cc 25 00 00 10 00 00 00  |.%.......%......|
(略)
0000d830  a6 e3 81 84 e3 81 be e3  81 99 00 e8 ad a6 e5 91  |................|
0000d840  8a 3a 20 00 78 6f 72 28  25 6c 66 2c 20 25 6c 66  |.: .xor(%lf, %lf|
0000d850  29 3a 20 e5 b0 8f e6 95  b0 e7 82 b9 e4 bb a5 e4  |): .............|
0000d860  b8 8b e3 81 af e5 88 87  e3 82 8a e6 8d a8 e3 81  |................|
0000d870  a6 e3 82 89 e3 82 8c e3  81 be e3 81 99 00 78 6f  |..............xo|
0000d880  72 28 25 6c 66 2c 20 25  6c 66 29 3a 20 e8 b2 a0  |r(%lf, %lf): ...|
0000d890  e3 81 ae e6 95 b0 e5 80  a4 e3 82 92 e4 bd bf e7  |................|
0000d8a0  94 a8 e3 81 99 e3 82 8b  e3 81 a8 e7 95 b0 e5 b8  |................|
0000d8b0  b8 e3 81 aa e7 b5 90 e6  9e 9c e3 81 ab e3 81 aa  |................|
0000d8c0  e3 82 8a e3 81 be e3 81  99 00 78 6f 72 3a 20 e9  |..........xor: .|
0000d8d0  9d 9e e6 95 b0 e5 80 a4  e3 81 ae e7 ac ac e4 b8  |................|
0000d8e0  80 e5 bc 95 e6 95 b0 e3  82 92 e5 8f 97 e3 81 91  |................|
0000d8f0  e5 8f 96 e3 82 8a e3 81  be e3 81 97 e3 81 9f 00  |................|
0000d900  78 6f 72 3a 20 e9 9d 9e  e6 95 b0 e5 80 a4 e3 81  |xor: ...........|
0000d910  ae e7 ac ac e4 ba 8c e5  bc 95 e6 95 b0 e3 82 92  |................|
0000d920  e5 8f 97 e3 81 91 e5 8f  96 e3 82 8a e3 81 be e3  |................|
0000d930  81 97 e3 81 9f 00                                 |......|
0000d936

んでまあちまちまと調べていくと

0000 DE 12 04 95 magic number
0004 00 00 00 00 file format version
0008 B9 01 00 00 N number of strings
000C 1C 00 00 00 O offset of table with original strings
0010 E4 0D 00 00 T offset of table with translation strings
0014 51 02 00 00 S size of hashing table
0018 AC 1B 00 00 H offset of hashing table

001C 00 00 00 00 F0 24 00 00 length & offset 0th string
     10 00 00 00 F1 24 00 00
     0C 00 00 00 02 25 00 00
     1C 00 00 00 0F 25 00 00
     12 00 00 00 2C 25 00 00
     17 00 00 00 3F 25 00 00
     1E 00 00 00 57 25 00 00
     1C 00 00 00 76 25 00 00
     17 00 00 00 93 25 00 00
     11 00 00 00 AB 25 00 00
     0E 00 00 00 BD 25 00 00
     1A 00 00 00 CC 25 00 00
     10 00 00 00 E7 25 00 00
     10 00 00 00 F8 25 00 00
     1B 00 00 00 09 26 00 00
     12 00 00 00 25 26 00 00
     1C 00 00 00 38 26 00 00
     14 00 00 00 55 26 00 00
     23 00 00 00 6A 26 00 00
     2B 00 00 00 8E 26 00 00
     1E 00 00 00 BA 26 00 00
     10 00 00 00 D9 26 00 00
     0D 00 00 00 EA 26 00 00
     19 00 00 00 F8 26 00 00
     1C 00 00 00 12 27 00 00
     14 00 00 00 2F 27 00 00
     11 00 00 00 44 27 00 00
     1E 00 00 00 56 27 00 00
     1A 00 00 00


0DE4 A0 01 00 00 85 6D 00 00 (翻訳文字列の長さとオフセットの対)
     14 00 00 00 26 6F 00 00
     0E 00 00 00 3B 6F 00 00
     2D 00 00 00 4A 6F 00 00
     12 00 00 00 78 6F 00 00
     17 00 00 00

024F0: (翻訳前文字列)
 1: 00
17: 09 23 20 25 73 20 62 6C 6F 63 6B 28 73 29 0A 0A 00
13: 09 23 20 52 75 6C 65 28 73 29 0A 0A 00
29: 09 23 20 67 61 77 6B 20 70 72 6F 66 69 6C 65 2C 20 63 72 65 61 74 65 64 20 25 73 0A 00
19: 09 2D 43 09 09 09 2D 2D 63 6F 70 79 72 69 67 68 74 0A 00
24: 09 2D 45 20 66 69 6C 65 09 09 09 2D 2D 65 78 65 63 3D 66 69 6C 65 0A 00
31: 09 2D 46 20 66 73 09 09 09 2D 2D 66 69 65 6C 64 2D 73 65 70 61 72 61 74 6F 72 3D 66 73 0A 00
29: 09 2D 4C 20 5B 66 61 74 61 6C 5D 09 09 2D 2D 6C 69 6E 74 5B 3D 66 61 74 61 6C 5D 0A 00


06D85: (翻訳文字列)
              50 72 6F 6A 65 63 74 2D 49 64 2D
56 65 72 73 69 6F 6E 3A 20 67 61 77 6B 20 33 2E
31 2E 38 33 0A 52 65 70 6F 72 74 2D 4D 73 67 69
64 2D 42 75 67 73 2D 54 6F 3A 20 61 72 6E 6F 6C
64 40 73 6B 65 65 76 65 2E 63 6F 6D 0A 50 4F 54
2D 43 72 65 61 74 69 6F 6E 2D 44 61 74 65 3A 20
32 30 31 31 2D 30 36 2D 31 37 20 31 31 3A 30 39
2B 30 33 30 30 0A 50 4F 2D 52 65 76 69 73 69 6F

6E 2D 44 61 74 65 3A 20 32 30 31 31 2D 30 35 2D
32 35 20 30 39 3A 34 34 2B 30 39 30 30 0A 4C 61
73 74 2D 54 72 61 6E 73 6C 61 74 6F 72 3A 20 59
61 73 75 61 6B 69 20 54 61 6E 69 67 75 63 68 69
20 3C 79 61 73 75 61 6B 69 74 40 67 6D 61 69 6C
2E 63 6F 6D 3E 0A 4C 61 6E 67 75 61 67 65 2D 54
65 61 6D 3A 20 4A 61 70 61 6E 65 73 65 20 3C 74
72 61 6E 73 6C 61 74 69 6F 6E 2D 74 65 61 6D 2D

6A 61 40 6C 69 73 74 73 2E 73 6F 75 72 63 65 66
6F 72 67 65 2E 6E 65 74 3E 0A 4C 61 6E 67 75 61
67 65 3A 20 6A 61 0A 4D 49 4D 45 2D 56 65 72 73
69 6F 6E 3A 20 31 2E 30 0A 43 6F 6E 74 65 6E 74
2D 54 79 70 65 3A 20 74 65 78 74 2F 70 6C 61 69
6E 3B 20 63 68 61 72 73 65 74 3D 55 54 46 2D 38
0A 43 6F 6E 74 65 6E 74 2D 54 72 61 6E 73 66 65
72 2D 45 6E 63 6F 64 69 6E 67 3A 20 38 62 69 74

0A 50 6C 75 72 61 6C 2D 46 6F 72 6D 73 3A 20 6E
70 6C 75 72 61 6C 73 3D 31 3B 20 70 6C 75 72 61
6C 3D 30 3B 0A 00

09 23 20 25 73 20 E3 83 96 E3 83 AD E3 83 83 E3 82 AF 0A 0A 00
09 23 20 E3 83 AB E3 83 BC E3 83 AB 0A 0A 00
09 23 20 67 61 77 6B 20 E3 83 97 E3 83 AD E3 83 95 E3 82 A1 E3 82 A4 E3 83 AB E3 80 81 E4 BD 9C E6 88 90 E6 97 A5 E6 99 82 20 25 73 0A 00
09 2D 43 09 09 09 2D 2D 63 6F 70 79 72 69 67 68 74 0A 00
09 2D 45 20 66 69 6C 65 09 09 09 2D 2D 65 78 65 63 3D 66 69 6C 65 0A 00
09 2D 46 20 66 73 09 09 09 2D 2D 66 69 65 6C 64 2D 73 65 70 61 72 61 74 6F 72 3D 66 73 0A 00
09 2D 4C 20 5B 66 61 74 61 6C 5D 09 09 2D 2D 6C 69 6E 74 5B 3D 66 61 74 61 6C 5D 0A 00

多分ハッシュ値は該当の文字列を探すときに楽をするためのものだと思うけど 生成関数やらはまだ不明。

■_ Perl 6

ほんとコード片見てもよくわからない。

Euler 5 « Just Rakudo It

So, Hacker News brought me this post this morning, and I wanted to see how Perl 6 
stacked up to Java / Scala. The answer turned out to be pretty poorly speed-wise, at 
least in my initial attempts. But that's a story for another post. Right now I’m 
just interested in finding a good solution to the problem itself: “What is the 
smallest positive number that is evenly divisible by all of the numbers from 1 to 20?”

“1から20までのすべての数で divisible であるような最小の正の数とは?”

So far, this is my favorite, I think:

	sub divides-by-all-up-to($a, $b) {
	    !(2..$b).grep($a !%% *);
	}
	 
	my $N = [*] 2, 3, 5, 7, 11, 13, 17, 19;
	my @attempts := $N, 2 * $N ... { divides-by-all-up-to($_, 20) };
	say @attempts[*-1];

You can easily get this down to a two-liner, but only at the cost of a good bit of 
clarity, IMO.

So, what does it do? divides-by-all-up-to checks to see if $a is divisible by all the 
numbers from 2 to $b. This is one of those concepts for which there is very definitely 
more than one way to do it in Perl 6. For instance,

さて、これはなにをやっているのでしょうか? divides-by-all-up-to は $a が 2 から $b までの
間にある数すべて divisible であるかどうかを検査しています。これは、Perl 6 における
very definitely more than one way to do it のためのコンセプトのひとつです。
#だー、変。
例を挙げましょう


	?all($a <<%%<< 2..$b)

or

	[&&} $a X%% 2..$b

(略)

■_ 4.0

もたもたしてたら出てしまいました~

[bug-gawk] Gawk 4.0.0 Now Available

From: 	Aharon Robbins
Subject: 	[bug-gawk] Gawk 4.0.0 Now Available
Date: 	Thu, 30 Jun 2011 11:26:43 +0300

Greetings all.

This note announces the next major release of GNU Awk: version 4.0.0.

The following files may be retrieved from ftp://ftp.gnu.org/gnu/gawk,
or via HTTP from http://ftp.gnu.org/gnu/gawk:

-rw-r--r--    1 1003     65534     1589204 Jun 29 21:32 gawk-4.0.0.tar.xz
-rw-r--r--    1 1003     65534     2651812 Jun 29 21:31 gawk-4.0.0.tar.gz
-rw-r--r--    1 1003     65534     2063647 Jun 29 21:31 gawk-4.0.0.tar.bz2

This is a major new release, with a number of new features, including
revamped internals.  The relevant part of the NEWS file is appended below.

(略)
------------------------------------------------------------
Changes from 3.1.8 to 4.0.0
---------------------------

1. The special files /dev/pid, /dev/ppid, /dev/pgrpid and /dev/user are
   now completely gone. Use PROCINFO instead.

2. The POSIX 2008 behavior for `sub' and `gsub' are now the default.
   THIS CHANGES BEHAVIOR!!!!

3. The \s and \S escape sequences are now recognized in regular expressions.

4. The split() function accepts an optional fourth argument which is an array
   to hold the values of the separators.

(略)

28. Many code cleanups. Removed code for many old, unsupported systems:
        - Atari
        - Amiga
        - BeOS
        - Cray
        - MIPS RiscOS
        - MS-DOS with Microsoft Compiler
        - MS-Windows with Microsoft Compiler
        - NeXT
        - SunOS 3.x, Sun 386 (Road Runner)
        - Tandem (non-POSIX)
        - Prestandard VAX C compiler for VAX/VMS
        - Probably others that I've forgotten

29. If PROCINFO["sorted_in"] exists, for(iggy in foo) loops sort the
    indices before looping over them.  The value of this element
    provides control over how the indices are sorted before the loop
    traversal starts. See the manual.

30. A new isarray() function exists to distinguish if an item is an array
    or not, to make it possible to traverse multidimensional arrays.

31. asort() and asorti() take a third argument specifying how to sort.
    See the doc.
-- 
Aharon (Arnold) Robbins                         arnold AT skeeve DOT com

ぼちぼちやりますかね。

■_

2011年06月29日

■_

大盛況
第0回 スタートHaskell : ATND
申し込み人数が1桁くらいのときに気がついてたんですが、今回は遠慮。 まあ色々考えるところはあると。

■_

■_ Perl 6

本文はおいといて :)

June 21 2011: Nested data structures :: Strangely Consistent

my @unit_matrix =
    [ 1, 0, 0 ],
    [ 0, 1, 0 ],
    [ 0, 0, 1 ],
;

say @unit_matrix.elems;     # "3"
say @unit_matrix[0].elems;  # "3"


my %directories =
    "/" => {
        "usr" => {
            "local" => {},
        },
        "home" => {
            "cinderella" => {},
            "santa"      => {},
            "gretl"      => {},
        },
    },
;

say %directories.keys;          # "1" (just the root)
say %directories</><home>.keys; # "3" (users)

sigls がついているのと、終端のセミコロンが必須なので問題なく解釈できるという話なんだろうけど、 一番外側のブラケットやラブレースがないというのはなんか不安が。

■_ 熱心

なのかなあ。

■_ sed

sed で××

full text search - Linux SED script find the 1st line that match pattern and delete it - Stack Overflow

I want to create a sed command to find in a file the 1st line that matchs a pattern 
and the delete all that line or replace it all with some other text. I dont want to 
match all the line because the rule is to match part of it.


how can i do it with sed?
for instance:

myline 1 is pretty
line 2 is ugly
myline 111 is nice

I want to delete the first line that contains "1 is"

UPDATE: My line may have characters like "/" and "<"

Regards Fak

I tend to use awk for more complicated tasks, it's a bit more powerful than sed, 
having proper looping and selection constructs (expanded for readability, you can 
compress it back to one line if you wish):

pax$ echo '
xyz
myline 1 is pretty
line 2 is ugly
myline 111 is nice'  | awk '
     /1 is/ {if (f) {print} else {f = 1}}
    !/1 is/ {print}'

xyz
line 2 is ugly
myline 111 is nice

For any line not matching the pattern (!/1 is/), it just prints it.

For lines that do match the pattern, it prints them all if the flag f is set (it's 
initially not set). When the flags not set and it encounters a matching line, it sets 
the flag and doesn't print it. This basically deletes the first matching line as 
desired.

If you want to modify the first matching line rather than deleting it, you just insert 
code alongside the f = 1 to do that, something like:

pax$ echo '
xyz
myline 1 is pretty
line 2 is ugly
myline 111 is nice'  | awk '
     /1 is/ {if (f) {print} else {f = 1;print "URK!!!"}}
    !/1 is/ {print}'

xyz
URK!!!
line 2 is ugly
myline 111 is nice

To use a shell variable in awk, you can use the -v option to pass it in as a real awk 
variable:

pax$ export xyzvar=URK ; echo '
xyz
myline 1 is pretty
line 2 is ugly
myline 111 is nice'  | awk -vmyvar=$xyzvar '
     /1 is/ {if (f) {print} else {f = 1;print myvar}}
    !/1 is/ {print}'

xyz
URK
line 2 is ugly
myline 111 is nice


You can accomplish it without sed. Bash script:

LINE=$(grep -n "$EXPR" "$FILE" |head -1 |cut -f1 -d:)
head -$(expr $LINE - 1 ) $FILE
tail +$(expr $LINE + 1 ) $FILE

Just declare $EXPR and $FILE.

From the sed FAQ:

sed '0,/RE/{//d;}' file        # delete only the first match
sed '0,/RE/s//to_that/' file   # change only the first match

If you are not using GNU sed, then check out the alternatives in the FAQ.

こういうケースのために、アドレス指定で0 を使えるようにしたんだっけか > GNU sed 1 だとうまくいかないパターンがあるんだよね。

■_ 買った

信長の忍び(4) (ジェッツコミックス)

四コマ仕立てだし、絵を見てもそうは感じられないと思いますが 結構まじめに歴史を追ってたりします。 桶狭間で今川義元が討たれるところは結構良かったな(ってそれだいぶ前の話)。

松永彈正いいわ。うんw

■_

GNU gettext 使って多言語メッセージをサポートしているプログラムを Windowsに持ってくるときにどうしようかで悩みんぐ。 いやまあ、GNU gettext 自体が移植されてたりするんでそれ使えという話も あるんでしょうけど、そこはそれいろいろと。

2011年06月28日

■_

カイジを観終わったところで轟沈。

■_

■_ 本気出す

【棺担ぎのクロ。】きゆづきさとこ 35【GA】 

853 名無しんぼ@お腹いっぱい [sage] 2011/06/18(土) 09:55:53.96 ID:uRxD8sXM0 Be:
    【1月】 初っ端から飛ばすと後でばてる。2月から本気を出す
    【2月】 まだまだ寒い。これではやる気が出ない。3月から本気出す
    【3月】 年度の終わりでタイミングが悪い。4月から本気を出す
    【4月】 季節の変わり目は体調を崩しやすい。5月から本気を出す
    【5月】 区切りの良い4月を逃してしまった。6月から本気を出す
    【6月】 梅雨で気分が落ち込む。梅雨明けの7月から本気を出す
    【7月】 これからどんどん気温が上昇していく。体力温存の為8月から本気を出す
    【8月】 暑すぎて気力がそがれる。9月から本気を出す
    【9月】 休みボケが抜けない。無理しても効果が無いので10月から本気を出す
    【10月】 中途半端な時期。ここは雌伏の時。11月から本気を出す
    【11月】 急に冷えてきた。こういう時こそ無理は禁物。12月から本気を出す
    【12月】 もう今年は終わり。今年はチャンスが無かった。来年から本気出す 

■_

Announce: Niecza Perl 6 v7 - nntp.perl.org

Niecza is a Perl 6 compiler project studying questions about the efficient 
implementability of Perl 6 features. It currently targets the Common Language Runtime; 
both Mono and Microsoft .NET are known to work. On Windows, Cygwin is required for 
source builds only; see the README for details.

へえ > CLR 向け

2011年06月27日

■_

練習どうしよう…というか原稿自体が以下略

■_ Compiler Construction, by Dr. Niklaus Wirth

Pascal でコンパイラーを書く。というのも前世紀のネタだろうとは思いますが、 ヴィルト先生のコンパイラー本のpdfからこういう話が reddit で展開されてました。

Compiler Construction, by Dr. Niklaus Wirth [PDF] : programming

Compiler Construction, by Dr. Niklaus Wirth [PDF] (inf.ethz.ch)


Best book on compilers (specifically on how to write one for Pascal) is 
http://www.amazon.com/Brinch-Hansen-Pascal-Compilers/dp/0130830984 but just shy of $60 
seems a bit steep - perhaps I should flog off my copy! And if anyone suggests the 
Dragon Book, I suggest they have never read it.


Can you give a quick overview of this book? I never heard of it.


It tells you how to write a Pascal compiler using recursive descent. All aspects are 
covered (lexing, parsing, code generation etc.), and you get the source of the 
compiler. The code is in Pascal, which may or may not be a plus point (personally I 
hate the stuff) but that doesn't really matter. Brinch Hansen, who unfortunately is no 
longer with us, was another of these great Danish CS guys. There must be something in 
the air over there - pig farts?


Indeed. Brilliant book.


I just got this book (used) a couple of weeks ago.

And I agree. This is a really good book. I especially appreciated the sections on 
testing, and how important it is that compilers generate correct code.

Have you seen downloadable source for the compiler in this book? I've scoured the web, 
(even left a message on comp.compilers) but have not been able to find it so far.

http://www.amazon.com/Programming-Language-Pragmatics-Third-Michael/dp/0123745144/


PLP is an excellent book covering many facets of programming language design, but it's 
not really relevant in a submission about compiler construction. PLP lightly touches 
on how certain features affect potential implementations, but doesn't go into details 
at all.

新品で60ドルかあ。

Modula-2 (でなくてもいいけど)で書かれた Modula-2 コンパイラー構築の本とか あったら欲しいなと思ったり。MODULE の扱いとかきちんとやろうとすると とんでもなく面倒くさくなるような気がする(というか、オブジェクトファイルのフォーマット とか実行ファイルまで手を入れないとだめなような気も…)。

■_ コピペ

あの有名テンプレにはまったものですが。

おもしろいコピペがあったら貼るスレinマ板part24 

909 仕様書無しさん [sage] 2011/06/26(日) 22:17:22.14 ID: Be:
    そんな事より>>26,27よ、ちょいと聞いてくれよ。スレとあんま関係ないけどさ。
    このあいだ、その千石2階に行ったんです。LEDやらICのフロア。
    そしたらなんか人がめちゃくちゃいっぱいで階段登れないんです。
    で、よく見たらなんか垂れ幕下がってて、150円引き、とか書いてあるんです。
    もうね、アホかと。馬鹿かと。
    お前らな、150円引き如きで嫌な2階に来てんじゃねーよ、ボケが。
    150円だよ、150円。
    なんか親子連れとかもいるし。一家4人で千石か。おめでてーな。
    よーしパパ凄いルーメンのLED買っちゃうぞー、とか言ってるの。もう見てらんない。
    お前らな、150円やるからその階から降りろと。
    あの2階ってのはな、もっと殺伐としてるべきなんだよ。
    Sの字形の階段上がってる時に上から降りてくる奴といつ喧嘩が始まってもおかしくない、
    刺すか刺されるか、そんな雰囲気がいいんじゃねーか。女子供は、すっこんでろ。
    で、やっと上がれたかと思ったら、踊り場の奴が、DSpicを、とか言ってるんです。
    そこでまたぶち切れですよ。
    あのな、DSpicなんてきょうび流行んねーんだよ。ボケが。
    得意げな顔して何が、DSpicを、だ。
    お前は本当にDSpicを使うのかと問いたい。問い詰めたい。小1時間問い詰めたい。
    お前、DSpicって言いたいだけちゃうんかと。
    千石通の俺から言わせてもらえば今、千石通の間での最新流行はやっぱり、
    テキサス、これだね。
    MSP。これが通の頼み方。
    MSPってのは超低消費。そんでもって低電圧電源可。これ。
    で、それにLCDを接続(ドライバなしでいける)。これ最強。
    しかしこれを頼むと次からあのドキュソ店員にマークされるという危険も伴う、諸刃の剣。
    素人にはお薦め出来ない。
    まあお前、26,27は、秋月に行ってまたPICライタでも買って書き込んでなさいってこった。

実は良くわからないw

■_ Why are people asking for a Perl name change again?

Perl 改名ネタ。

Why are people asking for a Perl name change again? | Mithaldu [blogs.perl.org]

Why are people asking for a Perl name change again?

By Mithaldu on June 27, 2011 9:22 AM

There has recently recently been an increase people asking, seriously or in jest, for
Perl 5 and/or Perl 6 to be renamed and others offering rebuffals of various types. You
could say a heated debate seems to be going on.

However, one thing stands out here: It does not seem to be clear to either party exactly
why the party is saying what it is saying. And when the realization arrives, some realize
that it should be fairly obvious and stop arguing, but do not make their realization
public, leaving others to make the same mistake.

As such, i'll try to put it into the most simple words i can here:
わたしにできるもっとも単純な言い回しで表現してみましょう

The existence of Perl 6 means that for the decision makers in IT, the managers and CEOs
who are not even programmers, Perl 5 appears to be obsolete.

Perl 6 の存在は、ITにおける decision makers、つまり
(プログラマーではない) マネージャやCEOのような人たちに対して
Perl 5が obsolete なものであると思わせているのです。

This is not a language issue, this is not a feature issue, this is not a community issue.
This is entirely an issue of marketing Perl 5 to the people who control the money,
because they decide which developers to hire and what languages to train their developers
in and which language to use in their next project. Many of them will not make the
decision based on how shiny Moose, Dancer or Mojolicious are, or how many modules there
are on CPAN. They will make the decision based on gut feeling and on how well they can
sell it to shareholders.

これは言語の問題 (language issue) ではありませんし、機能の問題でもコミュニティの問題でもありません。
これは完全に、お金を握っている人たちに対する Perl 5 のマーケティングの問題です
なぜならそのような人たちは
決定するからです
どの developers を雇うのか
train their developers するための言語
次のプロジェクトで使う言語はなんなのか
many of them は make the decision しません
how shiny に基づいて
どれほど多くのモジュールが CPAN にあるか
彼らは gut feeling や how well they can sell it to shareholders に基づいて
make the decision します。


The name Perl 6 implies to non-technical people that it is newer and better than Perl 5
and that Perl 5 is abandoned and a waste of time and money to invest in. There is a lot
of vibrancy and activity in the Perl 5 community, with new tools and toys springing up
weekly and improvements being made to the core regularly, but this is only visible to
programmers, people who are on the ground and working on it.

Perl 6という名前は implies します
non-technical people に
それが Perl 5よりも新しく良いものであること
Perl 5が放棄 (abandoned) され
それに興味を持つことが時間と金の浪費である
Perl 5 コミュニティには a lot of vibrancy and activity がありますが、
これはプログラマーや people who are on the ground and working on it
にだけ visible なものです。


People who ask for name changes do not do it so they can effect great upsets in the Perl
development. Perl 5 has had a great many upsets since it was first called Perl 5.

名前の変更を求めている人たちはそういった活動をしていないので、
effect great upsets in the Perl development できるのです。
Perl 5 はそれが Perl 5 と呼ばれるようになってから
 had a great many upsets
しています。

People ask for name changes so they can show the rest of the world just how alive Perl 5 really is.

■_ integer overflow - Bug in quicksort example (K&R C book)?

何年か前にJavaで話題に…は二分検索だっけ?

integer overflow - Bug in quicksort example (K&R C book)? - Stack Overflow

This quicksort is supposed to sort "v[left]...v[right] into increasing order"; 
copied (without comments) from The C Programming Language by K&R (Second Edition):

void qsort(int v[], int left, int right)
{
    int i, last;
    void swap(int v[], int i, int j);

    if (left >= right)
        return;
    swap(v, left, (left + right) / 2);
    last = left;
    for (i = left+1; i <= right; i++)
        if (v[i] < v[left])
            swap(v, ++last, i);
    swap(v, left, last);
    qsort(v, left, last-1);
    qsort(v, last+1, right);
}

I think there's a bug at

(left + right) / 2

Suppose left = INT_MAX - 1 and right = INT_MAX. Wouldn't this result in undefined 
behavior due to integer overflow?

It was probably programmed with the assumption that an array wouldn't be that large at 
runtime. :)

That's a very good assumption since you wouldn't have space in memory for your 
quicksort program

See also: googleresearch.blogspot.com/2006/06/… – 

Yes, you're right. You can use left - (left - right) / 2 to avoid overflows.

You aren't imagining an array with INT_MAX number of elements, are you?

確かに pivot を決めるためのこの計算に注目するのは悪くないと思うんだけど、

    qsort(v, left, last-1);
    qsort(v, last+1, right);

この辺りが引き金になるパフォーマンスバグは気にしないでいいのかなあ。などと思ったり。 その辺気にしだすと、だんだん複雑怪奇になるのだけど>クイックソート

■_

sl4m/gnu_smalltalk_koans - GitHub
https://github.com/sl4m/gnu_smalltalk_koans#readme

R and citations by David Firth | (R news & tutorials)
http://www.r-bloggers.com/r-and-citations-by-david-firth/

Object-oriented design patterns in the kernel, part 2 [LWN.net]
http://lwn.net/Articles/446317/

Debugging compilers with optimization fuel : Inside T5
http://blog.ezyang.com/2011/06/debugging-compilers-with-optimization-fuel/

Things you (probably) didn't know about xargs
http://offbytwo.com/2011/06/26/things-you-didnt-know-about-xargs.html

Why is Mercurial considered to be easier than Git? - Programmers - Stack Exchange
http://programmers.stackexchange.com/questions/87217/why-is-mercurial-considered-to-be-easier-than-git

2011年06月26日

■_

しかし、ダムエーを置いているのにアフタヌーンを置いていないコンビニがけっこうあってびっくりした。 以前はアフタヌーンも結構コンビニで見かけた覚えがあるんだけどなあ。

・-ize
最近(でもないか)使われるようになってきた、 「コミカライズ」という単語を見かけるたびに引っかかるものがあったのですが、 やっぱりそういうものだったらしいです(謎) Ize | Define Ize at Dictionary.com Comic | Define Comic at Dictionary.com コミカライズとは - はてなキーワード 「コミカライズ」という言葉はおかしくありませんか? Novel と.. - 人力検索はてな 漫画化 - Wikipedia
もう好きにしてw

■_ 名前重要?

Perl, Perl 5, Perl 6, and Names - Modern Perl Books, a Modern Perl Blog


Modern Perl Books, a Modern Perl Blog

Modern Perl programming, circa 2011, relies on the collected wisdom of the entire Perl 
ecosystem. It's time to write elegant, reliable, maintainable, well-tested, and 
predictable code.

Perl, Perl 5, Perl 6, and Names

By chromatic on June 24, 2011 1:33 PM

Let's change the name of Perl 6. Why not change the name of Perl 5 too?

Perl 6 の名前を変えようではありませんか。Perl 5 の名前も一緒に変えてみたら?

The benefit to Perl 6 is obvious, in the same way that applying liberal amounts of 
lubricant to a mechanical joint producing an extended and incessant whining sound is 
an obvious solution.

Perl 6 の benefit は明らかです。


Think about it though. Perl 5 would be free to break backwards compatibility. More 
than that, it could stop halfway borrowing features from Perl 6 that are impossible to 
introduce properly to Perl 5 because Perl 5's infrastructure just can't support them.

考えてみると、Perl 5 は後方互換性を壊すことに自由になるかもしれません。
もっと言えば、サポートできるインフラがないために Perl 5に適切に導入できないような機能を
Perl 6 から拝借してくることも中途で止められるかもしれません。


It could remove features and vestigial libraries from the core, like dumpvar.pl (look 
it up) and h2xs. It could clean up the bareword lexing mess and the dative syntax mess. 
It might even allow the autopromotion of bare blocks into first-class functions in 
places other than only the first argument of a predeclared and prototyped function.

dumpvar.pl や h2xs のような機能や vestigial libraries はコアから取り除けるかもしれません。


All of the creaky old ported-straight-from-Fortran tutorials would obviously no longer 
apply. Awful, awful examples and books would no longer work. Search engine result 
ranks would be open to a shiny new world of good code and great documentation from the 
start.

We also wouldn't have to use those stupid branding terms like "Modern Perl" 
or "Enlightened Perl" or "Perl Renaissance" or "Kensho" 
or "Foundation" or "Equites Synarchic".

わたしたちはまた、
"Modern Perl" 
"Enlightened Perl"
"Perl Renaissance"
"Kensho" 
"Foundation"
"Equites Synarchic".
のような馬鹿げた branding terms を使うべきではないでしょう。


Yes, so many problems would simply go away by changing at least two of four letters in 
the name "Perl". Maybe three. Or maybe adding a letter, or changing one of 
them to a number, or maybe a snowman glyph. Something that would look nice on a tattoo, 
or alliterates better than "Desperate Perl Hacker". The word 
"puppy" is nice. Can you work that in there somewhere?

そう。多くの問題が、"Perl" という名前にある四文字のうちの少なくとも二つ、ひょっとしたら
三つを変えることだけで解決できるでしょう。あるいは一文字追加するか、
文字のひとつを数字に変えるか雪ダルマの glyph に変えてもいいでしょう。


Don't worry about losing mindshare. Don't worry about confusing people. After all, the 
name "Perl" means exactly what you think it means right now, whether you 
first used Perl 1 in 1987 or last used Perl in 1987. If Perl, the concrete thing, is 
to change from what you think it means right now at this moment—this perpetual now, 
where there is no future and there is no past, just a bundle of electrical impulses 
sailing an eternal and constant voyage between wads of synapses—to something else, it 
must have a different name. There is no ideal. There is only what we see and 
experience in the immediate. (You kind of have to accept this anyway if there's no 
specification against which you can accurately measure a concrete thing's Perlishness.)

mindshare を失うことを恐れることはありません。
人々が混乱することを恐れることはありません。


Yes, renaming Perl 5 will immediately heal ten years of a great divide in the snap of 
my fingers. It will save the Perl community from the tyrannical march of version 
numbers (the horror, the horror). It will squelch the smoldering debates over whether 
the second item in a set of dotted decimal triplets is a sub-version or a major 
version or a minor version (and the families of the victims might finally know peace).

Perl 5の改名は即座に解決するでしょう
ten years of a great divide を

(two paragraphs elided; I wasn't sure whether to include them, which should have been 
a sign not to do so. I hereby apologize to Alberto for my poor judgment)

Just don't argue with me over the version numbering scheme. It's 2011.06.24.14.00.38 
as all good hearted people will obviously agree.

This blog is licensed under a Creative Commons License.

くっ。時間が(あとで埋めます

■_

↑の発端。

Perl, Perl 5, Perl 6, and names | Alberto Simões [blogs.perl.org]
Perl, Perl 5, Perl 6, and names

By Alberto Simões on June 23, 2011 2:17 PM under Perl

First, please, you are free to comment, but I do not want to open a flame war or 
anything. Also, I do not think this is the place for this to be discussed. This post 
is just my humble opinion.

I think Perl 6 is a bad name for the new language Larry (and Damian and others) are 
defining. First, before the language, although based on Perl 5, is a new language. 
Second, because the name is around for too many time, making it bad advertising for 
the language itself, and for the community. Third, because it makes hard to Perl 5 to 
advance.

わたしは、Perl 6 というのはLarry (と Damian、そしてそのほかの人々)が定義する
ところの新言語の名前として良くないものであると考えています。
第一に、この言語の前にその元となった Perl 5 がありましたが、これは新言語であるからです。
第二に、この名前はあまりにも多くの、自身とそのコミュニティにに対して
悪評をもたらしてしまっているからです。
#趙訳上等○| ̄|_
第三に、Perl 5 を発展させることを困難にしているからです。

In fact, I think that keeping the name of the new language as Perl 6 is bad for 
everybody, from the people that do not like Perl 6, for the people who love Perl 6, 
and for all the community members.

事実、Perl 6を新言語の名前として使い続けるのは誰にとっても良くないことであると
わたしは確信しています。
Perl 6 を好まない人から Perl 6を愛する人まで、そしてコミュニティの皆にとって。

I know there are some books out already that have Perl 6 in their names. But they are 
not best sellers, and changing Perl 6 name will not be that relevant.

Perl 6をその名前に冠した本がすでに数冊あることはわたしも知っています。
しかし、それらは best sellers ではありませんし、Perl 6の名前を変えても
それほど影響ないでしょう。

My point of view (thinking on advertising strategy, mostly) is that we should rename 
Perl 6 to something else. Camelia would be an option. You can also glue Perl with Six, 
and call it Perlix or Perlvi if you like roman numbers. In fact, Camelia would be the 
best.

わたしの主張は (広告戦略的に考えてみて)、Perl 6という名前を何かほかの名前に
変えるべきだというものです。Camelia はそのひとつの候補となるでしょう。
Perl に6(Six)というのをつけるのも可能ですが、
もしローマ数字がお好きなら、Perlix や Perlvi と呼んでもよいでしょう。
とはいえ、Camelia がベストではないでしょうか。

Then, we have another problem. We can't make Perl 5 advance to Perl 6. Also, it is not 
a good idea to keep Perl 5 current version strategy. As somebody already suggested in 
Perl 5 porters list, we should drop the five. So, next Perl version would be Perl 16!

それからもうひとつ、別の問題をわたしたちは抱えています。
わたしたちは Perl 5 を Perl 6へと発展させることはできないのです。
また、Perl 5 という current version を保ち続ける戦略もよろしくありません。
Perl 5 porters list で誰かがすでに提案していたように、わたしたちはその 5 を
落とすべきであり、そうすれば次なるバージョンの Perl は Perl 16 となるでしょう!

More than thinking with the heart, we should check what marketeers would do...


■_ なんでもJS

いや、前にもあったか? awk on JavaScript

SpiderMonkey, jsawk & resty on Snow Leopard | John Attebury

SpiderMonkey, jsawk & resty on Snow Leopard

June 25, 2011 by John Attebury

I recently needed to parse JSON from the command line. A GIS yielded a StackOverflow answer: jsawk.

There were other possibilities V8, Python, Perl and PHP, but a Javascript and Awk 
solution looked promising (and as a Javascript guy, the easiest to pickup). So after a 
bit of trial and error, here's what worked for me.

(略)

# Install jsawk – you can put this wherever you like, I used ~/Code
# For more info, see https://github.com/micha/jsawk

$ mkdir ~/Code
$ cd !$
$ curl -L http://github.com/micha/jsawk/raw/master/jsawk > jsawk
$ sudo ln -s jsawk /usr/bin/jsawk

# Install resty
# For more info, see https://github.com/micha/resty

$ curl -L http://github.com/micha/resty/raw/master/resty > resty
$ source resty

# View the current host (you can change this at anytime), outputs URL

$ resty

# For this demo, set the host to Twitter

$ resty http://api.twitter.com

# View host again to verify the change, outputs http://api.twitter.com/*

$ resty

# Get an array of dates from recent tweets on Twitter's public timeline

$ resty GET /statuses/public_timeline.json | \
jsawk  'return this.created_at'

# Get my recent tweets

$ resty GET /statuses/user_timeline/johnattebury.json | \
jsawk  'return this.text'

Integrate jsawk into your shell scripts and you've got an excellent JSON parser ready 
for interesting problems. Combine jsawk with resty and a world of JSON api's is just a 
prompt away.


なんか名前の響きがよさげだ> jsawk

spidermonkey のバイナリは…転がってないだろうなあ。 以前自分でやったことがあるけどだいぶ前だ。

■_

■_

来週月曜日から、偽サマータイムのために一時間早く起きなければなりません。 すると寝る時間も一時間繰り上げて…といきたいのですがそうも行かない個人的事情が (会社からすりゃあ知ったこっちゃないでしょうが)… ということで、これまで以上に更新がぐだぐだになる可能性が大です。

2011年06月25日

■_

完結
【安彦良和】機動戦士ガンダムTHE ORIGIN 65号 [chaika]
本当に十年やってたんだなあ。色々と書きたい(言いたい)ことはあるけど、とりあえずは 「リメイク」って難しいね。くらいか(「リメイク」じゃないとかどっかに書かれた覚えもあるけど)。 細かいところで、あのシーンがなかったこのシーンがなかったというのもあるけれども、 途中から違和感が期待感を上回ってしまった気がする。

新刊
FRONT MISSION DOG LIFE & DOG STYLE(7) (ヤングガンガンコミックス) 書店で見かけて気がついた。 一応新刊チェックはしているはずなんだけどなあ。
買ってないのにアサマシを貼りますがw、ざっと見た感じでは悪くない感じですね。 とはいえ、海千山千なそこのアナタにとってはすでに知っているものが多いでしょうけど :) シリーズもので、あと二つ続刊があるらしいのでそっちにも期待。 財布の中身やらなんやらのしがらみで買う(買える)かどうかはわからんけど
独習コンピュータ科学基礎I 離散構造

・(偽)サマータイム
サマータイムは不健康…睡眠学会が反対を提言へ : 社会 : YOMIURI ONLINE(読売新聞)
某社の総務に突きつけたい。

■_ 白熱

組み込みプログラマー雑談スレッド その20 

9 仕様書無しさん [sage] 2011/06/24(金) 21:37:42.84 ID: Be:
    前スレ最後あたりに、Cをたいしてしらずに語ってる人もいたし、
    新人を馬鹿に出来ないな 

10 仕様書無しさん [sage] 2011/06/24(金) 21:56:14.16 ID: Be:
    その新人を教えてるのが 

11 仕様書無しさん [sage] 2011/06/24(金) 22:56:05.14 ID: Be:
    >>9
    それって君の事なんじゃないの?w

    Cの配列の意味も知らずに、構造体の中に要素数不定の配列が置けるとか言ってたの、
    たぶん君でしょ? 

12 仕様書無しさん [sage] 2011/06/24(金) 23:00:08.51 ID: Be:
    GCCなら、引数に要素数不定の配列が書けるな。
    使う方はもの凄く楽だが、互換コンパイラ作らされると死ねる。 

13 仕様書無しさん [sage] 2011/06/24(金) 23:04:54.54 ID: Be:
    だからそんなものはどのCコンパイラでも書ける。
    それはポインタの糖衣構文なんだよ。
    前スレでも出た話でしょ?

    そもそもCには、C的な意味で「配列」という言葉を使うならば、
    要素数が不定の配列なんてものはないのだから。

    この変なんか勘違いしてる人はjavaとかから入った人かね 

14 仕様書無しさん [sage] 2011/06/24(金) 23:11:18.34 ID: Be:
    char hoge[]={0,1,2,3,4,5,6,7,8,9}; 

15 仕様書無しさん [sage] 2011/06/24(金) 23:36:03.11 ID: Be:
    >>13 結局勘違いしたままだね、君は。
    糖衣構文ではない。

    {
    int foo;
    char *bar;
    }
    これはメモリの構造としては、

    [ int ]
    [ ptr -]---> [char|char|char|char|...]

    こうなる。

    {
    int foo;
    char bar[];
    }

    これは、

    [ int ]
    [char|char|char|char|...]

    こうなる。

    わかってないのはおまえだ。
    それから、今時 C99 ぐらい知っておけ。
    ttp://seclan.dll.jp/c99d/c99d04.htm#dt19990726 

16 仕様書無しさん [sage] 2011/06/24(金) 23:45:13.77 ID: Be:
    また、微妙な 

17 仕様書無しさん [sage] 2011/06/25(土) 00:16:51.93 ID: Be:
    >>15
    なんか痛い人だね。
    君が自分で示した参照先のコード、ちゃんと読んでるか?

    正直に言うと俺はそれを知らなかったけど、君の理解も間違ってる。

    それは構造体の中に可変長の配列が入っているんじゃない。

    あくまでポインタでポイントされたあるメモリ領域を、構造体の最後に
    ある特定の長さの配列が入っているかのように扱う時のための表記法でしょ。

    > char bar[];
    要するにこれは単なるプレースホルダーの役割を果たしてるだけ。

    だから何度もその構造体の値を変数に代入したらどうなるんだって言ってるじゃないか。
    C言語的な意味で構造体の中に配列が入ってるのならば、配列自体もコピーされないとおかしいだろう。 

18 仕様書無しさん [sage] 2011/06/25(土) 00:28:02.20 ID: Be:
    >>17
    C言語的には、int fooと長さ0バイトの配列を持った構造体。
    長さ0バイトの配列がちゃんとコピーされるよ。 

19 仕様書無しさん [sage] 2011/06/25(土) 00:33:36.31 ID: Be:
    言葉の解釈が 

20 仕様書無しさん [sage] 2011/06/25(土) 00:35:08.46 ID: Be:
    つまり、使い方を知らないんだな。
    struct unko* unkop = (struct unko*)malloc(sizeof(unko) + 10);
    これで、unkopはあたかも
    struct unko{
    int len;
    char name[10];
    }
    という構造体へのポインタのように使える。 

21 仕様書無しさん [sage] 2011/06/25(土) 00:37:22.98 ID: Be:
    え、使えんだろ 

22 仕様書無しさん [sage] 2011/06/25(土) 00:41:25.77 ID: Be:
    あぁ、コピーしたい時には代入とか使わずに
    (コピー先の大きさを考慮しながら)memcpyとかでコピーするんだよ。 

23 仕様書無しさん [sage] 2011/06/25(土) 00:45:22.34 ID: Be:
    struct unko{
    int len;
    char name[1];
    };
    これじゃないとおかしくならないか、確保した後の動作が?
    struct unko* unkop = (struct unko*)malloc(sizeof(unko) + 10);

24 仕様書無しさん [sage] 2011/06/25(土) 00:47:09.41 ID: Be:
    コンパイラとしては、長さ0の配列とみなしてるんだけど
    プログラマが
    「実際にメモリあるんならそんだけの配列として使って問題ないだろ?」
    って使ってしまうってのはいかにもC言語的な流儀ではあるな。 

27 仕様書無しさん [sage] 2011/06/25(土) 07:41:57.06 ID: Be:
    >>23
    いいや。少なくともC99準拠なコンパイラなら
    struct unko{
    int len;
    char name[];
    };
    はおかしくならない。
    つまり、unko.nameは常にunko.lenの次のアドレスを指す。
    (場合によってはパディングが入ったあとのアドレスかもしれないが)
    C99以前のコンパイラで同じコードを通すかどうかはコンパイラ次第だな。 

28 仕様書無しさん [sage] 2011/06/25(土) 07:56:21.48 ID: Be:
    構造体の中のアドレスは気をつけたほうがいい。
    sizeof(int)倍のアドレスしかchar name[]に割り当てられない場合もあるそうな

    不定長の配列なんて俺は使いたくないな。固定長にする。 

29 仕様書無しさん [sage] 2011/06/25(土) 07:59:20.33 ID: Be:
    gccは大昔から成る。まぁC99がgccの追認だからな。
    しかし「次の」アドレスを指すとは限らない。CPUアーキによって「次」の定義が色々だからな。

    そんなことより、unkop とかいうリテラル名を使いたがるおまいらのセンスに絶望したっ! 

拡張云々はともかく、最後の配列を [1] にしといて実は…てのは割とありましたね。 構造体のメモリ割り当てするときに、 * なメンバーだと二回 malloc しないといけないけどこのようにしておくと一回でできる。と。 これはこれで問題があるので、どちらかといえば廃れたテクニックかなあ。

■_ E

Emperor の E からとったんじゃなかったっけ?(要出展) プログラミング言語 C の新機能

【R言語】統計解析フリーソフトR 第4章【GNU R】

90 132人目の素数さん [sage] 2011/06/24(金) 09:20:34.16 ID: Be:
    format="%Y/%m"
    と書くと
    2011/06
    と出力されるけど、幅を節約して
    11/06
    とするにはどうすれば? 

91 132人目の素数さん [sage] 2011/06/24(金) 09:22:44.15 ID: Be:
    あ、ぐぐったら一瞬で判ってしまった
    %y だ 

92 132人目の素数さん [sage] 2011/06/24(金) 10:43:36.69 ID: Be:
    >>90,91
    そのあたりは共通だから覚えておいて損はないよ。

    > format(Sys.Date(),"%Y")
    [1] "2011"
    > format(Sys.Date(),"%y")
    [1] "11"
    > format(Sys.Date(),"%EY")
    [1] "平成23年"
    > format(Sys.Date(),"%Ey")
    [1] "23"

93 132人目の素数さん [sage] 2011/06/24(金) 12:32:27.69 ID: Be:
    おおー
    なんでEが平成なんだろう 

94 132人目の素数さん [sage] 2011/06/24(金) 13:01:48.18 ID: Be:
    >>93
    マニュアルには、
    %E Modifier: use alternative format
    と書いてあるよ。つまり日本語ローケルだと、日本語化した形式にするという意味。

    >>92を書き込んだ後、MacOSXとWindowsで試してみたが、
    どちらも和暦にならなかった。GNUだけかも。ヘルプには環境依存って書いてあるしね。

■_

  "Modern Perl 5 tutorial, part 1" 
http://szabgab.com/blog/2011/06/modern-perl-5-tutorial-part-01.html

  "Perl, Perl 5, Perl 6, and Names - Modern Perl Books, a Modern Perl Blog" 
http://www.modernperlbooks.com/mt/2011/06/perl-perl-5-perl-6-and-names.html

  "Old Tricks, New Dogs: Removing Branches ≫ #AltDevBlogADay" 
http://altdevblogaday.org/2011/06/24/old-tricks-new-dogs-removing-branches/
  

時間が~

■_

■_ その分岐を消せ

こういうの好きな人多そう(誰とは言わないw

Old Tricks, New Dogs: Removing Branches » #AltDevBlogADay

Prior to the CMOVcc instruction being introduced on the PentiumPro, some nifty bit 
tricks were used for removing branches on x86 cpus.

PentiumPro で  CMOVcc 命令が導入されるまでは、
x86 CPUで分岐を取り除くためにちょっとしたトリックが使われていました。

static inline uint32_t branchless_min( uint32_t a, uint32_t b ) {
  register uint32_t tmp;
  __asm__ (
    // Intel syntax (compile with -masm=intel), not AT&T syntax
    "sub %0,%2\n\t"     // a - b
    "sbb %1,%1\n\t"     // a < b ? -1 : 0
    "and %0,%1\n\t"     // a < b ? a - b : 0
    "add %0,%2\n\t"     // b + ( a < b ? a - b : 0 )
    : "+r&"(a), "=r&"(tmp)
    : "r"(b)
    : "cc"
  );
  return a;
}

Guess what, the PowerPC inside of today's consoles has no integer conditional move, 
so these old skool tricks are back with a vengeance!

static inline uint64_t branchless_min( uint64_t a, uint64_t b ) {
  register uint64_t t0,t1,t2;
  __asm__ (
    "subfc  %0,%4,%3\n\t"   // a - b
    "subfe  %1,%1,%1\n\t"   // a < b ? -1 : 0
    "and    %0,%0,%1\n\t"   // a < b ? a - b : 0
    "add    %2,%0,%4\n\t"   // b + ( a < b ? a - b : 0 )
    : "=r&"(t0), "=r&"(t1), "=r"(t2)
    : "r"(a), "r"(b)
    : "xer"
  );
  return t2;
}

It is quite satisfying when something you've learnt a long time ago, and had long 
since filed away as a relic of the past, shows up again as something useful in the 
here and now. Unlike the many brain cells sacrificed to the mighty beer gods, these 
ones were put to good use after all! Plus it meant i could use a silly title for this 
post.

But why is it important to remove branches ?
(略)

© 2011 #AltDevBlogADay 		Suffusion theme by Sayontan Sinha

2011年06月24日

■_

新しいC の入門書を見かけたときには、 まずは索引の「あ」の項目とか「さ」の項目をたどって調べたりします

■_ 4th

そいや Programming Python の日本語訳って、第2版まででしたっけ?

A Review of Programming Python 4th Edition | Book Zone

Review

This book is not for the Python noob, it doesn't cover any of the language fundamentals
(e.g. looping constructs, operator precedence etc.), and defers all discussion of these
introductory topics to Oreilly's Learning Python 4th edition, also written by Mark Lutz.
Instead this book focuses on applying Python to meet real world programming challenges
across three programming domains:

この本はPython入門者のためのものではありません。
(ループ構造だとか演算子の優先順位のような) 言語の基本的な部分は一切カバー
していません。そういった諸々のトピックは Mark Lutz の手による
Oreilly の Learning Python 4th edition に委ねられています。


    * System programming,
    * GUI Programming  with the tkinter library, and
    * Internet Programming.

Special attention was given to cross platform compatibility and the use of the Python 
Standard Library.

(略)

If you are considering the use of Python 3.x for your next project, or planning to 
update an existing application you will want to read this book first. For some 
applications Python's Unicode issue and other regressions may not be an issue (e.g. 
system scripting) for others the current state of Python may be a deal breaker. But 
after reading this book you will have the knowledge needed to make an informed 
decision one way or the other.

もしあなたが次のプロジェクトや計画している既存のアプリケーションのアップデート
に Python 3.x を使うことを考えているのであれば、まずはこの本を読んでみたくなる
でしょう。

英語でも何でも興味はあるんだけど、ボリュームありすぎだよなあ(^^;

■_ いてれーた

23のパターンのうち、最初に理解(じぶんのものに)できたのってこの辺かなあ。 visitor は未だに(ry

The Essence of the Iterator Pattern - A++ [Eric Torreborre's Blog]

24 June 2011 

The Essence of the Iterator Pattern

"The Essence of the Iterator Pattern"(EIP) is the paper I liked the most 
last year. It gave me a brand new look over something which I had be using for years: 
the for loop.

"The Essence of the Iterator Pattern"(EIP) は
昨年わたしが見た中でもっとも好きな論文です。
これはわたしに for ループという長いこと使ってきたものに対して
新しい観点をもたらしたのです。

In this post I'll try to present some ideas of that paper and show how to implement 
the solution described by the authors using Scalaz-like code. A minimum previous 
exposure to functional programming, functors and monads will definitely help!

このポストではその論文にあったアイデアのいくつかを present することを試みます。

What's in a for loop?
for ループの中にあるのは何?

That was really what hooked me. What do you mean "what's in a for loop"?. Is 
there anything magic in that construct I've been using for years?

The introduction of EIP shows an example of a for loop. I'm transmogrifying it here to 
Scala but the idea remains the same:

EIP の導入部では、for ループを例にとっています。
ここではそれを Scala に変換したものを例示しますが、考え方は変わっていません:

  val basket: Basket[Fruit] = Basket(orange, apple)
  var count = 0

  val juices = Basket[Juice]()
  for (fruit <- basket) {
    count = count + 1
    juices.add(fruit.press)
  }

We start from a "container" of fruits: Basket. It could actually be anything, 
a List, a Tree, a Map... Then the for loop actually does 3 things:

話を fruits の“コンテナー”であるバスケットから始めます。
それは実際にはリストかもしれませんし、Tree か Mapかもしれません。
そして、この for ループは三つのことを行っています。

   1. it returns a container having the same "shape"; juices is still a Basket
      同じ“姿形をした”ジュースはバスケットに残ったままです
      コンテナーを返します

   2. it accumulates some kind of measure. Here, the number of fruits in the count variable
      なんらかの measure で accumlate する
      この例ではcount 変数に格納されるフルーツの数がそれである。

   3. it maps the elements to other elements: pressing the fruits to get some juice
      要素を別の要素へ写像(map) する: ジュースを得るためにフルーツを押しつぶす

And this for loop is actually not the most complex:
そしてこの for ループは実際のところもっとも複雑なものではありません。

    * the count variable could influence the mapping of elements:
      juices.add(fruit.press(harder=count))

      変数 count は要素の写像に影響を及ぼす可能性があります:

    * we could have several variables depending on each other:
      cumulative = cumulative + count

      相互に依存した複数の変数を持つかもしれません

    * the mapping could also influence a "measure" variable:
      liquid = liquid + fruit.press.quantity

      ここで行う写像が "measure" 変数にも影響するかもしれません:

The purpose of EIP is to show that the "essence" of what happens in the for 
loop above can be abstracted by an Applicative Traversal. And the authors go on 
showing that given this Applicative abstraction, we get an incredible modularity for 
programming.

EIP の目的は、Appicative Traversal によって抽象化されている可能性のある上述の
for ループの中で起こっていることの“エッセンス”を明らかにすることです。
そして、著者は続いてこの Applicative Traversal にも言及していて、
わたしたちはプログラミングについての incredible modularity を手にします。
#なんか違う感が

■_

2011年06月23日

■_

アレとかアレのフラゲに失敗 ○| ̄|_

■_ Scala ネタその1

あとで訳つけます ○| ̄|_

Furious Bob » Blog Archive » Why moving to Scala? Part I – Writing less code

Why moving to Scala? Part I – Writing less code
なぜ Scala に移行するのか?

Tuesday, June 21, 2011, 11:03

The past couple of years we've seen a blooming of new languages that run on top of JVM. 
This is not news to anyone. But, moving towards one of those languages is not an easy 
task, you will need something really strong to motivate you to do it.

過去数年、わたしたちはJVM上で動作する新しい言語のbloomingを目撃してきました。
それはすべての人に対して新規のものではありませんが、
そういった言語の一つに移ることは簡単な task ではなく、
言語を移るための強力な同期が必要となるでしょう。

After just a few weeks playing with Scala, I think I finally have a new favorit language to
code. Ruby and Groovy are great, but they are dynamic type languages (I'm not going into a
philosophical discussion here on which approach is right) but to me, static typed languages
make code easier to read, and that's something I'm interested in.

Ruby や Groovy はgreat ですが、これらは動的型付け言語です (ここでは静的動的いずれのアプローチ
が正しいかという哲学的議論をするつもりはありません) が、わたしにとって静的型付け言語はコード
を読むのを簡単にし、わたしが興味を持つようななにかにするのです。


So why Scala? Well one point is that you write less code, another is that you benefit 
from Functional behavior and finally you get the extras (Traits, Actors)

ではなぜ Scala なのでしょうか? ポイントの一つは (比較して) 少ないコードを書けばよいという
ことであり、もうひとつは関数的な振る舞いから利益を得られること、さらにそれに
おまけ (Traits と Actor) も手に入るということです。


This first part I'm just gonna show the less code part ok? Later I'll show interesting 
stuff like Traits, Actors, and Functional Programming.

前者については実例をご覧に入れましょう。後者については Traits、Actors、関数プログラミングの
ような interesting stuff を取り上げます。

1. Dynamic Maps (動的な map)

Have you ever had to create a List>? I bet my horses that you had. And don't you 
hate the way it looks at the end? Don't you hate having to instantiate a Hashmap, and 
then use put methods on it? I bet you do, so how can we save time by moving from this:

これまでに List> を作らなければならないことはありましたか?
あなたはそれを経験しているだろうとわたしは確信しています。
そのようなやり方をすることが終いにはイヤになりませんでしたか?
まず Hashmap を作ってからメソッドを使って put していくのに嫌気を感じたことはありませんか?
I bet you do, so how can we save time by moving from this:
きっとあなたは嫌気を感じたでしょう。では、次のようなコードからどのようにすれば時間を節約
できるでしょうか:


  	public List<Map<String, Object>> createList(){
  		List<Map<String,Object>> entries = new ArrayList<Map<String,Object>>();
  		Map<String, Object> e1 = new HashMap<String, Object>();
  		e1.put("name","john");
  		e1.put("age",35);
  		Map<String, Object> e2 = new HashMap<String, Object>();
  		e1.put("name","mary");
  		e1.put("age",32);
  		entries.add(e1);
  		entries.add(e2);
  		return entries;
  	}

Now let's compare with scala version:
ではこれを Scala バージョンと比較しましょう:

  val entries = List(Map("name"->"joe","age"->35),Map("name"->"joe","age"->32))

Wow, just one liner? Yep! And it's gonna be like this many many times

2. Avoid creation of instance variables
   インスタンス変数の生成の排除

Well lets have a look at the following java code:
さて、では次のJavaコードから見てみましょう:


  public class Shape {
  
  		private int height;
  		private int width;
 
  		public Shape(int w, int h) {
  			this.width = w;
  			this.height = h;
  		}
 
  		public void setWidth(int w) {
  			this.width = w;
  		}
 
  		public void setHeight(int h) {
  			this.height = h;
  		}
 
  		public int getWidth() {
  			return width;
  		}
 
  		public int getHeight() {
  			return height;
  		}
 
  	}

This whole variable assignment is just boilerplate code, you really don't need them on Scala:

ここでの変数代入は単なる boilerplate code です。Scala ではそれが必要になることはありません:

  class Shape(val width:Int, val height:Int){
  }

Again? Just one line? Yep, you've been doing boilerplate code for a long time right? 

We just saved 25 lines here
ここでは25行を節約しただけです


On Scala, if you prefix you constructor arguments with either val (immutable) or var 
(mutable) keywords, a field instance is already created for you.

Scala では、val (immutableなもの) か var (mutable なもの) というキーワードをコンストラクター
の引数に前置するとフィールドインスタンスが作られます。


3. Default values for method arguments
   メソッドの引数に対するデフォルト値

I miss this :( I hate having to do this:
これを見落としていました :( 次のように書くのは嫌いです:

  public void draw(Integer sides, Float radius){
  			if(sides == null || sides == 0){
  				sides = 3;
  			}
  			if(radius == null || radius == 0){
  				radius = 1.0f;
  			}
  		}

Where I could be doing :
これは次のようにできます:

  def draw(side:Int=3, radius:Float=1.0f) = {    
  }

I really find this default value handy. And we just saved another 6 LOC

このデフォルト値は便利であることに気づきました。
また、それ以外にも6行節約しています



4. Forcing constraints
   制約の強制

Sometimes you need to enforce a specific domain constraint on your objects. Let's say 
you don't wan't your Shape class to have width and values that are less equal than 
zero right. So:

あなたのオブジェクトを特定のドメインに制限するように強制しなければならないことがあるかも
しれません。さてここで、あなたが自分のクラス Shape がゼロよりも小さな値を持たないように
したいとしましょう。こんな感じになりますね:


  public Shape(int w, int h) {
  			if(w <= 0 || h <=0){
  				throw new IllegalArgumentException();
  			}
  			this.width = w;
  			this.height = h;
  		}

In Scala we can actually force this on our class as required constraints:

Scala ではこれを required constraints として強制できます: 

require(width>0 && height>0)

Now, free your mind and read both snippets of code again, doesn't the Scala version 
makes way more sense now?

さあ思い込みを捨てて、二つのコード片をもう一度読んでみてください。
Scala 版の方がより意味がわかりやすい方法ですよね?


5. Type inference
   型推論

Although Scala is a static typed language, it can reduce part of you boiler code as it 
can infer some types for you.

Scalaは静的型付けの言語ですが、推測可能ないくつかの型では boiler code の部分を reduce できます

  
  Integer x = 1;
  List<Integer> intList = new ArrayList<Integer>();
  intList.add(1);
  intList.add(2);
  intList.add(3);


  val x = 1
  val intList = List(1,2,3)


The Scala code you don't need to define the type, as the compiler will infer for you, 
also note how simpler it is to declare lists. Thanks God Java 7 has something called 
the diamond operator which will allow you (not me as I'll quit writing java code by 
there) write things like this: List list = new ArrayList<>().

コンパイラーが推測してくれるのでこの Scala コードでは型を定義する必要はありません。
また、リストの宣言もとても単純になっていることに注意してください。
Java 7 には List list = new ArrayList<>() のように書くことを可能にする
diamond operator と呼ばれるものがあります:


  
6. Named parameters
   名前つき引数
  
Another nice thing from Scala is support the named parameters. Remember our draw method?

Scala のもう一つの nice thing は named parameters のサポートです。
draw メソッドをおぼえていますか?

  shape.draw(5,2.0f) 
  shape.draw(radius=1.0f,sides=4)

Scala will allow you to pass parameters on their order, or any order you want as long 
as you specify it's names.


7. No more checked Exceptions
   checked Exceptionはもういらない

Debatable, but I hate them. I hate having to close a resource, and having to check for 
exception on my finally clause. Hate it to death. This unchecked approach is one of 
the things I like most on the design of Spring Data Access exceptions, they are all 
unchecked.

議論の余地はありますが、わたしはこれ (checked exceptions) が嫌いです。リソースをクローズしな
ければならないのも、自分の作った finally clause に関する exception をチェックしなければなら
ないのも嫌いです。
Hate it to death.
unchecked approach は Spring Data Access exptions の設計に関してわたしが最も好きな点の一つです。
they are all unchecked.

	def draw(sides:Int=3, radius:Float=1.0f) = {
	  if(sides > 99)
	    throw new UnsupportedOperationException
	}
	shape.draw(15,2.0f) //No catching here :D


8. Methods everywhere, parenthesis nowhere
   メソッドはどこにでも。カッコはどこにも。

The first good thing is: Scala is a OO language, not like Java. Java is something that 
can be OO, but you can also write static everywhere and find your self in a C 
procedural world (I've been there, worked with great guys from C, that started writing 
java code, and not a line of OO).

最初の good thing は Scala が Java とは違ったオブジェクト指向言語であるということです。
Java はオブジェクト指向にもできる何かですが、すべてをstatic に書いて C の手続き世界にい
ることも可能なのです(わたしはそこにいます。C を使ってきたけれども
OO でない Java コードを書き始めた great guys と共に働いています)。


So you can actually call:
ですから実際に呼び出しできます:
  
  1.until(10)

which will create a Range of integers from 1 to 10. This is nice, but what looks cool, 
and make your code so readable that even you mom can read is:

これは1から10までの整数のRangeを作り出します。
This is nice, but what looks cool, 
あなたのコードをあなたのお母さんでも読めるほどに簡単にします:


  1 until 10

So, when you do 1+1 you are actually doing: 1.+(1)
ですから 1+1 としたときに実際に行われるのは 1.+(1) なのです

9. Embrace Functional Programming
   関数プログラミングの embrace

This is a more advanced topic, and I'm still getting used to it, but a simple way to 
see this is: Everything returns something ;) . I mean, every language execution must 
return something or Unit (kinda void). This is such a powerful feature once you get 
used to it, your if-else statements can return a value, your loops, your try-catch. 
This will reduce your code a lot

This is a more advanced topic, and I'm still getting used to it, but a simple way to see this is:
すべてのものが何かを返します ;)
つまり、すべての言語の実行はなにか(something) もしくは Unit (void のようなもの)を
返さなければならないのです。
これは一度使えるようになれば非常に強力な機能で、
if-else 文やループ、try-catch が値を返せるようになります。
これはあなたのコードを大いに reduce することでしょう

  val max = if(x>y) x else y
   val nums = 0 until 9
    val odds = for {
      i <- nums
      if i%2!=0
    } yield i
    println(odds)

One could argue on the max example being possible using ternary operator (which I use 
a lot, and now I understand why, I had a deep need for Functional Programming). But 
the capacity of yielding values as your for loop gets evaluated is really powerful. 
Combine this with the inline if conditions, and you have a very powerful filter 
without having to rely on external Predicate classes

例にある max について、 ternary operator (三項演算子) をつかってもできると主張する人がいる
かもしれません(わたしはこの三項演算子を多用しますが、今は関数プログラミングがとても必要に
なったのでその理由を理解していています)。しかし for ループを評価したとして得られる
yielding values の capacity が really powerful なのです。これを inline if condintions と組
み合わせると、外部のPredicate クラス群に頼る必要なく非常に強力なフィルターを手に入れられます。


10. goodbye semicolons (セミコロンにさようなら)

Well, you probably noticed this already. No semicolons needed here.
さてすでにお気づきでしょうが、セミコロンは不要です。

Conclusion (結論)

Well there are so many reasons on why you should move to Scala, that was actually hard 
coming up with only 10 that were simple to explain. Next time I'll dig into traits and 
actors, and maybe get more people to join the Scala Army.

さてこのように、あなたがScalaへ移行すべき理由がたくさんあって、
簡単に説明できるものを十個だけ挙げることは困難でした。
次回は traits、actors について言及します。これでさらに多くの人を Scala Army に参加させら
れるかもしれません。

Happy Coding

■_ Scala ネタその2

こっちも ○| ̄|_

Why Scala seems difficult but really isn't | Software development and other things

Why Scala seems difficult but really isn't
(なぜ Scala は難しそうに見えるけれども実際はそうでないのか)

Posted by Markus Jais on June 15, 2011

When I learned C++ and Java a long time ago, I loved Bruce Eckel's books Thinking in 
C++ (two volumes) and Thinking in Java .

はるかな昔、わたしが C++ と Java とを学んだ頃、わたしは Thinking in C++ や
Thiking in Java といった Bruce Eckel の本が大好きでした。


They had very clear and detailed explanations and I learned a lot from them. So I 
value his opinion. Bruce also often wrote very positively about Python, a language I 
like a lot.

それらの本は非常に明快かつ詳細に説明がなされていて、わたしは多くのことをそこから学んだ
のです。ですからわたしは彼の意見を尊重します。Bruce はまた、(わたしがとても好きな言語
である) Python についてしばしば非常に肯定的なことを書いていました。

A few days ago, he published a great article about Scala:

数日前のことですが、彼は Scala についての great article を公開しました:

Scala: The Static Language that Feels Dynamic”

It is a very interesting article which shows that Scala is not complex – at least not 
more complex than Java. He writes “… Scala should be a lot easier than learning 
Java!”.

これは非常に興味深い article で、Scala は複雑ではない、少なくともJavaよりも複雑なもの
ではないということを主張するものでした。彼はこう書いています
“… Scala should be a lot easier than learning Java!”.
(Java を学ぶよりも Scala のほうがずっと簡単だよ!)
と。

I agree. When you use the subset of Scala that let's you do with Scala what you can do 
with Java, it is not more difficult at all, probably even easier than Java.

わたしはこれに賛成します。Java を使ってあなたのできることをやらせるためにScalaのサブセ
ットを使ったとき、それは Java よりも格段に難しくなっているということはなくて、おそらく
はとても簡単になっているでしょう。

Here are a few reasons why I think Scala seems more difficult:
なぜ Scala のほうがより難しいものに見えるのかについてわたしの考えた理由をいくつか挙げます:

1) Programmers think they can master Scala within a few days or weeks

   プログラマーは自分が数日から数週間もあればScalaをマスターできると考えている


Programmers are used to Java and learning something new is always an effort. Not everyone is
willing to really make the effort. To truly master Java, it takes years of practice. Some
programmers think after programming in Java for 10 years or more, they should become as
proficient in Scala as they are in Java within a few weeks. But that's not how it works, no
matty how easy an language is. You can write simple or even somewhat complex programs in
Scala after a few days really studying it, but to truly master it, it will take a lot of
time and effort. But this can be very rewarding. I am still relatively new to Scala and
don't claim to be an expert or even understand everything about the language. But when I
play with it, learn or read something about, I always have fun and learn something. But I
know to give it time to become an expert. If you just started with Scala, give it time.
When you are stuck, ask on the mailing lists or try a different website or book with
explanations. Don't give up. Even if you end up not liking Scala very much, you will
definitely become a better programmer by learning it.

Programmers are used to Java and learning something new is always an effort.
Java を日頃使っていて、新しい何かを学んでいるプログラマーはいつでも
日常 Java を使っていて何か新しいものを学ぼうというプログラマーは誰もが本当に努力しよう
としているわけではありません。本当に Java をマスターするには何年もの実践を要します。中
には Java で十年以上プログラミングしていて、自分たちは数週間あれば Scala を使いこなせ
るようになるだろうと考えるプログラマーもいます。
But that's not how it works, no matty how easy an language is.
数日勉強した後でなら、Scala で単純なプログラムは書けるでしょうし複雑なプログラムさえ書
けるかもしれません。けれども本当にマスターするには時間がと手間が掛かるでしょう。でもそ
れには非常に大きな見返りがあるかもしれません。わたしは Scala についてはまだ比較的新米
であり、この言語について自分がエキスパートであるとかあるいはよく理解しているとさえ主張
する気はありません。しかし Scala で遊んだり、Scala について何か学んだり読んだりするときには
いつでも楽しみ、その上で学んでいます。
ですがエキスパートになるには時間が掛かることをわたしは知っています。
もし Scala を学び始めたばかりなら、時間をかけてください。
stuck してしまったときにはメーリングリストで尋ねたり別の web サイトや本に当たってみましょう。
諦めてはいけません。結局は Scala をそれほど好きにならなかったとしても、
Scala を学ぶことできっとより良いプログラマーになることでしょう。


2) Programmers don't know anything or not much about functional programming
   プログラマーは関数プログラミングについて何も知らなかったりよく知っていなかったりする

Java is not a functional programming language. If a programmer has been using mostly 
Java and C++ for the last years, he may have created great software with Java in an 
object oriented way. This works great with Java and there is absolutely nothing wrong 
with that. I love Java and OOP is a great way for building software. But when people 
start playing with Scala they are also confronted with functional programming. You can 
do Scala in a pure OOP way but you will get more out of the language if you also 
master functional programming (FP). Because most programmers don't have much 
experience with it, it seems very difficult and strange at first. But like I wrote 
above, you will have to give it some time to really understand it. It will be worth it 
and you will even think differently about your Java code when you've played more with 
high order functions, closures and recursion. FP is not always better or worse than 
OOP. It is another tool that is good to have in your toolbox. Sometimes FP is a better 
fit, sometimes OOP and sometimes a combination. This is why Scala supports both.

Java は関数プログラミング言語ではありません。あるプログラマーが最近数年間においてほと
んどJava や C++ を使ってきていたならば、その人はオブジェクト指向流の Java でもって偉大
なソフトウェアを作っているかもしれません。
This works great with Java and there is absolutely nothing wrong with that.
わたしは Java が大好きですし、OOP はソフトウェアを構築するための great way です。しか
し Scala で遊び始めた人は同時に関数プログラミングに confront します。pure OOP way で 
Scala を使えますが、関数プログラミング(FP)もマスターしたならばより多くのことをこの言語
から得られるでしょう。大部分のプログラマーは関数プログラミングについてそれほど経験をつ
んでいないので非常に難しく見えるし、初めは奇妙なものに思えるでしょう。しかしわたしがす
でに述べているように、それを本当に理解するためには多少の時間が必須なのです。高階関数や
クロージャ、再帰をより使うようになったときにはそれは時間をかけても理解したことが価値あ
るものとなり、自分の Java コードが異なるものにさえ思うようになるでしょう。FP はいつで
も OOP より優れたものとは限りませんが、常に劣ったものであるわけでもありません。Scala 
はあなたの道具箱に忍ばせておくと良い another tool です。FP がより fit するときもあれば
OOP の方が fit するときもあるしときにはその組み合わせがよいこともあります。
これが、Scala が (OOPとFPの) 両方をサポートしている理由です。


3) Many Scala websites are blogs can seem intimidating to beginners
   多くの Scala のサイトは初心者をintimidateするような記事を書きがちに見える

When someone is really good at a language, he or she often want's to show it. This is 
why Ruby sometimes looks very complicated when a Ruby guru writes a blog post with 50 
lines of code and 10 different meta programming techniques within them.

ある人が本当に good at a lanugage であるとき、その人はしばしばそのことを誇示しようとし
ます。これは Ruby グルが 50 行のコードと十個の別々のメタプログラミング技法と共にブログ
のエントリを書いたときに Ruby が非常に複雑なものに見えることがある理由です


The same is true for Scala. In many blog posts and websites, you find stuff about 
Monads, advanced FP, very concise but not necessarily very readable code and other 
things you won't need in your daily business and is way to confusing for a beginner.

これは Scala でも同じです。多くの blog の投稿や web サイトであなたは、モナドや高度な FP、
very concise ではあるけれども not necessarily very readable code、
そのほかあなたの日々の仕事には必要なくて初心者を混乱させるやり方のものを見ることがあるでしょう。

This can be and is sometimes very intimidating for beginners who just want to read a 
file with Scala.

これはそうなりがちなことで、Scala でファイルを読みたいだけのようなビギナーに対して
非常に intimidating なことです。

That doesn't mean I don't like those blogs, but I think the Scala community should 
publish more simple stuff.

このことはそういった blog をわたしが好きではないという意味ではありません。
しかし Scala コミュニティはもっと単純な stuff を publish すべきであろうとは考えています。


4) Lack of a good cookbook for Scala
   Scala 向けのよい cookbook が欠けている
  
Many programmers learn by examples of how to do everyday tasks like opening files, 
sending an emails or building a socket server. For many languages there are great 
cookbooks with hundreds of recipes about how to do that. Such a book does not yet 
exist for Scala. I think it could really help to bring even more people to this 
wonderful language.

多くのプログラマーがファイルのオープンだとかメールの送信、ソケットサーバーの構築といった
日々のタスクをどのように行うかの例から学びます。そのようなことをどう行うかについてのレシ
ピをたくさん集めたプログラミング言語向けの cookbok が多数存在しています。そういった本は
Scala 向けにはまだありません。わたしはそれがもっともっと多くの人をこの素晴らしい言語に導
く助けになるだろうと確信しています。

Conclusion: Scala is not difficult – just keep on learning
結論: Scala は難しくはない。学び続けよう

This are just a few reasons why I think Scala sometimes seems more difficult than it 
really is. If you don't know Scala yet, I highly recommend reading Bruce Eckel's 
article mentioned above.

以上のことが、Scala がときに実際よりも難しいものに見えたりすることについて、
わたしが考える理由です。もしあなたがまだScalaのことを知らないのであれば、
先に紹介した Bruce Eckel のarticle を読むことを強くお勧めします。

If you already know some Scala but struggle a bit to grasp some of it's concepts, keep 
on learning. As I wrote, you cannot become a Scala expert within 3 weeks. Keep pushing 
until you are comfortable with Scala and you will very likely really love it. And if 
you don't you will nonetheless have learned a lot. (Btw, this holds true for all 
languages).

もしすでに多少 Scala を知っていてもそのコンセプトの一部に苦戦しているようなら学び続けてくだ
さい。すでに書いているように三週間で Scala のエキスパートにはなれません。Scala が快適になる
まで続けてください。そうすればきっと Scala がとても好きになるでしょう。仮に好きになれなかっ
たとしても、多くのことを学ぶことでしょう (ところでこのことはすべての言語について言えること
です)。

Copyright © 2011 Markus Jais 

■_ どのくらい違う

from ム板。

推薦図書/必読書のためのスレッド 63

130 デフォルトの名無しさん [sage] 2011/06/22(水) 22:53:02.03 ID: Be:
    C++とC++/CLIって全く別物なん?

131 デフォルトの名無しさん [sage] 2011/06/22(水) 23:15:21.23 ID: Be:
    PSPとPSPgoくらい違う 

132 デフォルトの名無しさん [sage] 2011/06/22(水) 23:17:26.57 ID: Be:
    それは・・・どうなんだ 

134 デフォルトの名無しさん [sage] 2011/06/22(水) 23:45:40.03 ID: Be:
    >>130
    別ものではないよ。
    C++/CLI = better C++ 

135 デフォルトの名無しさん [sage] 2011/06/22(水) 23:56:05.62 ID: Be:
    それならまだ>>131のほうがいいな 

131 がツボにはまったのでつい。

■_ Active Perl

そういえば古いバージョンのはダウンロードできなくなってるとか以前聞いたなあ。 それがさらに進んだということね。 まあ古いバージョンの本体が必要になることもないだろう。たぶん。

ActivePerl 5.8 & 5.10 Business Edition and Enterprise Edition | Extended Support Options

ActivePerl 5.8 & 5.10: Extended Support Options

Troy Topnik, June 21, 2011

ActivePerl

ActivePerl Community Edition 5.8 and 5.10 are no longer available for free download. 
These versions, like ActivePerl 5.6, are now available to our Business Edition, 
Enterprise Edition, and OEM customers only. We're bringing ActivePerl Community 
Edition in line with the maintenance and support policy of the perl5-porters. When the 
underlying Perl version becomes "unsupported" by the Perl community itself, 
support for and access to the corresponding ActivePerl versions will be limited to 
Business and Enterprise Edition customers.

Last year, I wrote a post about our rationale for removing older builds from Community 
Edition. I used an analogy about stale bread to illustrate the point, but someone on 
reddit summed it up much more succinctly: "The good stuff is free, the old broken 
stuff will cost you".

While there's nothing particularly broken about the latest releases of Perl 5.8 and 
5.10, if something were broken or vulnerable, the perl5-porters won't be fixing it 
"officially".

What's with the quotation marks?

Perl 5 is maintained by a group of volunteers who's primary interest is the 
development of a useful, stable, modern implementation of the language. Most of them 
are not paid for this work, and there are no contractual obligations or service level 
agreements requiring them to ensure that an application written 10 years ago will run 
with the current release. By "official" they mean "what we've committed 
to provide on a best efforts basis".

That commitment is commendable, and it has ensured the continued interest in Perl by a 
new generation of programmers, a healthy CPAN community, and a vibrant language. A lot 
of proprietary software makers could take a lesson from the perlpolicy document.

But the needs of Perl programmers are not always the same as those of Perl users. The 
groups mostly overlap, but there are a significant number in the "user" 
group who rely on Perl as a piece of infrastructure rather than a language. They are 
often businesses running legacy applications, scripts, system utilities, or small bits 
of network glue which have not been changed in years. For these people there is a need 
for support beyond what the community can provide.

Extended support

ActiveState provides official support for ActivePerl. No quotation marks.

    * If the applications you rely on require an older version of Perl, Business Edition
      can give you access to the build you need and provides technical support.

    * If you require more in-depth support backed by a service level agreement, 
      Enterprise Edition is available.

    * If the software you sell requires Perl 5.8 or 5.10, ActivePerl OEM provides you 
      with the builds you need and the license to distribute ActivePerl to your customers.

Community Edition

If you're currently running ActivePerl 5.8 or 5.10 Community Edition, you can continue 
to do so. You'll be able to access the ppm repositories for another six months, but 
the modules will no longer be updated with new releases from CPAN. The CPAN shell will 
of course continue to work if you would like to build the modules directly from source.

The Jan & Troy Show

As we did shortly after the ActivePerl 5.12 release, Jan Dubois and I will be presenting a webinar on Perl 5.14 and the state of Perl. Please join us as we talk about what's new in the language and the larger Perl world.
Trackback URL for this post:
http://www.activestate.com/trackback/3088

■_ そりゃ違うだろう

OKWaveから

正規表現について | OKWave

正規表現について

C言語版の鬼車ライブラリを利用して、ある検索プログラムを作成したいのですが、
1点質問です。

以下のような例文があるおします。
(例)
--
最初の試験、二番目の試験、三番目の試験、最後の試験

--

onig_search()を使用して上記から”試験”のすべての検出箇所を調べたいのですが、
パターンに”試験”を指定してonig_search()をコールしても最初の1件目のみしか
検出しません。

特殊なオプションが必要なのでしょうか?
それとも、パターン(正規表現)の書き方が誤っているのでしょうか?

問題が解決せず非常に困っています。
どなたか、解決策をお持ちの方は知恵を貸してください。


ANo.1

まず「どう呼んでいるか」を提示してもらわないことにはどこが誤ってるのかも指摘しようがな
いんですが……

API仕様を読んだ感じでは「start⇒rangeの間で最初にマッチした部分」を返すようなので、
「意図に合うような呼び出し方をしていない」線が濃厚じゃないかという気はするのですが。

補足

回答ありがとうございます。

>まず「どう呼んでいるか」を~
ごもっともです。
コメント用に少し簡易的に編集していますが、
概ねこんな感じです。
※

--ココカラ--
unsigned char *start, *range, *end;// 正規表現用ポインタ
regex_t* reg = NULL; // 正規表現オブジェクト
OnigErrorInfoeInfo;
char *Target = "最初の試験、二番目の試験、三番目の試験、最後の試験";
char *pattern = "試験";

onig_new(&reg, (unsigned char*)pattern, (unsigned char*)pattern + strlen((char*)pattern),
ONIG_OPTION_MULTILINE | ONIG_OPTION_IGNORECASE,
ONIG_ENCODING_UTF8, ONIG_SYNTAX_DEFAULT, &eInfo);

end = (unsigned char*) (Target + strlen((char*)Target));
start = (unsigned char*) pTarget;
range = end;
region = onig_region_new();

onig_search(reg, Target, end, start, range, region, ONIG_OPTION_NONE);
--ココまで--

で、onig_search()の結果として、構造体regionに格納されるのですが、
該当数を示すregion->num_regs は1 になっており、初回該当の情報のみ格納されています。

確認した感じでは意図通りの呼び方に見えたのですが、
期待値と異なります。。。

どうでしょうか?

#1です。

改めて仕様を読み直してみたら、戻り値が最初のヒット位置というだけで、それとは別に引数の
構造体regionにヒット数と開始・終了アドレスが入るんですね。

読み違えてました。失礼。

さて、それを踏まえて例示されたコードですが、間違いはなさそうに見えます。
こちらでも以下の環境下で試してみたのですが、

・OpenSuSE 11.4 x64
・gcc 4.5.1

配布元の最小限使用例に対してonig_newのencをUTF8に変えてpatternとstrを質問と同じ状態
にしてみただけのコードで再現しますね……。

ASCIIに直して追試したらUTF-8と同じ結果が出たので、なんとなくですがUTF-8の処理が甘いよ
うな印象があります。

「とりあえず回避」というやり方ですが、startを前回のヒット位置(onig_searchの戻り値)+
strへずらしながらヒットしなくなるまで一つずつ拾っていく手かと思います。

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

#1/3です。少々訂正。

> startを前回のヒット位置(onig_searchの戻り値)+strへずらしながら

startを前回のヒット位置(onig_searchの戻り値) + str 「+ strlen(pattern)」へずらしながら

です。でないと無限ループしてしまいますね。


お礼

回答ありがとうございます。

(略)

> 「とりあえず回避」というやり方ですが、startを前回のヒット位置(onig_searchの戻り値)+strへずらしながらヒットしなくなるまで一つずつ拾っていく手かと思います。

すいません。再現確認までして頂いて感謝します。
そうですよね。。。
私もこの方法しかないと考えていました。
入力情報(検索対象とパターン)はファイルから読み込む設定値なので、プログラムを変えずに対応できれば
と思っていたのですが。。。了解です。
当初、鬼車ライブラリの使用方法の誤りかと思っていのたですが、
そうでもなさそうですね。
深夜に対応ありがとうございました。

その region はサブパターンの結果を入れてもらうところだわさ。 Python でいうところの findall みたいなことをしたいのなら、 出た結論のとおり、自前でちまちまやらないと。

こういうのに限って締め切られるのが早いんだよなあ。 オープンされてた状態のときに気がついていれば…

ところで なんとなくですがUTF-8の処理が甘いような印象があります ってどゆこと?

■_

2011年06月22日

■_

じゅうみんぜー ○| ̄|_

■_ 1.85→1.86

どうも方針があっちいったりこっちいったりしてるなあ

diff -urp --exclude-from=.excludes gawk-3.1.85/dfa.c gawk-3.1.86/dfa.c
--- gawk-3.1.85/dfa.c	2011-06-01 04:23:18.000000000 +0900
+++ gawk-3.1.86/dfa.c	2011-06-16 02:05:29.000000000 +0900
(略)
diff -urp --exclude-from=.excludes gawk-3.1.85/re.c gawk-3.1.86/re.c
--- gawk-3.1.85/re.c	2011-06-01 12:29:19.000000000 +0900
+++ gawk-3.1.86/re.c	2011-06-16 02:02:39.000000000 +0900
@@ -382,10 +382,9 @@ resetup()
 {
 	if (do_posix)
 		syn = RE_SYNTAX_POSIX_AWK;	/* strict POSIX re's */
-	else if (do_traditional) {
+	else if (do_traditional)
 		syn = RE_SYNTAX_AWK;		/* traditional Unix awk re's */
-		syn |= RE_RANGES_IGNORE_LOCALES;
-	} else
+	else
 		syn = RE_SYNTAX_GNU_AWK;	/* POSIX re's + GNU ops */
 
 	/*
diff -urp --exclude-from=.excludes gawk-3.1.85/regcomp.c gawk-3.1.86/regcomp.c
--- gawk-3.1.85/regcomp.c	2011-06-03 16:39:11.000000000 +0900
+++ gawk-3.1.86/regcomp.c	2011-06-16 02:04:51.000000000 +0900
@@ -2651,7 +2651,6 @@ build_range_exp (reg_syntax_t syntax, bi
 # endif /* not RE_ENABLE_I18N */
 {
   unsigned int start_ch, end_ch;
-  int ignore_locales = (syntax & RE_RANGES_IGNORE_LOCALES) != 0;
 
   /* Equivalence Classes and Character Classes can't be a range start/end.  */
   if (BE (start_elem->type == EQUIV_CLASS || start_elem->type == CHAR_CLASS
@@ -2672,7 +2671,6 @@ build_range_exp (reg_syntax_t syntax, bi
     wchar_t wc;
     wint_t start_wc;
     wint_t end_wc;
-    wchar_t cmp_buf[6] = {L'\0', L'\0', L'\0', L'\0', L'\0', L'\0'};
 
     start_ch = ((start_elem->type == SB_CHAR) ? start_elem->opr.ch
 		: ((start_elem->type == COLL_SYM) ? start_elem->opr.name[0]
@@ -2698,11 +2696,7 @@ build_range_exp (reg_syntax_t syntax, bi
 #endif
     if (start_wc == WEOF || end_wc == WEOF)
       return REG_ECOLLATE;
-    cmp_buf[0] = start_wc;
-    cmp_buf[4] = end_wc;
-    if (ignore_locales && start_wc > end_wc)
-      return REG_ERANGE;
-    else if (wcscoll (cmp_buf, cmp_buf + 4) > 0)
+    else if ((syntax & RE_NO_EMPTY_RANGES) && start_wc > end_wc)
       return REG_ERANGE;
 
     /* Got valid collation sequence values, add them as a new entry.
@@ -2741,23 +2735,10 @@ build_range_exp (reg_syntax_t syntax, bi
       }
 
     /* Build the table for single byte characters.  */
-    if (ignore_locales)
-      {
-        for (wc = 0; wc < SBC_MAX; ++wc)
-          {
-    	     if (start_wc <= wc && wc <= end_wc)
-    	       bitset_set (sbcset, wc);
-          }
-      }
-    else
+    for (wc = 0; wc < SBC_MAX; ++wc)
       {
-        for (wc = 0; wc < SBC_MAX; ++wc)
-          {
-    	     cmp_buf[2] = wc;
-    	     if (wcscoll (cmp_buf, cmp_buf + 2) <= 0
-    	         && wcscoll (cmp_buf + 2, cmp_buf + 4) <= 0)
-    	       bitset_set (sbcset, wc);
-          }
+         if (start_wc <= wc && wc <= end_wc)
+           bitset_set (sbcset, wc);
       }
   }
 # else /* not RE_ENABLE_I18N */
diff -urp --exclude-from=.excludes gawk-3.1.85/regex.h gawk-3.1.86/regex.h
--- gawk-3.1.85/regex.h	2011-06-01 04:23:19.000000000 +0900
+++ gawk-3.1.86/regex.h	2011-06-16 02:02:25.000000000 +0900
@@ -184,10 +184,6 @@ typedef unsigned long int reg_syntax_t;
 /* If this bit is set, then no_sub will be set to 1 during
    re_compile_pattern.  */
 # define RE_NO_SUB (RE_CONTEXT_INVALID_DUP << 1)
-
-/* If this bit is set, then ranges act like they are in
-   the "C" locale.  */
-# define RE_RANGES_IGNORE_LOCALES (RE_NO_SUB << 1)
 #endif
 
 /* This global variable defines the particular regexp syntax to use (for
@@ -213,7 +209,6 @@ extern reg_syntax_t re_syntax_options;
 
 #define RE_SYNTAX_GNU_AWK						\
   ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS		\
-    | RE_RANGES_IGNORE_LOCALES                                          \
     | RE_INVALID_INTERVAL_ORD)						\
    & ~(RE_DOT_NOT_NULL | RE_CONTEXT_INDEP_OPS				\
       | RE_CONTEXT_INVALID_OPS ))
diff -urp --exclude-from=.excludes gawk-3.1.85/version.c gawk-3.1.86/version.c
--- gawk-3.1.85/version.c	2011-05-29 04:31:12.000000000 +0900
+++ gawk-3.1.86/version.c	2011-06-17 17:08:38.000000000 +0900
@@ -1,3 +1,3 @@
 #include "config.h"
 
-const char *version_string = "GNU Awk 3.1.85";
+const char *version_string = "GNU Awk 3.1.86";

これなら手元の 1.85改変版にほぼそのまま適用できそうなんで、 この週末にでも修正を反映したのをビルドしてみんべ。

■_

元ページの写真がいいな。

Why am I learning Perl? « Bruno P. Kinoshita

Why am I learning Perl?

June 15th, 2011

Last month I attended the II Sao Paulo Perl Workshop, where I had the privilege of 
learning with the great talks performed by bryan d foy, Brad FitzPatrick and Larry 
Wall. For being a Java programmer, you can imagine how lost I was feeling there.

The first programming language that I had contact with was Perl. I was a 16 years old 
Slackware aficionado at that time, and was dying to have a web site with a guestbook . 
We did not have any cheap hosting services in Brazil that offered a PHP environment, 
but there were few companies that offered a free host with ads, and with Perl. I don'
t remember which script I used, only that I found it in HotScripts.com and that it 
stored the guestbook entries in disk. Now, ten years after, here I am playing with 
Perl again! :-D

略

■_

■_

眠い

2011年06月21日

■_

買った。長かったがようやく最終巻
OVA BLACK LAGOON Roberta's Blood Trail Blu-ray 005

あとこいつ
[予約先着外付け特典DVD付]とある魔術の禁書目録II 第5巻 〈初回限定版〉 [Blu-ray]

原稿…

■_ Scala v.s. Java

Scala の方が速いってのは本当かということについていろいろ。 元ページのメモリ使用量などのグラフが興味深いです。

で、結論(笑)

Swarm of XeBees ≫ Is Scala really Faster than Java?
So what is the conclusion.

It seems that difference in implementations is the cause for difference in the time 
taken by Java/Scala programs.  This is reflected in the different object creation 
patterns for the implementations. As you can see in the graphs below that the Java pro 
implementation managed to get similar old generation size patterns as to Scala. I have 
not gone in the details of implementations to be able to comment on why.

Like they say for cricket statistics, "they hide more than they reveal". It 
won't be fair to conclude that Scala is faster than Java in all cases. But having a 
language like Scala which provides better abstractions on top the existing JVM is 
great. Great work by guys at Google to create a benchmark which evaluates different 
aspects of a language.

But i am still looking for an answer on why there is more object churn in Java 
implementation compared to Scala (where i would expect a lot of immutables to be 
created).

PS: Results shown are only for a single

■_ Generators:

なんかその起源やらから説明しているものらしく。 興味深いんで訳してみたりしたいんだけど、余裕がなっしんぐ(こればっか)

Generators: yield = exceptions + non-determinism

Generators have become popular because they give the benefit of lazy evaluation -- 
modular on-demand processing -- in strict languages or when lazy evaluation does not 
apply because the computation has observable effects such as IO. Our main result 
clarifies the meaning of generators and may lead to new ways of implementing them: 
computations that yield decompose into exceptions and non-determinism. To be precise 
if abstruse, a monad of generators is an exception-monad--transformed LogicT monad. 
The one-line Haskell definition of yield should clarify:

このあとの部分で CLU がどうとか書かれてます。

■_

■_ awk one-liners

電子ブックかあ。買ってみようかな(といいつつその手の端末を持っていない) Announcing my first e-book "Awk One-Liners Explained" - good coders code, great reuse

■_

ずいぶん伸びているけどなんだろう

In Windows, the directory is the application bundle : programming


一つ前へ 2011年6月(中旬)
一つ後へ 2011年7月(上旬)

ホームへ


リンクはご自由にどうぞ

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