ときどきの雑記帖 ぴゅあ

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

一つ前へ 2011年12月(上旬)
一つ後へ 2011年12月(下旬)

ホームへ

2011年12月20日

■_

で、「笑っていいとも」でなにが? (録画はしておいたけどまだ観てな)

なんかみあたらないんですけどー → Amazon.co.jp: ヤングキング増刊 ワイルド7特集号 2012年 1/19号 [雑誌]: 本 いやまあ発売日(19日)にはすっかり忘れててチェックしてなかったてのはあるんだけどさ ○| ̄|_

■_ Lua 5.2

そこかしこで新バージョンリリースの話題が出てましたが。

Lua 5.2 Final Released : programming

This is mostly the list of incompatibilities, and doesn't include some new features (luafaq.org has a good overview):

Some big ones:

    new library for bitwise operations
    goto statement
    tables can now define metamethods for __len, __pairs, __ipairs, __gc
    emergency garbage collector (when allocation fails)
    definitely read about _ENV and the way globals work now if you haven't already

おー > goto statement

上記の発言のあるスレッドではなんかいろいろやりあってますが追いかけてません(笑)

■_

constexpr

■_ 今日の丸投げ

bumprubyさんの質問一覧 - Yahoo!知恵袋

rubyの問題です。 コードを教えてください | OKWave

同じ年に生まれたnの学生がいる。こ
の中には,同じ誕生日を持つ学生と,そうでない学生がいる。前者が何
人いるか数えるアルゴリズムをいくつか考え,その計算量を考えよ。簡
単のために,誕生日は1月1日からの日数(つまり0から364の整数)
で表わすことにする。また,学生の誕生日は大きさ冊の配列bに入って
いるが,その順序はデタラメだとする。
アルゴリズム1:同じ誕生日を持つ学生の人数を変数mで表わすこと
にして,最初は、0にしておく,学生の誕生日を1人ずつとり出
し,配列bのすべての中身と比較して同じ誕生日の学生がいる
かどうかを調べ,1人でも同じ誕生日の者がいた場合はmを1
増やす。これをすべての学生について行う。
アルゴリズム2:同じ誕生日を持つ学生の人数を変数皿で表わすこと
にして,最初は0にしておく。配列bを併合整列法によって小さ
い順に並べる。並べ換えた配列を先頭から順に調べてゆき,同
じ値が連続する区間の長さkを数える。kが2以上の場合の区
間があった場合は,mをkだけ増やす。これを配列の最後まで
行う。
アルゴリズム3:日付ごとの人数を数えるために,大きさ365の配列
cを作り,中身をすべてOにしておく。学生の誕生日dを1人
ずつとり出し,その日付の人数c[d]を1増やす。これをすべて
の学生について行う。最後に,cを先頭から調べて2以上になっ
ている値の和を求める。


丸投げするなよっていうのはおいておいて。

そんな面倒なことしなくてもcountメソッドでできる。
http://ref.xaio.jp/ruby/classes/array/count

コードを書いてくれ。つーても「計算量を求めよ」ってのはどうするんだろう? まあそれはさておき。なんか R でごにょごにょできるんじゃねえ? と思ったものの


R version 2.12.0 (2010-10-15)
Copyright (C) 2010 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i386-pc-mingw32/i386 (32-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]

> set.seed(0,NULL)
> x<-floor(runif(100,0,364))
> x
  [1] 326  96 135 208 330  73 327 343 240 228  22  74  64 250 139 280 181 261 361 138 282 340  77 237
 [25]  45  97 140   4 139 316 123 175 218 179  67 301 243 289  39 263 149 298 235 284 201 192 287   8
 [49] 173 266 252 173 313 159  89  25  36 115 188 240 148 332 106 167 120 236  93 174 278  30 318 123
 [73] 305 126 121 173 324 314 141 282 349 158 259 145 118 275  73 258  44  89  52  87  21 233 318 283
 [97] 290 165 149 295
> x<-floor(runif(100,0,364))
> x
  [1] 220 238 128  98 361 230  77  47 174 336 217 355 266 129 157  53   4 260  37 162 232 361 180 176
 [25]  63 274 165 186  75  83 216 209  28  12 233 338 217 204 191 358 184 248 218  86  93 265 164  63
 [49] 271  38 314 223 202 119 164 182  65 192  27 101  77 103 325 162 283 320 150  23 122 263 122 229
 [73] 305 311 142 138 325 234 269 220 328 106  69 322 183 319  68 275 263 343 199 259 141  36 337 103
 [97] 214  40 305 115
> length(x[x==77])
[1] 2
> for (i in 1:365){if (length(x[x==i])>1){print(i)}}
[1] 63
[1] 77
[1] 103
[1] 122
[1] 162
[1] 164
[1] 217
[1] 220
[1] 263
[1] 305
[1] 325
[1] 361
> for (i in 1:365){if (length(x[x==i])>1){print(length(x[x==i]))}}
[1] 2
[1] 2
[1] 2
[1] 2
[1] 2
[1] 2
[1] 2
[1] 2
[1] 2
[1] 2
[1] 2
[1] 2
> 

for 文を使わずに、同じ値が存在する値を抜き出せないものか。

> z <- numeric(365)
> z
  [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [50] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [99] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[148] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[197] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[246] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[295] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[344] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> z[x] <- 1
> z
  [1] 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0 1 1 1 0 1 0 0 0 0 0 0 1 0 0
 [50] 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1
 [99] 0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0
[148] 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1 0 1 1 1 0 1 0 0 0 0 1 1 0 0 0 0
[197] 0 0 1 0 0 1 0 1 0 0 0 0 1 0 0 0 0 1 0 1 1 1 0 1 0 0 1 0 0 0 0 0 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0
[246] 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 1 1 0 0 1 0 1 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
[295] 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 1 1 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 1
[344] 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0
> 

んーむわからん。1 を代入するんじゃなくて、そこに対応する値が何個あるのかを代入したいんだけど無理? 代入の右辺を工夫すればできるのかなあ。

■_ CoffeeScript

Hacker News で結構伸びてたネタ。 元記事は誰か訳すんじゃなかろうか :) CoffeeScript is not a language worth learning | Hacker News

2011/12/jargon.md at master from raganwald/homoiconic - GitHub

CoffeeScript is not a language worth learning
CofferScript は学ぶに値するような言語ではない

    A language that doesn't change the way you think about programming is not worth learning.
    (プログラミングに関するあなたの考え方を変えない言語は学ぶ価値がない)

                                                                         —Alan Perlis


CoffeeScript is a program that takes some text you write using a special set of rules 
and transforms it into some other text, which happens to be a JavaScript program. It 
is often described as a programming language that "compiles" to JavaScript 
much as other programming languages compile to assembler or JVM byte codes. Like many 
new ideas, CoffeeScript has inspired some enthusiasm from early adopters, some 
diffidence from pragmatists, and disdain from conservative laggards.

(略)


CoffeeScript isn't a language worth learning because it isn't a language. It doesn't 
make you think about programming in a new way. It's a tool for writing programs in a 
language you already know, JavaScript. And considered in that light, it's a damn fine 
tool.

CofferScript は学ぶに値するような言語ではない。なぜなら言語ではないから。
CofferScript はあなたを新しいプログラミング手法の思考に導くものではない。
CofferScript はあなたがすでに知っている言語 JavaScropt でプログラムを書くための
ツールである。
And considered in that light, it's a damn fine tool.

(discuss)

p.s. My friend Nikolai had this to say about CoffeeScript providing a standard way to 
solve common JavaScript problems such implementing OOP: "Those who do not learn 
from history, are doomed to repeat it."


© 2011 GitHub Inc. All rights reserved.

■_

2011年12月19日

■_

Modula-2 を話のタネにいろいろ書きたいことがあるんですが面倒くさいw

■_ 遅いループ

Stackoverflow 発、reddit やら Hacker news やら。 Why is one loop so much slower than two loops? : programming

c++ - Why is one loop so much slower than two loops? - Stack Overflow

なぜループのひとつはほかの二つに比べてとても遅いのか?

Suppose a1,b1,c1,d1 point to heap memory and my numerical code has the following core loop:

ヒープ領域を指す a1, b1, c1, d1 があって、わたしの書いた numerical code に
以下のようなループがあったとします

  const int n=100000

  for(int j=0;j<n;j++){
      a1[j] += b1[j];
      c1[j] += d1[j];
  }

This loop is executed 10.000 times via another outer for loop. To speed it up I changed the code to:
このループはその外側にある別のループの中にあって一万回実行されます。
これを高速化するために次のように変更しました

  for(int j=0;j<n;j++){
      a1[j] += b1[j];
  }
  for(int j=0;j<n;j++){
      c1[j] += d1[j];
  }

Compiled on MSVC10 with full optimization and SSE2 enabled for 32bit on a Intel Core 2 
Duo (x64) the first example takes 5.5 seconds and the double-loop example takes only 
1.9 seconds. My question is: (Please refer to the my rephrased question at the bottom)

PS: I am not sure, if this helps:

Disassembly for the first loop basically looks like this (this block is repeated about 
5 times in the full programm):

movsd       xmm0,mmword ptr [edx+18h]  
addsd       xmm0,mmword ptr [ecx+20h]  
movsd       mmword ptr [ecx+20h],xmm0  
movsd       xmm0,mmword ptr [esi+10h]  
addsd       xmm0,mmword ptr [eax+30h]  
movsd       mmword ptr [eax+30h],xmm0  
movsd       xmm0,mmword ptr [edx+20h]  
addsd       xmm0,mmword ptr [ecx+28h]  
movsd       mmword ptr [ecx+28h],xmm0  
movsd       xmm0,mmword ptr [esi+18h]  
addsd       xmm0,mmword ptr [eax+38h]  

Each loop of the double loop example produces this code (the following block is repeated about 3 times):

addsd       xmm0,mmword ptr [eax+28h]  
movsd       mmword ptr [eax+28h],xmm0  
movsd       xmm0,mmword ptr [ecx+20h]  
addsd       xmm0,mmword ptr [eax+30h]  
movsd       mmword ptr [eax+30h],xmm0  
movsd       xmm0,mmword ptr [ecx+28h]  
addsd       xmm0,mmword ptr [eax+38h]  
movsd       mmword ptr [eax+38h],xmm0  
movsd       xmm0,mmword ptr [ecx+30h]  
addsd       xmm0,mmword ptr [eax+40h]  
movsd       mmword ptr [eax+40h],xmm0 

EDIT: The question turned out to be of no relevance, as the behavior severely depends 
on the sizes of the arrays (n) and the CPU cache. So if there is further interest, I 
rephrase the question:

Could you provide some solid insight into the details that lead to the different cache 
behaviors as illustrated by the 5 regions on the following graph?

It might also be interesting to point out the differences between CPU/cache 
architectures, by providing a similar graph for these CPUs.

PPS: Here is the full code. http://pastebin.com/ivzkuTzG It uses TBB Tick_Count for 
higher resolution timing, which can be disabled by not defining the TBB_TIMING Macro.

(It shows FLOP/s for different values of n) enter image description here
c++ c performance compiler-optimization vectorization

熱い議論はどうぞ Stackoverflow/Hacker news/reddit へ!

■_ Emacs

メジャーバージョンが上がると

What's New In Emacs 24 (part 1) | Mastering Emacs

What's New In Emacs 24 (part 1)
by mickey on December 6th, 2011
Home > All Articles > What's New In Emacs 24 (part 1)

With Emacs 24 looming around the corner I figured it was time I took a close look at 
all the new features and changes. As it's not officially out yet I will settle for the 
pretest build (get it here.) With that said, there's little difference (in my 
experience anyway) between the pretest versions of Emacs and the real mccoy. They're 
usually rock-solid and won't crash on you, but the featureset is, of course, still 
subject to change.

I've annotated most changes and given my view of how useful each change is to most 
people. Obviously I do not speak for all of us, so don't neglect to read the NEWS file 
in its entirety yourself (C-h n.)

(略)


Right-to-Left support in Emacs has been a long time coming and a difficult and complex 
change to Emacs's display engine. If you're a RTL user I'd love to hear how functional 
and useful it actually is.

(略)

Copyright © 2011 Mickey Petersen. Titan Theme by The Theme Foundry.

bi-directional な言語のテキストも扱えるようになりました。と。

What's New in Emacs 24 (part 2) | Mastering Emacs

(略)

Lisp changes in Emacs 24.1

    Code can now use lexical scoping by default instead of dynamic scoping.
    The `lexical-binding' variable lets code use lexical scoping for local
    variables. It is typically set via file-local variables, in which case it
    applies to all the code in that file. 

    `eval' takes a new optional argument `lexical' to choose the new lexical
    binding instead of the old dynamic binding mode. 

    Lexically scoped interpreted functions are represented with a new form
    of function value which looks like (closure ENV ARGS &rest BODY). 

    New macro `letrec' to define recursive local functions. 

    New function `special-variable-p' to check whether a variable is
    declared as dynamically bound. 

The first of many changes to Emacs's elisp engine to make it more performant, feature 
rich and in line with what people expect of a modern Lisp. A large amount of the 
existing Emacs packages have already been switched to lexical scoping, but it is 
apparently difficult to get right as Emacs's codebase is heavily reliant on dynamic 
scoping to monkeypatch or extend other parts of the code.

    An Emacs Lisp testing tool is now included.
    Emacs Lisp developers can use this tool to write automated tests for
    their code. See the ERT info manual for details. 

(略)

The End

Copyright © 2011 Mickey Petersen. Titan Theme by The Theme Foundry.

お、use lexical scoping by default が。 letrec とかいうのも見えますね

■_

ぼつ。

■_

2011年12月18日

■_

2012 ハヤカワ新書juice ってどうなってんでしょうか? 2011年にこのレーベルで新刊でてないですよね?

・見逃し
こんなのがあったとは! 再放送は…ないか。オンデマンドなあ。 NHKオンデマンド | 100年インタビュー 「作家・塩野七生」 NHK 100年インタビュー | トップページ

この本買おうかなあと思ってたんですが、ふと紹介文を見ると

Amazon.co.jp: パブリック―開かれたネットの価値を最大化せよ: ジェフ・ジャービス, 小林 弘人, 関 美和: 本

内容紹介
自分をどこまでネットに晒せますか?

なぜあなたはもっとオープンになるべきなのか? なぜ企業はパブリックにならなければ生き残
れないのか? フェイスブックからオープン・ガバメントまで、いま、ネットを介して生まれつ
つある新しい“パブリック”──それはソーシャルメディア革命と3.11を経て見えてきた、大公
開時代の新しいフロンティアだ!

■『フリー』『シェア』に続いてデジタル社会のパラダイムチェンジに迫る翻訳書。著者ジェフ・
ジャービスのブログ『バズ・マシーン』日本語版も同時開設。 

「パラダイムチェンジ」で一気に買う気失せたw いやまあこの文章を書いた人は著者でも訳者でもないんでしょうけど。

■_

やりなおすのでぼつ。

■_

日本語版…は無理か(翻訳書は除外)

A Big List of Interesting Programming Books Released in 2011

A Big List of Interesting Programming Books Released in 2011

The following is a list of 48 interesting programming books that were released in 2011. 
While technically some of them are only programming-related and not about coding per 
se, each one is sure to be of interest to some programmers.

As some of you know, I run a service called Any New Books?, which emails you a list of 
new books that are related to the categories of your choice each week. For the most 
part I pulled this list from the weekly staff picks there throughout this past year, 
just in time for your Christmas shopping. ;-)

The books are ordered by their current sale rank on Amazon (from the most popular to 
the least popular at the moment, with hardcovers first). I hope this page will help 
you discover a few titles you may have not have noticed yet.
The Information: A History, a Theory, a Flood
By James Gleick
ISBN: 0375423729

The Art of Computer Programming, Volumes 1-4A Boxed Set
By Donald E. Knuth
ISBN: 0321751043

Algorithms (4th Edition)
By Robert Sedgewick, Kevin Wayne
ISBN: 032157351X

The Art of Computer Programming, Volume 4A: Combinatorial Algorithms, Part 1
By Donald E. Knuth
ISBN: 0201038048

GPU Computing Gems Emerald Edition
By Editors at Morgan Kaufmann
ISBN: 0123849888

Visualize This: The FlowingData Guide to Design, Visualization, and Statistics
By Nathan Yau
ISBN: 0470944889

Programming Android
By Zigurd Mednieks, Laird Dornin, G. Blake Meike, Masumi Nakamura
ISBN: 1449389694

JavaScript: The Definitive Guide: Activate Your Web Pages
By David Flanagan
ISBN: 0596805527

iOS Programming: The Big Nerd Ranch Guide (2nd Edition)
By Joe Conway, Aaron Hillegass
ISBN: 0321773772

Programming in Objective-C, Third Edition
By Stephen G. Kochan
ISBN: 0321711394

Cocoa Programming for Mac OS X (4th Edition)
By Aaron Hillegass, Adam Preble
ISBN: 0321774086

Introducing HTML5 (2nd Edition)
By Bruce Lawson, Remy Sharp
ISBN: 0321784421

Programming Python
By Mark Lutz
ISBN: 0596158106

Beginning Android Application Development
By Wei-Meng Lee
ISBN: 1118017110

Agile Web Development with Rails
By Sam Ruby, Dave Thomas, David Heinemeier Hansson
ISBN: 1934356549

Eloquent Ruby
By Russ Olsen
ISBN: 0321584104

Matlab, Second Edition: A Practical Introduction to Programming and Problem Solving
By Stormy Attaway
ISBN: 0123850819

Java Performance
By Charlie Hunt, Binu John
ISBN: 0137142528

Gamification by Design: Implementing Game Mechanics in Web and Mobile Apps
By Gabe Zichermann, Christopher Cunningham
ISBN: 1449397670

Learn You a Haskell for Great Good!: A Beginner's Guide
By Miran Lipovaca
ISBN: 1593272839

Supercharged JavaScript Graphics: with HTML5 canvas, jQuery, and More
By Raffaele Cecco
ISBN: 1449393632

Arduino Robotics
By John-David Warren, Josh Adams, Harald Molle
ISBN: 1430231831

HBase: The Definitive Guide
By Lars George
ISBN: 1449396100

The Tangled Web: A Guide to Securing Modern Web Applications
By Michal Zalewski
ISBN: 1593273886

MongoDB in Action
By Kyle Banker
ISBN: 1935182870

Programming Pig
By Alan Gates
ISBN: 1449302645

The Python Standard Library by Example
By Doug Hellmann
ISBN: 0321767349

The Joy of Clojure: Thinking the Clojure Way
By Michael Fogus, Chris Houser
ISBN: 1935182641

Xcode 4
By Richard Wentk
ISBN: 111800759X

Programming Amazon EC2
By Jurg van Vliet, Flavia Paganelli
ISBN: 1449393683

Advanced Mac OS X Programming: The Big Nerd Ranch Guide
By Mark Dalrymple
ISBN: 0321706250

CUDA Application Design and Development
By Rob Farber
ISBN: 0123884268

Sinatra: Up and Running
By Alan Harris, Konstantin Haase
ISBN: 1449304230

Management 3.0: Leading Agile Developers, Developing Agile Leaders
By Jurgen Appelo
ISBN: 0321712471

Professional NoSQL
By Shashank Tiwari
ISBN: 047094224X

Scalability Rules: 50 Principles for Scaling Web Sites
By Martin L. Abbott, Michael T. Fisher
ISBN: 0321753887

Programming Concurrency on the JVM: Mastering Synchronization, STM, and Actors
By Venkat Subramaniam
ISBN: 193435676X

Learning HTML5 Game Programming: A Hands-on Guide to Building Online Games Using Canvas, SVG, and WebGL
By James L. Williams
ISBN: 0321767365

Semantic Web for the Working Ontologist, Second Edition: Effective Modeling in RDFS and OWL
By Dean Allemang, James Hendler
ISBN: 0123859654

Brave NUI World: Designing Natural User Interfaces for Touch and Gesture
By Daniel Wigdor, Dennis Wixon
ISBN: 0123822319

Haskell: The Craft of Functional Programming (3rd Edition)
By Simon Thompson
ISBN: 0201882957

Think Stats
By Allen B. Downey
ISBN: 1449307116

Rails 3 in Action
By Ryan Bigg, Yehuda Katz
ISBN: 1935182277

Test Driven Development for Embedded C
By James W. Grenning
ISBN: 193435662X


MacRuby: The Definitive Guide: Ruby and Cocoa on OS X
By Matt Aimonetti
ISBN: 1449380379

Modern Information Retrieval: The Concepts and Technology behind Search (2nd Edition)
By Ricardo Baeza-Yates, Berthier Ribeiro-Neto
ISBN: 0321416910

Designing Search: UX Strategies for eCommerce Success
By Greg Nudelman
ISBN: 0470942231

Windows Phone 7 Recipes: A Problem-Solution Approach
By Fabio Claudio Ferracchiati, Emanuele Garofalo
ISBN: 1430233710


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

さすがにアサマシ貼りまくる気にはならなかったw さて、このうちどのくらいが翻訳されるでしょうか?

■_ break

今日も break で。

Java言語について。 - Yahoo!知恵袋

Java言語について。

閲覧ありがとうございます。
さっそく質問ですが、ある企業に内定を頂き4月から入社予定なのですが
Java言語での課題が届きました。
サンプルソースを直して不具合を直すと言うものです。
学校では、「while break は基本的には使うべきではない」との事を習ったのですが、
会社のサンプルソースの記述には書かれていました。
これは直すべきなのでしょうか?

回答よろしくお願い致します。 

無限ループを break で抜けるような書き方するなということでしょうか? フラグ変数使ってそれで判定しろつーことではないですよねえ (そういう流儀があるのは聞いたことがある)。

■_ er とか ist とか

-ist - Wiktionary やっぱ「アルゴリズマー」とか変じゃね?

-er - Wiktionary

Suffix

-er

    (added to verbs) person or thing that (does the action indicated by verb);
    used to form an agent noun.

        reader, cooker, computer, runner-up, do-gooder

    (added to a noun denoting an occupation)
    person whose occupation is (the noun).

        astrologer, cricketer, trumpeter

    (added to a number, measurement or noun denoting a quantified set)
    person or thing ranked by (the number) or having (the measurement or quantified set).

        sixer, six-footer, three-wheeler, first grader

    (slang, chiefly entertainment, with few limitations)
    used to form nouns shorter than more formal synonyms.

        percenter (commission agent);
        one-hander (one-man show);
        oater (a Western-themed movie)

    (informal, added to a noun) One who enjoys.

        Tooners lined up for tickets to Toy Story.

いや、最後の infromal な用法に当てはまる?

■_ じかんねー

J言語 

177 デフォルトの名無しさん [sage] 2011/12/18(日) 17:02:31.12 ID: Be:
    来年7月にJのカンファレンスをやるらしい。
    http://www.jsoftware.com/jwiki/Community/Conference2012

    この手カンファレンスで参加費1000カナダドルて、安いのか高いのかよく分からんw 

178 デフォルトの名無しさん [sage] 2011/12/18(日) 17:29:02.09 ID: Be:
    >>177
    http://www.murc.jp/fx/index.php

    76,960円 
Monads are programming languages | tailcalled

Monads are programming languages

Posted on 16/12/2011

Everyone else is writing about their interpretation of monads, so I'll write one too. 
This post assumes that the readers are somewhat familiar with haskell, or that they 
are fast learners.

Enter the void * - What's in an ADT ?

What's in an ADT ?

by Etienne Millon on December 14, 2011

Introduction

Algebraic Data Types, or ADTs for short, are a core feature of functional languages 
such as OCaml or Haskell. They are a handy model of closed disjoint unions and 
unfortunately, outside of the functional realm, they are only seldom used.

In this article, I will explain what ADTs are, how they are used in OCaml and what 
trimmed-down versions of them exist in other languages. I will use OCaml, but the big 
picture is about the same in Haskell.

■_

2011年12月17日

■_

Facebook のアカウント作ってみた。

C81 の サークルチェックなど。 三日目だけでいいっぽい?

■_ ブレイク

ブレイク祭り

いやまあブレイクつながりで。

リストを項目ごとに集計するときのデータオブジェクトの使い方 - 虎塚

irofさんのブログを見て、自分ならどう書くかなーと思ったので、読み進める前に書いてみました。

その結果、本題のアルゴリズムとは全然関係ないところで疑問を持ったので、グデグデとメモします。

元エントリ

irofさんによる元エントリはこちら。

    リストを項目ごとに集計する http://d.hatena.ne.jp/irof/20111203/p1

{code, 名前, 数値} というデータ構造のリストについて、code(idみたいなものです)をキー
に数値を集計したい。このとき、Javaでどう書くか?というお話です。

書いてみた

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

(略)

余談

Javaで書く限り、そんなにバリエーションはないだろうと高を括っていたのですが、コメント欄
に貼られたxuwei-kさんの回答( https://gist.github.com/1429171 )を見て愕然としました。
Scalaを習得すればあんな世界観を獲得できるのか! 凄い!

また、ひしだまさんの記事も、勉強になりました。

    キー毎に値を集計する方法 http://blog.goo.ne.jp/hishidama/e/0c0b4097643ad7d4f737cca79731587c

awk でやっていーすか?w

というオヤクソクはおいといてですね。

キー毎に値を集計する方法 - ひしだまの変更履歴

irofさんとdaiksyさんがTwitter上でキーブレイク処理について話していました。

(リストを項目ごとに集計する→「ブレイク処理」を定形のアルゴリズムとして習いました→こ
んな解りにくいの、なんで好んで書くんだろう)

キーブレイク処理というのは、データをキーでソートしておいて順番に読み込み、キーが同じ値
の間に処理(よくあるのが集計)を続ける。キーが違う値になったら(キーがブレイクしたら)
集計値を出力し、集計用変数をクリアしてまた処理を続ける。というアルゴリズムです。

(略)

という訳で、キーブレイク処理をJavaで書こうと思ったら、Hadoopのソースを参考として見てみ
るといいかもしれませんね。

というか、キー毎に集計するなら、Hadoopを使うといいんじゃないですかね(笑)

Hadoop と。

リストを項目ごとに集計する - 日々常々

データをコードごとに集計することってのは結構よくあります。

例えばこんなデータを…

code	name	value
A01	hoge	100
A01	piyo	200
A02	hoge	300
A03	hoge	400
A03	piyo	500

codeごとに集計してこうしたい。

code	value
A01	300
A02	300
A03	900

現場でよく見るのはこんな感じになってます。

// データはこれのリストに入ってるてことで。
class Data {
	String code;
	String name;
	int value;
}

public List<Data> summary(List<Data> list) {
	List<Data> result = new ArrayList<>();
	Data data = null;
	for (Data d : list) {
(略)

一般的にどういうのかは知らないですが、私の現場では「ブレイク処理」とか言われてます。コ
ードが変わるタイミングでブレイクするとかそんな意味らしいです。

前のDataを保持しながらcodeが変わっているかを比較し、変わっていたら結果リストに前のData
を追加して新しいDataを作り、codeが変わっていなかったら前のDataに、valueを加算する。ル
ープが終わったら結果に最後まで残ってたDataを追加する。言葉で書くとわけわかんない…。

データは元々RDBに入ってたりするので、「集計はSQLでやれば良いのにー」と思わなくはないの
ですが、なんかあんまりやらないですね。取得したデータをさらに加工しながら集計するとかも
あるので、この辺は一概には言えないところかも。まぁそれはとりあえず置いておきます。

この処理はだいたい定形的に書かれるのですけど、正直意味が分かりにくいし、よくバグってる
のを見ます。こんな面倒なことやってたらバグっても仕方ないと思うのです。でも、こういうの
の典型的なのってどう書くものなんだろう。

私はこんなふうに書いたりします。

public static List<Data> summary(List<Data> list) {
	Map<String, Data> map = new LinkedHashMap<>();
	for (Data d : list) {
		if (!map.containsKey(d.code)) {
			Data data = new Data();
			data.code = d.code;
			map.put(d.code, data);
		}
		map.get(d.code).value += d.value;
	}
	return new ArrayList<Data>(map.values());
}

入力値がコードでソートされていない場合の挙動が違いますが、そこは同じコードを集計するの
が目的だとかなんとか言ってごまかす感じで。なんかこう、スマートな書き方あったら、教えて
下さると、とても嬉しい…。


ふーむ。使うところでは使うようですね >ブレイク処理 前に書いたようにどうも日本生まれの用語っぽいのですが (control break という言葉が同様の処理を指す用語としてはあるようです)。

んで、噂の Scala 版 http://d.hatena.ne.jp/irof/20111203/p1 — Gist

Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_29).
Type in expressions to have them evaluated.
Type :help for more information.

scala> case class Data(code:String,name:String,value:Int)
defined class Data

scala> val dataList = List(
     | Data("A01","hoge",100),
     | Data("A01","piyo",200),
     | Data("A02","hoge",300),
     | Data("A03","hoge",400),
     | Data("A03","piyo",500)
     | )
dataList: List[Data] = List(Data(A01,hoge,100), Data(A01,piyo,200), Data(A02,hoge,300), Data(A03,hoge,400), Data(A03,piyo,500))

scala> dataList.groupBy(_.code).map{case (_,v) => v.head.copy(value = v.map{_.value}.sum) }
res0: scala.collection.immutable.Map[String,Int] = Map(A03 -> 900, A01 -> 300, A02 -> 300)

おー、なんか Ruby っぽい。

ところで Boost 付きC++ 版希望 :)

■_ State of lambda

まあすぐに訳されるでしょうが、訳されはしないだろう部分がちょっと面白かったり。

InfoQ: State of the Lambda

State of the Lambda

Posted by Alex Blewitt on Dec 16, 2011

Brian Goetz has published an updated state of the lambda, giving a status report on 
the plan for adding lambdas to the Java language (also being tracked as JSR 335 and 
Java Enhancement Proposal number 126.

(略)

The addition of lambdas to the Java language, along with method references, will 
significantly reduce the amount of boilerplate needed for common operations. For 
example, in order to sort an Array of Strings with case-insensitive comparison, you 
will be able to do:

    Arrays.sort(names, String::compareToIgnoreCase)

Together with default methods, which enable interfaces to grow (like Scala's traits) 
without affecting existing code, writing Java code will be much more concise. A fully 
functional-object hybrid it isn't, but the foundations will see the rise of a number 
of functional-style libraries available for JDK8 and beyond. And whilst code compiled 
with lambdas and default methods won't be runnable on anything older than JDK8, it 
will permit the use of code compiled against older versions of the JDK to run, and be 
used in a functional way, in much the same way that generic types were slowly brought 
into the Java language.
    Why not go directly to Scala
    by Serge Bureau

    The numerous patch attempts to Java are incredibly slow coming and are all afterthoughts.
    Javaに対する数々のつぎあてはコンパイルを信じがたいほど遅いものにするし、すべては後付のものです。

    They should move to something having all of this the right way. Then we could really move on.
    彼らは正しいやり方でこれらすべてを持った何かに移るべきです。
    そうすればわたしたちは実際に移行できるかもしれません。

    I loved Java, not anymore: it has to be replaced
    わたしはJavaが好きでしたが、置き換えられるべきものです。

    Re: Why not go directly to Scala
    by arnaud m

    Because Scala breaks binary compatibility at each release,
    Because Scala has performance issues,
    Because tooling is not as good as java (yet?),
    Because Java code is easier to understand by non-expert developers,
    ...

    Closures in Java should have been implemented as syntaxic sugar around inner classes several years ago,
    it would have avoided so many discussions (Joshua Bloch).

    Java におけるクロージャは数年前に多くの議論を無視する形で
    内部クラスに対する syntaxic sugar として実装されました。

    I agree that Java evolves too slowly (but it seems that things are moving again now),
    and if it's the price to pay to keep the language robust, stable and simple, it's ok for me.
    わたしは Javaの進化が遅すぎるということには賛成します
    (が、現在は再び事態は動いているようです)。
    そして、言語を頑健かつ安定して単純なものに保つために対価が必要であるのなら
    わたしはそれでも良いと思います。

    Re: Why not go directly to Scala
    by Serge Bureau

        Because Scala breaks binary compatibility at each release,
        Because Scala has performance issues,
        Because tooling is not as good as java (yet?),
        Because Java code is easier to understand by non-expert developers,
        ...


    Binary compatibility is also an overblown issue, but it needs to be addressed.Hundreds
    of language have this on a much larger scale. Small price for the flexibility and
    evolution.

    Performance issues ?? In general because it is more expressive you get more performance
    and much better algorithm and abstraction. It is like saying that a type of collection
    is slow, choose another one ! They have parallels ones, where are the Java ones ー Be
    serious.

    Tooling is old news, the latest Eclipse plugin is really good, plus testing tools are
    much better than Java ones and order of magnitude more expressive. Plus since the 
    code is 3 to 5 times smaller than Java, it is much easier to maintain.

    As far as understanding, once again, having 3 times less lines means easier to understand.
    Some abstractions are more mathematical, but at least they are available. Where are those facilities in Java ?
    And understanding comes with the use. Java generics is the most incredible mess, talk about being easy ???

    Forget JDK8(1.8) and give me the true JDK2.0
    by light iron

    Forget all old f**kin Java code base.
    Let's change! All!
    So many things we can learn from.
    .Net CLI(not Mono), Erlang VM, Haskell, Go and more.

    Google, you are the only one who can create this new world(VM not just Language).

    IL

■_

こんどいなばさんに道を尋ねてみるとしよう

Perlについての質問箱 49箱目 

506 デフォルトの名無しさん [sage] 2011/12/17(土) 08:19:09.35 ID: Be:
    ActivePerlをWindowsにインストして
    コマンドプロンプトからPerlのプログラムを実行したいのですが
    systemに日本語のファイル名を渡すと正常に処理できません。
    どうすればsystemで日本語のファイルを処理できますか?

    system "dir 日本語.txt";

    を実行すると

    「ファイルが見つかりません」となりますが
    コマンドプロンプトで

    dir 日本語.txt

    と打つとファイルの情報が表示されます。 

507 デフォルトの名無しさん [sage] 2011/12/17(土) 08:38:01.84 ID: Be:
    >>506
    >>7 

508 デフォルトの名無しさん [sage] 2011/12/17(土) 10:07:43.74 ID: Be:
    >>506
    いまから >>7 をするよりは...

    ----------
    use Sjis; # ←これ追加するだけ!!
    system "dir 一覧表.txt";
    ----------

    参考
    ttp://text.world.coocan.jp/TSNET/?Sjis.pm

509 デフォルトの名無しさん [sage] 2011/12/17(土) 10:45:25.45 ID: Be:
    >>7 の 2行目から 5行目って
    use open qw(:encoding(cp932) :std);
    一個で済むんじゃないの?

512 デフォルトの名無しさん [sage] 2011/12/17(土) 12:26:51.28 ID: Be:
    # [Perl 日本語処理]
    # さまざまな機能をわかった上でどうしても,という方を留め立てする
    # つもりはありませんが,>>7 でできることのほとんどはもう

     use Sjis;
     require 'jacode.pl';

    # に含まれてるかもです。
    # いまさら >>7 を使わずに,いなばの道を行くしかありません。

513 デフォルトの名無しさん [sage] 2011/12/17(土) 12:37:30.55 ID: Be:
    >>506
    > system "dir 日本語.txt";
    普通に通るぞ。
    v5.12.3 build 1204 

514 デフォルトの名無しさん [sage] 2011/12/17(土) 12:38:40.13 ID: Be:
    Perl 関係のスレで Sjis.pm とか jacode.pl を勧めてくる人って一人でやってんのかな。作者本人かしら。
    そういうのが必要なシーンもあるのか知らんが、9割9分の人間は Encode 使ったほうがいいと思うなあ。 

515 デフォルトの名無しさん [sage] 2011/12/17(土) 13:04:35.50 ID: Be:
    >>513
    たぶん 506 の人はプログラムを UTF-8 で書いてるのでは。

    >>514
    古いスクリプトの資産があって、なるべく変更したくないっていうんならともかく、
    新しく書くんなら utf8 + Encode の一択でしょうね。


516 デフォルトの名無しさん [sage] 2011/12/17(土) 13:38:59.32 ID: Be:
    なるほど、use utf8;前提なら必要なのは>>7の
    > # ※2. OS に渡す文字列(ファイル名,dos コマンドのオプションなど)は、
    > # この例のように cp932 でエンコードする必要があります。 

517 506 [sage] 2011/12/17(土) 14:34:01.02 ID: Be:
    >>507
    >>508
    >>509
    >>510
    >>511
    >>512
    >>513
    >>514
    >>515
    >>516
    ありがとうございます。
    木曜日にActivePerlを始めたばかりの初心者です。
    use utf8;
    encode( 'CP932', "日本語.txt" );
    でうまくいきました。 

518 デフォルトの名無しさん [sage] 2011/12/17(土) 16:09:22.04 ID: Be:
    >>512
    「いなばの道」って何でっか?w 

519 デフォルトの名無しさん [sage] 2011/12/17(土) 16:18:07.28 ID: Be:
    100人乗っても大丈夫な道 

520 デフォルトの名無しさん [sage] 2011/12/17(土) 16:18:15.88 ID: Be:
    こういうことだろう。
    ttp://blog-imgs-18.fc2.com/l/u/c/luckystar01/20090228214717.jpg

    故事を辿れば、ワニを騙して道にし、そしてたちまちワニの怒りを買って全身の皮を剥がされる。

521 デフォルトの名無しさん [sage] 2011/12/17(土) 16:54:02.04 ID: Be:
    ワニの集団に襲われたのに、よく皮剥がされただけで済んだよな
    いなば君強しw 

522 デフォルトの名無しさん [sage] 2011/12/17(土) 17:28:01.40 ID: Be:
    >>518
    おそらく、
    ttp://gihyo.jp/dev/serial/01/modern-perl/0031
    のパロディだとおもわれ 

528 デフォルトの名無しさん [sage] 2011/12/17(土) 21:36:31.64 ID: Be:
    それはいばらの道だ... 

529 デフォルトの名無しさん [sage] 2011/12/17(土) 21:40:58.02 ID: Be:
    >>522
    「いばら」が読めなかったんだろw 

530 デフォルトの名無しさん [sage] 2011/12/17(土) 21:46:59.41 ID: Be:
    ち、ちがうもん 

■_

■_

積読解消週間とかやりたい

2011年12月16日

■_

NHKの海外ドキュメンタリーだったと思うのだけど第一次世界大戦をシリーズもの(6~8回くらいだったかな)があって、 あれもう一度観たいなあ。かなり前のものだけど。

なんだろうこれ。 日刊 関数プログラミング 紙

■_

http://www.reddit.com/r/programming/comments/ndzkc/why_programmers_work_at_night/

先送り

■_

http://www.reddit.com/r/Python/comments/nf0dl/python_a_good_first_language_to_stick_with/

先送りその2

■_

■_

2011年12月15日

■_

数学セミナーまだ買ってない。 これほど普段通るところにある本屋で扱っていない代物だったとは! 恵比寿の有隣堂に他の用事でいったときにここならあるだろうと思ったら 見つからなくて、検索機で探しても本当になかったときにはびっくりした (目黒の有隣堂で買ったことがあるからあると思ったんだけど)。 つくばではコンビニにすらあるというのに!(伝聞)

■_

■_ じぇねれーたー

好きなんですよこれ。

Generators for Engineers: A gentle introduction to infinite sequences.

Generators for Engineers

A gentle introduction to infinite sequences.

Original A gentle introduction to infinite sequences. Editable

version 1 of 1

Generators and iterators form the backbone of how Python deals with infinite lists of 
data. Computer Science folk might be a little bored now, because this is the only data 
structure that matters to non-theoretical branches of science, physics and engineering. 
Why an infinite list? All these fields collect data through experiments. The data 
takes the form of a list, one measurement after another. This list is extended until 
the experiment is shut down. Sometimes the experiment is never shut down and results 
must be calculated while new data is still streaming in. From the smallest digital 
signal processor in an MP3 player to the largest force sensor embedded in a bridge's 
roadbed, infinite lists are the norm.

ジェネレーターとイテレーターは Python でのデータの無限リストの扱い方のバックボーンを形
成しています。non-theoretical branches of science や物理、工学では無限リストは非常に重
要なデータ構造ですから、コンピュータ科学の folks にとってはイマサラなものかもしれません。
さて、なぜ無限リストなのでしょう? これらの分野では実験を通じてデータを集めます。
データはリストの形態を取り、one measurement after another.
そしてこのリストはその実験が終了するまで拡大していきます。
ときには実験は終わることがなく新しいデータがまだストリームにある間に結果を計算しなけれ
ばならないこともあります。MP3プレイヤーに内蔵された smallest digital signal processor
から、橋の roadbed に埋め込まれた lagest force sensor に到るまで無限リストは普通なもの
なののです。


Generators and iterators are Python's means of handling infinite sets of data. As of 
Python 3000, they are the default for every operation.

ジェネレーターとイテレーターは Python でデータの無限集合を取り扱う手段です。
Python 3000 では、これはすべての操作におけるデフォルトです。


An excellent feature of Python's generators is constant memory usage. Short generators 
and infinite generators are both the same size, a consequence of not storing any values
the generator produces. Once a value is produced, it is thrown away. One can not look
into a generator's past or future. This article is about using the limitations of
generators to your advantage.

Python のジェネレーターの excelent な feature は一定のメモリーしか使わない点です。
短いジェネレーターと無限ジェネレーターはどちらも同じ大きさで、
格納されてない any values の続きはジェネレーターが生成します。
生成された値は捨てられます。ジェネレータの過去や未来を見ることはできません。
This article is about using the limitations of generators to your advantage.

Let's start practical. You've got a list of data points, and you need to find the 
two-point moving average. Groundwork, first loop through the data and echo out a copy.

Let's start practical.
data point のリストを受け取り、
その two-point moving average を求める必要があるとしましょう。
Groundwork,
最初にデータをなめてそのコピーを出力します。



  >>> data_list = range(10)
  >>> for datum in data_list:
  ...     print datum,
  0 1 2 3 4 5 6 7 8 9

The simplest way to generate the pairs uses C-style array manipulation.

ペアの群を生成する最も単純なやり方は C 形式の配列操作を使うことです。

  >>> data_list = range(10)
  >>> for i in range(len(data_list)):
  ...     print (data_list[i] - data_list[i-1]) * 0.5,
  -4.5 0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5

Of course, in C trying to access data_list[-1] would need to be protected against.

If you want to be clever, you might try list slicing. This works by making two copies 
of the original list. One copy is missing the first element, the other copy lacks the 
last element. zip() lines up the two lists and marches through them simultaneously.

If you want to be clever,
リストのスライシングを試してみたくなるかもしれません。
これは元のリストのコピーを二つ作ることで動作します。
コピーの一つは最初の要素がなく、もう一つのコピーは最後の要素を欠いています。
zip() は二つのリストを lines up し、marches through them simultaneously します。


  >>> data_list = range(10)
  >>> now = data_list[:-1]
  >>> old = data_list[1:]
  >>> for n,o in zip(now, old):
  ...     print (n-o) * 0.5,
  0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5


Amusing bugs caused by negative list indices aside, neither version is acceptable. 
Both require having the entire list in memory. They will not work on streams of data, 
produced in real time. It will also break if you have several gigs of historical data 
to crunch. A better method involves caching:

負のリスト添え字によって引き起こされる amusing バグをおいても、
どちらのバージョンも受け入れられません。
どちらのやり方でもリスト全体をメモリーに納めておくことを要求します。
これはリアルタイムで生成されるデータのストリームに対しては動作しません。
この手法はまた数ギガバイトにおよぶ  historical data を crunch するときにも破綻します。
より良い手法ではキャッシュを用います:

  >>> data_list = xrange(10)
  >>> previous = 0
  >>> for datum in data_list:
  ...     print (datum - previous) * 0.5,
  ...     previous = datum
  0.0 0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5

This is ugly, but it gets the job done. xrange() works as expected. Notice how I've 
been printing data instead of building the results into a new list? We are going to 
make this example into a generator by simply replacing the print with a yield.

これは見た目は悪いですが、仕事はきちんと果たします。xrange() は期待通り
(リストを丸ごと生成してメモリを大量に使用したりしない) に動作します。
新しいリストに構築した結果を格納するのではなく表示したのかに気がついていますか?
print を yield で置き換えてこの例をジェネレーターを使うようにします。

  def moving_average(data_list):
      previous = 0
      for datum in data_list:
          yield (datum - previous) * 0.5
          previous = datum

  >>> list(moving_average(xrange(10)))
  [0.0, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5]

This is not the typical use case, however. Wrapping the generator in list() removes 
any benefits. A more practical case would apply the moving average to cut through 
sensor noise.

しかしこれは典型的な use case ではありません。
list() でジェネレータをラッピングすることで一切の benefits を捨ててしまっています。
より practical な case は sensor noise を cut through するのに moving average
を適用することです

  for average in moving_average(noisy_sensor):
      if average > safe_value:
          alert("Sensor reads dangerous values.")

There are a few problems. The name data_list is now misleading. Lists, tuples, 
generators, iterators, any can be taken as input. But naming conventions are the least 
of our problems. This code is brittle. What do you do when you need to support +3 
point moving averages?

いくつか問題があります。name data_list は misleading なものになりました。
リスト、タプル、ジェネレーター、イテレーター、任意のものを入力として受け取れます。
しかし命名規約は the least of our problems です。
このコードは brittle (壊れやすい、不安定) です。
moving averages に +3 point するのをサポートしなければならなくなったら
あなたはどうしますか?


If you've heard of the itertools module, feel free to skip this section. If you do not 
already love itertools, read this. Itertools provides high level operations for 
infinite lists. There are also a bunch of awesome mathy parts, such as
itertools.combinations() and itertools.permutations(). We'll be using tee(), islice() 
and count(). count() is pretty simple. It acts like xrange(0, infinity). You can 
specify any starting point, but it will always keep on counting up. islice() is a bit 
more tricky. It has similar semantics to slice(), where slice() is the underlying 
function to Python's list[start:stop:interval] notation. All these snippets do the 
same thing, produce even numbers between 4 and 16.

itertools モジュールのことを聞いたことがあるのなら、
このセクションを飛ばしてしまってもかまいません。
もしまだ itertools が好きでないのなら、このセクションを読んでください。
itertools は無限リストに対する high level の操作を提供します。
itertools モジュールには itertools.combinations() や itertools.permutations()
のような awesome な mathy parts がたくさんあります。
わたしたちはこれから tee()、 islice()、count() を使います。
count() はとても単純で、xrange(0, infinity) のように振る舞います。
任意の開始点を指定できますが、常にカウントアップし続けます。
islice() はそれよりもちょっと tricky です。
Pythonn の list[start:stop:interval] 表記の underlying function である
slice() に似た semantics を持っています

All these snippets do the same thing, produce even numbers between 4 and 16.
以下のコード片はすべて同じことをして、4から16までの偶数を生成します。


  range(20)[4:16:2]
  slice(range(20), 4, 16, 2)
  from itertools import islice, count
  islice(count(), 4, 16, 2)


What makes islice really different is that the ending bound is optional, by setting it to
None. To make all even numbers greater than four, just use islice(count(), 4, None, 2).

islice が本当に slice と異なっているのは、None を設定することにより
ending bound が optional になるということです。
4 よりも大きなすべての偶数を生成するには単に islice(count(), 4, None, 2) とすればできます。


tee() is more complicated. It spawns iterators which are linked back to the original 
iterator. Basically, it lets you loop over the same iterator multiple times, at the 
same time. For example, let's say you need the moving average and deviation from the 
noisy_sensor. This is wrong:

tee() はさらに複雑で、元のイテレーターに対する linked back であるイテレーターを spawns します。
基本的には tee() は同一のイテレーターを同時に複数回 loop over させます。
たとえばnoisy_sensor から moving average と deviation を求める必要があるとしましょう。
次のやり方は間違いです:

  from itertools import izip
  averages   = moving_average(noisy_sensor)
  deviations = moving_deviation(noisy_sensor)
  for ave, dev in izip(averages, deviations):
      if ave > safe_value:
          alert("Sensor reads dangerous values.")
      if dev < expected_deviation:
          alert("Sensor may be disconnected.")

The problem here is that moving_average() and moving_deviation() are both consuming 
values from the generator noisy_sensor. Each will take half the values, and none will 
be shared. tee() fixes this.

ここでの問題は、moving_average() と moving_deviation() の両方ともが
noisy_sensor というジェネレーターからの値を消費するという点です。
それぞれが値の半分を取り、共有するものはありません。
tee() はそれを解決します。

  from itertools import tee
  copy1, copy2 = tee(noisy_sensor, 2)
  averages   = moving_average(copy1)
  deviations = moving_deviation(copy2)
  ...

Okay, so now that the basics are out of the way, here is a code snippet I use 
frequently. It provides a moving window over a stream of data.

Okay, so now that the basics are out of the way,
わたしが良く使うコード片を紹介しましょう。
これはデータのストリームに対する moving window を提供します。

  def moving(iterator, length, step=1):
      ms = tee(iterator, length)
      return izip(*[islice(m,i,None,step) for m,i in zip(ms, count())])

  >>> for i in moving(xrange(10), 3):
  ...    print i
  (0, 1, 2)
  (1, 2, 3)
  (2, 3, 4)
  (3, 4, 5)
  (4, 5, 6)
  (5, 6, 7)
  (6, 7, 8)
  (7, 8, 9)

  # step makes it very flexible
  >>> for i in moving(xrange(9), 3, 3):
  ...     print i
  (0, 1, 2)
  (3, 4, 5)
  (6, 7, 8)
 
From there is is easy (although inefficient) to apply the average or deviation to each 
chunk. It works identically to the example awhile back; where the list was copied, 
sliced and zipped together but instead with iterator-friendly commands.



Regarding efficiency, simple operations such as moving averages can be improved 
tremendously using double-ended queues, or deques. Oddly enough, it is pronounced 
"deck". Deques are another friend of the engineer, as they make a simple 
FIFO buffer. Lists can be used as a crude FIFO, but they do not scale well. Adding new 
elements to a list with .append() is O(1). But using .pop(0) to remove the oldest 
element is O(n). For deques, the equivalent of both are O(1). Here's how to computer a 
moving average using a deque.

効率に関して、moving averages のような単純な操作は double-ended queue (deques) を使うことで
劇的に改善される可能性があります。Oddly enough, it is pronounced "deck".
deques はエンジニアのもう一人の友人で、FIFO バッファーを単純にします。
リストは crude FIFO として使えますが、それはよく scale しません。
.append() でリストに要素を追加するのは O(1) ですが、
最も古い要素を remove する .pop(0) は O(n) なのです。
deque ではそのどちらも同じで O(1) です。
どのように deque を使って moving average を計算するのかを示します。


s/computer/compute in "Here's how to computer [...]". Thanks for ...

  from collections import deque

  def moving_average(iterator, length):
      d = deque(islice(iterator, 0, length))
      s = sum(d)
      yield s / length
      for i in iterator:
          s -= d.popleft()
          s += i
          d.append(i)
          yield s / length

This is O(n) to start up, and O(1) for all subsequent averages. Feel free to get in 
touch with me if you need something more exotic.


© Kyle Keen 2008-2011

2011年12月14日

■_

J10 欲しい パナソニック Let's noteシリーズ、超軽量モデルからA4モバイルまで:メーカー別に一気に見せます!2011年秋冬パソコン パナソニック Let's noteシリーズ、超軽量モデルからA4モバイルまで:メーカー別に一気に見せます!2011年秋冬パソコン

もうちょい安ければなあ

三分冊の二冊目がでるみたいなのだけど、このシリーズやっぱ買っておいたほうがいいかなあ。 独習コンピュータ科学基礎I 離散構造 - 翔泳社の本 独習コンピュータ科学基礎II 論理構造 - James L. Hein/神林靖/翔泳社

まあ大型本はなかなか買う気になれないんだけど (それで手を出していないのが何冊もあったりして)。

■_ R とか L とか

rvalue reference、move semanticsに挫折した人のための再入門解説 - Ideals and Reality

C++ Rvalue References Explained Page 2 of: C++ Rvalue References Explained (Move Semantics)

Value (computer science) - Wikipedia, the free encyclopedia
Assignment: l-values and r-values

Some languages use the idea of l-values and r-values. Lvalues are values that have 
addresses being programmatically accessible to the running program (e.g., via some 
address-of―operator like "&" in C/C++), meaning that they are variables 
or dereferenced references to a certain memory location. Rvalues can be lvalues (see 
below.) or non-lvalues―a term only used to distinguish from lvalues.

一部の言語では、l-value と r-value という考え方を使っています。
lvalue はプログラムを実行させるためにプログラム的にアクセス可能な addresses being を
持つ値のことで、要するに変数であるとか特定のメモリー領域への
dereferenced references です。rvalue は lvalue であってもよいし、
lvalue と区別するためだけに使われる non-lvalue を指す用語でもあります。

あとでまとめる。 うぃきぺの Value の項目のところで CPL が出てきてちとびっくりした http://en.wikipedia.org/wiki/Combined_Programming_Language

■_

Zed が執筆中の正規表現入門書の最初の辺り。

Introduction: Giants In Tiny Pants

Introduction: Giants In Tiny Pants

Do you like word problems? You know those annoying "math" questions you had 
to study in class simply because the SAT used them. They went something like this:

word prlblems は好きですか?


   "A train leaving a station at 10:50pm from San Francisco is travelling at 40MPH. 
   Another train leaving Chicago at 12:00pm is going 60MPH. At which point will the two 
   trains cross paths."

Even today, after studying years of advanced mathematics, statistics, and computer 
science, I still can't solve these things. The reason is they're an attempt to hide an 
actual equation from you with convoluted English wording. Rather than just give you a 
straight math problem, like ax + b = c they want you to "reverse engineer" 
the real equation from this pile of ambiguity. In an attempt to simplify mathematics 
these types of questions actually end up obfuscating the real symbolic language behind 
them.

今日もなお、何年も高度な数学だとか統計、コンピューター科学を学んだあとでさえ
こういった問題を解くことができません。その理由は、こういった問題は
convoluted English wording から actucal equation を隠してしまっているからです。
ax + b = c のような直接的な数学の問題というよりはむしろ、
本当の euation をくずデータの山から組み立てる
「リバースエンジニアリング」のようなものなのです。
#おーだいぶ変えたぞ

Imagine if all mathematics was like this where every single problem you encountered, 
no matter how simple or complex, was only written as English because nobody understood 
the symbols. This would drive you crazy, even if you didn't know mathematics. Without 
the symbols of mathematics we'd find mathematics degenerate to one Jacques Derrida 
style "obscurantisme terroriste" paper after another. They'd be no better 
than Philosophers!


Thankfully, humans invented symbols to succinctly describe the things that symbols are 
best at describing, and left human languages to describe the rest.1 The symbolic 
languages act as building blocks to construct complex structures in a short space that 
would take entire books in English to describe.

The power of symbolic languages is that, once you learn them, they can describe things 
more quickly and accurately than a human language can.

0.1 Regular Expressions Are Character Algebra
    正規表現とは Character Algebra (文字代数?) である

ぐはっ。なんかこううまい日本語がでてこない。

■_

Programming With Nothing

■_

■_ Hash の構文

こう言う人もいるのだなあ。

I don't like the Ruby 1.9 hash syntax ≪ Logical Friday
"There, I said it, I don't like it. And I don't know why you do either."
http://logicalfriday.com/2011/06/20/i-dont-like-the-ruby-1-9-hash-syntax/

Scripting News: Why apps are not the future
"I hear it everywhere. The web is dead, apps are the future. #"
http://scripting.com/stories/2011/12/13/whyAppsAreNotTheFuture.html

2011年12月13日

■_

この辺でちょっと凹んだ→ 【プロ野球】9年越しの巨人入りを喜ぶ村田 - MSN産経ニュース いやまあ、あの年いろいろあったらしいのは聞いたことあるけどさあ そんなこといっちゃあ以下略だよなあ。がっくし。

twitter
フィルタリングしたい。 人じゃなく発言で。 そうでもしないともうどうにもならん気がするw

■_

かなりぐだぐだになってしまった

The Problem with C++ Templates

The Problem with C++ Templates
C++ のテンプレートにまつわる問題点

C++ has evolved as a language that encompasses many modern programming techniques. In
this way, C++ has managed to stay relevant, despite the many issues that it may have
compared to safer languages such as Java or C#. In C++, one can decide the set of
features that will be used from within a large set of alternatives. If you're
inclined to do so, you could use only an strictly object oriented style, or maybe a
functional oriented style, if that suits you better. Moreover, with the additions
proposed in C++11, you can even use closures to make your coding style more functional.


C++ は多くの modern なプログラミングテクニックを encompasses (包含)する言語として進化
してきました。その過程において、Java や C# のようにより安全な言語と比較されてしまうか
もしれない多くの issues がありましたが、 C++ は適切に管理されてきました。C++ では、ユ
ーザーは使うであろうひと揃いの機能をa large set of alternatives の中から選び取れます。
ユーザーが望むのであれば strictly なオブジェクト指向スタイルだけを使うことをできるでし
ょうし、より良いものであるのなら関数指向スタイルもできるでしょう。さらに C++11 で追加
提案されたものによって、コーディングスタイルをより functional にするためにクロージャー
すら使えるのです


Among the features provided by C++, one that it pioneered was the use of template
programming. While templates provide some of the features allowed by Lisp macros, they
also enforce type safety. This safety helps a lot when working with a language such as
C++, which is so strict about the correct use of types.

C++ によって提供されている機能の中で one that it pioneered だったのが、テンプレートプ
ログラミングの利用です。テンプレートはLispのマクロによって可能となっている機能の一部
を提供していますが、テンプレートは型の安全性も enforce しています。この safety は
C++ のように型の使用を correct することに関してとても strict な言語を使って作業すると
きに大いに助けになります。


Templates and the Type System
テンプレートと型システム


Templates have been crucial to provide some features previously missing in C++. For
example, the idea of generic containers can only be possible with some kind of type
instantiation. Even other languages such as Java and C# had to introduce template-like
features in order to cope with the problem of generic containers.

テンプレートは、それまでの C++ に欠けていた幾つかの機能を提供するために必須なものでした。
たとえば generic コンテナーのアイデアはある種の type instantiation があってのみ可能とな
ります。ほかの、Java や C#のような言語でさえ、 generic containers の問題に対処するために
テンプレートのような機能を導入しなければなりませんでした。


While templates are very important, they also bring a severe burden into the language.
Templates operate at compile time, making decisions about how to instantiate a
particular type given the options allowed by the available template code. This kind of
decision is not only powerful, but also time consuming.

テンプレートは非常に重要である一方で、severe burden (非常に厄介な問題) を言語に持ち込みも
しました。テンプレートはコンパイル時に operate し、利用可能なテンプレートコードで可能な
選択の範囲で特定の型をインスタンス化できるのかを決定します。この種の decision は強力であ
る一方で、時間のかかるものでもあるのです。


The trouble with using templates more generally is that they are not very programmer
friendly. While templates solve important problems, they are also hard to use and
design. Here follow a few issues that I believe are of high importance.

より一般的には、テンプレートを使うことによる問題はそれがプログラマーに対してぜんぜん親切
ではないということです。テンプレートは重要な問題を解決しますが、それと同時に、使ったり設
計することがとても難しいものなのです。わたしがとても重要だと確信している issue の幾つか
を以下に挙げます。


Module Separation
モジュールの分割

C++ provides header files as a method for creating modules and explicitly separating
interface from implementation. However, templates make this separation harder to
achieve. When a compiler creates code from a template, it needs not only access to the
interface, but also to the whole definition of the template. The reason is that much
of the required information used by a template is stored in its definition. For
example, what are the methods accessed in a particular type? These properties are
needed by the compiler to decide if a template can be expanded or not.

C++ はモジュールの作成手段とインターフェースと実装とを明確に分けるための手段としてヘッダ
ーファイルを提供しています。しかしテンプレートはこの分割を achieve 困難なものにします。
コンパイラーはテンプレートからコードを生成するときにインターフェースに対するアクセスだけ
ではなくて、テンプレートの定義まるごとに対するアクセスを必要とします。その理由は、テンプ
レートで使用されていて必要な情報の多くがその定義に置かれているからというものです。それは
たとえば、ある特定の型においてアクセスされるメソッドは何か? といったものです。そういった
属性はテンプレートが expand 可能か否かをコンパイラーが決定するのに必要なです。


In the past, there were some proposals to fix the module separation issue. Using the 
external keyword along with a template declaration was one of the options proposed by 
the ANSI committee, but it was never implemented by the major compilers, and nowadays 
it has been deprecated. It seems that there will be no solution in foreseeable future, 
so the only thing it remains for software engineers is to minimize the use of 
templates unless they are really required.

過去、このモジュール分割問題を解決するための提案がいくつかなされました。予約語 external を
使ったテンプレート宣言は ANSI commitee によって提案されたオプションのひとつでしたが、しかし
それはメジャーなコンパイラーにはまったく実装されることなく今日では deprecated とされていま
す。foreseeable future (予見可能な将来) においても解決策はなさそうなので、ソフトウェアエン
ジニアに残されている手段は、本当にそれが必要でない限りテンプレートの使用を最小限にするとい
うものです。


Compilation Time
コンパイル時間

Another issue that is a consequence of the above is the compilation time necessary to
use templates. Since all of the template must be accessible to the compiler, if no
additional calculations were necessary we would still have a severe burden by including
templates in a project. However, remember that templates provide a sub-language within
C++ that is known to be Turing-complete. This means that badly behaving templates can
very well turn into infinite loops, among other issues that need to be debugged ― at
compile time. This means that using templates requires a lot of care from the part of
the programmer, since it can result both in compile-time as well as run-time bugs.

上記に関連するもうひとつの問題がテンプレートを使ったコンパイルに必要となる時間です。テンプレ
ートのすべてはコンパイラーからアクセス可能でなければならないので、additional calculations の
必要がなかったとしてもプロジェクトでテンプレートを使ったことによる severe burden  は依然とし
て残ります。ただし、テンプレートが C++ 内部に provide する sub-language はチューリング完全で
あると知られているものだということを忘れないでください。これはテンプレートを使うことはプログ
ラマーの一部に多くの注意を要求することを意味します。なぜなら、テンプレートの使用によって実行
時のバグだけでなくコンパイル時のバグもその結果としてありうるからです。


But it doesn't stop there. Templates also have a very particular way to bloat
executables, which can turn a simple looking solution into a nightmare of slow linking
times. Templates have this tendency to generate additional code for each instantiation
for a concrete type. For example, for every compilation unit, in the first time you
create a std::vectorthe compiler will try to instantiate yet another version of
std::vector, even if there already is a version of that template for each compilation
unit of the program. This is not such a huge problem because a linker will check all
existing object files and remove duplicate versions of template instantiations. The
real problem is that this process takes time. In a big C++ project this can consume
from a few seconds to several minutes.

問題はまだあります。テンプレートには、単純に見える solution を slow linking times の悪夢
へと変えてしまいかねないような実行ファイルを膨れ上がらせる very particualar way がありま
す。テンプレートは、具体的な型の instantiation のそれぞれに対する additional code を生成
するためにこの tendency を持っています。たとえば、すべてのコンパイルユニットに対して、
std::vector をあなたが初めて生成したときにコンパイラーはそれでも別のバージョンの
std::vector のインスタンス化にトライするでしょう。たとえそれが、プログラムのコンパイルユ
ニットごとのテンプレートですでにコンパイルされたものであってもです。
本当の問題 (real problem) はこのプロセスに時間が掛かるということです。
大きな C++ プロジェクトではこのプロセスに数秒から数分要する可能性があります。


The other issue, however, happens when the method described above doesn't remove all
the multiple copies of a template. In fact, there might be thousands of legitimate
instantiations of a template in a single program. For example, if you have thousands
of types (which is common in a C++ project), you may also have thousands of different
instantiations of std::vector, and even millions of instantiations of std::map(not
common, but possible).

しかし、上記のように記述されている手順でテンプレートの重複しているコピーを全部取り除か
なかったときには別の問題が起きます。実際、ひとつのプログラムのひとつのテンプレートの、
何千もの legitimate instantiations (妥当なインスタンス化) となるかもしれません。たとえ
ばもし、ユーザーが数千個の型を持ち(一つのC++プロジェクトとしてはよくあることです)、
std::vector の異なるインスタンス化 (diffrent instantiaions) が起こる可能性や、
数百万になんなんとする std::map のインスタンス化 の可能性すらあります (一般的ではあり
ませんが可能性はあります)。


Then you have design issues that make this even worse. I once worked in a project that
had a template for String, where n was the maximum size of the string. The designers
of this template thought they were doing a good service, until you realize that there
is a copy of this template for each of the hundreds of string sizes used in the
project. Also, using a template like this induces the creation of related templates,
so you end up having ImmutableString, etc.

それからさらに事態を悪化させる設計上の問題 (design issues) を抱え込むことになります。
I once worked in a project that had a template for String,
where n was the maximum size of the string.
The designers of this template thought they were doing a good service,
until you realize that 
there is a copy of this template 
for each of the hundreds of string sizes used in the project.
Also, 
using a template like this induces the creation of related templates,
so you end up having ImmutableString, etc.



Conclusion
結論

I just scratched the surface of possible problems when using templates in C++. My goal
is not to discourage the use of existing templates, such as the STL, but to caution
against the indiscriminate use of templates in C++ projects. I personally think that
you should use templates only to go around limitations in C++, because that is why
they were originally created. Trying to use templates as a normal programming paradigm
unleashes more problems, as we just mentioned, than it can possibly solve.

わたしは単に C++ のテンプレートを使ったときに起こりうる問題を表面的に眺めてみただけです。わ
たしの目標は STL のような既存のテンプレートを使うのを discourage することではなくて、C++ プ
ロジェクトにおけるテンプレートの indiscriminate use に対して警告することです。個人的にはわ
たしはこう考えます。C++ における制限を回避するためにのみテンプレートを使うべきだと。なぜな
らそれこそがテンプレートが作られた元々の理由であるからです。a normal programming paradigm
としてテンプレートを使おうとすることは、わたしたちが今まさに述べてきたように、問題解決が
可能になるというよりむしろ一層問題を引き起こすこととなります。


Published on November 10th, 2011

Copyright c Carlos Oliveira ・ All rights reserved.
Powered by HostGator

■_ 群環体

ム板でこういう質問が出るんだねえ

スレ立てるまでもない質問はここで 115匹目

362 デフォルトの名無しさん [sage] 2011/12/13(火) 03:37:44.18 ID: Be:
    数学で、群・環・体ってありますよね。
    体についてはおおよそ思い出せるのですが、群・環について、満たすべき条件を中々思い出せません。
    ググればいいのですが、基礎の基礎ですので暗記していないとまずいですよね?
    群・環が満たすべき条件の、いい覚え方ってないでしょうか?

    どなたか、暇な時でいいので答えていただけませんでしょうか?

363 デフォルトの名無しさん [sage] 2011/12/13(火) 03:40:52.79 ID: Be:
    おいどんは軍艦たい
    死むど 

364 デフォルトの名無しさん [sage] 2011/12/13(火) 03:42:40.33 ID: Be:
    ゲバ本嫁 

366 デフォルトの名無しさん [sage] 2011/12/13(火) 06:01:53.02 ID: Be:
    >>362
    演算数の違い。
    群・・・ひとつ
    環・・・ふたつ
    体・・・みっつ 

367 デフォルトの名無しさん [sage] 2011/12/13(火) 06:06:02.79 ID: Be:
    体はちがうか。
    体が一番複雑。群が一番簡単。

    群は、足し算のような演算が定義されている集合。
    環は、群であってかけ算のような演算が定義されている集合。
    体は、環であってかけ算に関する可逆元が存在する集合。 

368 デフォルトの名無しさん [sage] 2011/12/13(火) 06:11:50.96 ID: Be:
    体が一番簡単。
    群が複雑。
    のまちがえだろ? 

369 デフォルトの名無しさん [sage] 2011/12/13(火) 06:20:25.00 ID: Be:
    定義がいちばん複雑なのが体。
    体は群であるから、群の方が沢山あるという意味で調べる事のは群の方が大変と言える。 

370 デフォルトの名無しさん [sage] 2011/12/13(火) 06:24:01.68 ID: Be:
    群環体を勉強してこれの知識があると、ある事象をプログラムとして設計するときにかなり面白くかつ楽しくなるのは確かだけどね。 

371 デフォルトの名無しさん [sage] 2011/12/13(火) 06:36:32.66 ID: Be:
    足し算、かけ算に関して群をなす集合が体。
    足し算が群、かけ算が半群である集合が環。
    足し算が定義されている集合が群。 

373 デフォルトの名無しさん [sage] 2011/12/13(火) 07:00:18.05 ID: Be:
    >>362 半群がすべての基礎。
    集合Sが、半群であるとはSに二項演算+が定義され次を満たすとき。
    Sの要素a, bに対して、a+bはSの要素。Sの要素a, b, cに対して、(a + b) + c = a + (b + c) が成り立つ。


    半群Sが、群であるとはSの要素Iで任意のSの要素aに対してI + a = a + I = aを満たすものが存在し、
    かつ任意のSの要素aに対してある要素bが存在してa + b=b + a = Iをみたす。(単位元と可逆元の存在)

    群Sが、環であるとは 

374 デフォルトの名無しさん [sage] 2011/12/13(火) 11:10:12.81 ID: Be:
    >>362です。寝落ちしてました。すみません。

    >>363
    語呂合わせか何かでしょうか?
    もう少し詳しくお願いします。

    >>364
    ゲバ本とは何でしょうか?ググってみましたが、分かりません。

    >>367
    それが、覚えにくいんですよね・・・

    >>373
    > 群Sが、環であるとは
    加法に関してアーベル群をなし、乗法に関して半群または単位半群であり分配法則を満たすものですよね?

    調べてもすぐ忘れてしまう・・・何かいい暗記法はないものか・・・ 

375 デフォルトの名無しさん [sage] 2011/12/13(火) 11:15:17.53 ID: Be:
    何んでこのすれで聞くの? 

■_

じかんぎれー

■_

■_

実に興味を惹かれるが時間がががががが Why I Don't Think Twitter Has a Future Why metaprogram when you can program? « The Real Adam

2011年12月12日

■_

付箋紙
あとで何か書こうと思いながら読む本には付箋紙をやたらと貼っていくのですが、 移動時に読む場合付箋紙をどう持ち歩くかは非常に悩ましい問題だったりします。 で、昨日紀伊国屋書店で見つけたのがこれ→ 株式会社カンミ堂【取扱商品】ココフセン 買ってみたのでちょっと試そう。

■_

Perl 6 Advent Calendar 結構面白い題材が並んでる。

Traits — Meta Data With Character « Perl 6 Advent Calendar

Traits — Meta Data With Character
by Moritz

Traits are a nice, extensible way to attach meta data to all sorts of objects in Perl 6.

trait は Perl 6におけるすべての種類のオブジェクトに対して
メタデータを attach するための nice な extensible way です。

An example is the is cached trait that automatically caches the functions return value, 
based on the argument(s) passed to it.

ひとつの例として挙げるのは、関数の戻り値を渡された引数に応じて自動的にキャッシュする
cached trait です。

Here is a simple implementation of that trait:
以下のものはそういった trait の単純な実装です:

 # this gets called when 'is cached' is added
 # to a routine
 # あるルーチンに 'is cached' が追加されたときに呼び出される
 multi sub trait_mod:<is>(Routine $r, :$cached!) {
     my %cache;
     #wrap the routine in a block that..
     # ブロックの中にルーチンをラップする
     $r.wrap(-> $arg {
         # looks up the argument in the cache
         # キャッシュに置かれた引数を検索する
         %cache.exists($arg)
             ?? %cache{$arg}
             # ... and calls the original, if it
             # is not found in the cache
             !! (%cache{$arg} = callwith($arg))
         }
     );
 }

 # example aplication:
 sub fib($x) is cached {
     say("fib($x)");
     $x <= 1 ?? 1 !! fib($x - 1) + fib($x - 2);
 }

 # only one call for each value from 0 to 10
 # 0 から 10の値それぞれに対してただ一度だけ呼び出す
 say fib(10);

A trait is applied with a verb, here is. That verb appears in the routine name that 
handles the trait, here trait_mod:<is>. The arguments to that handler are the 
object on which the trait is applied, and the name of the trait (here cached) as a 
named argument.

ここでは trait は verb (動詞)を伴って適用されています。
この verb はその trait を扱うルーチン名の中に現れていて、
この例では trait_mod:<is> です。
そのハンドラーに対する引数はtrait が適用されたオブジェクトと
名前つき引数としての trait の名前(ここでは cached)です。

Note that a production grade is cached would need to handle multiple arguments, and 
maybe things like limiting the cache size.

cache された production grade は複数の引数を取り扱う必要があり、
キャッシュサイズのような制限があるだろうことに注意してください。


In this example, the .wrap method is called on the routine, but of course you can do 
whatever you want. Common applications are mixing roles into the routine or adding 
them to a dispatch table.

この例では、ルーチン上で .wrap メソッドは呼び出されますが、
もちろんあなたの望むことは何でもできます。
Common application (一般的な適用例) はそのルーチンに roles を mixing したり
ディスパッチテーブルにルーチンを追加したりすることです。

Traits can not only be applied to routines, but also to parameters, attributes and 
variables. For example writable accessors are realized with the is rw trait:

trait はルーチンに対してだけではなくパラメーターやアトリビュート、変数に対しても適用できます。
たとえば writable なアクセサーは rw trait によって realize されます。


 class Book {
     has @.pages is rw;
     ...
 }

Traits are also used to attach documentation to classes and attributes (stay tuned for 
an addvent calendar post on Pod6), marking routine parameters as writable and 
declaring class inheritance and role application.

trait はまた、クラスやアトリビュートにドキュメントを attach するためや
ルーチンパラメーターを writable とマーキングするため、あるいは
クラス継承や role application の宣言にも使われます。


This flexibility makes them ideal for writing libraries that make the user code look 
like a domain-specific language, and supplying meta data in a safe way.

この flexibility はユーザーのコードをドメイン特化言語 (domain-specific langauge) の
ように見せるライブラリーを書きやすくして、安全な方法でメタデータを supply させます。

■_

ぼつ

■_

■_

2011年12月11日

■_

コミケのカタログ(DVD-ROM版)を買った。 暗刻通信団が出ているらしいのと、 "Twitter / @baatarism: 誰か行ってみて下さい。w RT @96nabe_ く ..." のあたりをチェックしておかねば。

The end of social - O'Reilly Radar

■_ echo

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

344 デフォルトの名無しさん [] 2011/12/10(土) 20:56:22.99 ID: Be:
    void main()
    ってなんでできないんだろう 

347 デフォルトの名無しさん [sage] 2011/12/10(土) 23:33:47.57 ID: Be:
    >>344
    短い答え: 規格嫁 旧規格 現規格
    長い答え: 略w

    しかし、「なんで~はできないんだろう」という質問をするということは、「~はできるべき」と
    思ってるのか? ならなんで「~はできるべき」だと思うんだ?
    まずはそこから説明してくれw 

348 デフォルトの名無しさん [] 2011/12/11(日) 00:11:40.09 ID: Be:
    ちょっと違うね
    できないという前提でなぜだと聞く二重質問だ
    前提が間違っているだけに答えようがない 

349 デフォルトの名無しさん [sage] 2011/12/11(日) 00:30:46.01 ID: Be:
    「UNIXプログラミング言語」に載ってたEchoの童話を思い出した。 

350 デフォルトの名無しさん [sage] 2011/12/11(日) 00:37:25.06 ID: Be:
    >>349
    すごく内容が気になるな
    どんな話だよ 

351 デフォルトの名無しさん [sage] 2011/12/11(日) 00:46:02.80 ID: Be:
    "[UNIXプログラミング環境] Unix と Echo"で検索すればおk(多分…) 

352 デフォルトの名無しさん [sage] 2011/12/11(日) 00:48:04.32 ID: Be:
    間違えた、「UNIXプログラミング環境」だった。

    >>350
    昔読んだので詳しくは覚えていない。
    確か、Echo に完全な動作を求める若者が、最後は観念の渦に飲み込まれてしまう話。 

353 デフォルトの名無しさん [sage] 2011/12/11(日) 01:07:07.41 ID: Be:
    えちょー!

    その本、買うだけ買って読んでないなw 

うん。あれはなかなか面白い話だった> echo の物語

■_ おーい

誰だよ訳したの

テンプレートを使ったコードをビルドしようとして???ってなってる - 虎塚
(略)

VCとgccコンパイル時の違いメモ
その1

VCではこれで通るけど、

  template<class T, class A = allocator1<T>> class vector1 {
      // ...
  }

gccではこうしないとダメ。

  template<class T, class A = allocator1<T> > class vector1 {
      // ...
  }

閉じカッコが間にスペースを挟まずに続くと、operator>>とみなされるのでしょうか?
(略)
E_Mattsan 2011/12/10 16:21 「きちんと閉じカッコふたつと解釈する」という仕様が採用されたくだりがこちらに書かれてますヨ。
http://www2.research.att.com/~bs/C++0xFAQ.html#brackets
http://www32.ocn.ne.jp/~ons/text/CPP0xFAQ.html.ja#brackets (日本語訳)
美味しい魚を食べる会で、コンパイラについて云々騒いでいたのがちょうどこのあたりの話でした。

このコメントのリンク先に行ってみる

C++11 FAQ

不等号閉じ括弧
以下を考えよ。


	list<vector<string>> lvs;

C++98 では、二つの > の間にスペースがないので、文法エラーになる。 C++0x では、この >
を正しく二つの template 引数リストの終わりだと認識する。

なぜこれが今まで問題だったのか? コンパイラフロントエンドはパース/ステージに構成されて
いる。 もっとも簡単なモデルは以下のようになる:

    構文解析 (文字列からトークンを切り出す)
    文法解析 (文法をチェックする)
    型チェック (型名と式を見つけ出す) 

これらのステージは理論的に (そして時には実用上の理由で) 厳密に分かれており、そのため >>
をトークン (通常は右シフトか入力の意味) だと判定する構文解析器は、その意味を知らないのだ;
特に、template やネストした template の引数リストの意味は全く知らない。 しかしながら、
この三つのステージがどうにかして協力しないと、この例を「正しく」処理することはできない。
この問題を解決に導くのに鍵となったことは、全ての C++ コンパイラが既にこの問題を理解しており、
きちんとしたエラーメッセージを出力できている、という実績だった。

以下も参照。

    C++ 草案セクション ???
    [N1757==05-0017] Daveed Vandevoorde: 右不等号括弧に関する提案の改版 (第2版). 

え、構文解析 (文字列からトークンを切り出す) ってどゆこと? で、原文。

C++11 FAQ
right-angle brackets
Consider

	list<vector<string>> lvs;

In C++98 this is a syntax error because there is no space between the two >s. C++0x 
recognizes such > as a correct termination of two template argument lists.

Why was this ever a problem? A compiler front-end is organized parses/stages. This is 
about the simplest model:

    lexical analysis (make up tokens from characters)
    syntax analysis (check the grammar)
    type checking (find the type of names and expressions) 

These stages are in theory and sometimes in practice strictly separate, so the lexical 
analyzer that determines that >> is a token (usually meaning right-shift or 
input) has no idea of its meaning; in particular, it has no idea of templates or 
nested template argument lists. However, to get that example "correct" the 
three stages has somehow to cooperate. The key observation that led to the problem 
being resolved was that every C++ compiler already did understand the problem so that 
it could give decent error messages.

See also

    the C++ draft section ???
    [N1757==05-0017] Daveed Vandevoorde: revised right angle brackets proposal (revision 2). 

んー、lexical analysis は「字句解析」で、 syntax analysis が「構文解析」ですね。 文法に従っているかどうかを検査するのだから、「文法解析」はちと変な気が。

字句解析 - Wikipedia 構文解析 - Wikipedia

■_ 求むメンター

reddit。

Looking for a Python mentor to 'apprentice'. Anyone interested in that sort of thing? : Python

A little background on me:

I'm a Cisco network engineer at a medium-to-large size manufacturing company. I've been
in IT around 6 years doing mostly networking, but some helpdesk and server admin as well.
I've always been amazed at how the developers are treated and paid compared to almost
everyone else in IT, and I've always had an interest in programming. In high school I
learned QBasic and made Final Fantasy fan pages in Geocities (don't hold that against
me please). Anyway, I digress.

I'm brand new to the language, but I'm pretty passionate about learning it and learning
it the right way.

わたしはこの言語 (Python) に入門したばかりですが、学ぼうという情熱はありますし
正しいやり方で学びたいのです。

I've always been a fan of the apprenticeship method.

わたしはいつも apprenticeship method (師匠と弟子メソッド。くらい?) にあこがれていました。

I guess what I'm asking is, is someone out there willing to do the following:

ここでお願いしたいことは、誰か以下にあげることをやってくれないだろうかということです:

  Take on an apprentice
  Communicate with me directly over facebook or e-mail
  Give me basic tasks or activities to learn Python
  Help me with any questions I might have in-between

If this sounds like something you might want to do, please reply!


The python tutor mailing list is extremely friendly and will be a good place to start 
while you wait for a mentor

Best wishes


Thank you, I was unaware this existed. I will use it while waiting :)


As a sysadmin you might be acustomed to certificate programms. There is a fully featured
Python certificate course on oreillyschool.com.

This course was written by Steve Holden who is the chairman of the 
Python-Software-Foundation.

I have a similar background as you and this course made me a programmer, i loved it 
and it taught me a lot.

If you go that way then google for promo codes before purchasing the courses, this can 
take off 20 or more % if you're lucky.

■_

なんか面白そうなので読む

Java apps have most flaws, Cobol apps the least, study finds - Computerworld

Java apps have most flaws, Cobol apps the least, study finds

Analysis of 745 apps determines costs of flawed software as IT interest in 'technical debt' takes off

■_


一つ前へ 2011年12月(上旬)
一つ後へ 2011年12月(下旬)

ホームへ


リンクはご自由にどうぞ

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