ときどきの雑記帖'

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

一つ前へ 2013年9月(上旬)
一つ後へ 2013年9月(下旬)

ホームへ

2013年09月20日

■_

どうもこの出版社の本に対する情報が入ってくるのが遅いなあ。 入手元の問題だろか。 Amazon.co.jp: ECMA-262 Edition 5.1を読む: 竹迫 良範: 本 発売日: 2013/9/25 すぐじゃーん。 そういやYAPCの会場で竹迫さんと(二回ばかり)間近ですれ違ったんだけど、 shibuya.pm でわたしが発表したのは二年ちょっと前だったりしたので 気づかれなかった。いやまあこちらから声かけるべきなんですけどねねね。

■_

むかーーーーしとある雑誌で 「言語にとっての美とは何か」とかいった特集があったような。 あ、ここでいう「言語」は「プログラミング言語」のことね。

■_ yapc

なんかこうまとめるキリョクが… とりあえず気になったのは飲食禁止なルールを守ってない人がちらほらいたこと。 理由はともあれ会場貸している側からの要望だしねえ。 ちょっと離れてたんでよくわからなかったけどなんか食ってるのもいたねえ (開場する前の入り口付近)。 あと「開放厳禁」の張り紙が貼ってある扉を開けようとしてた(たぶん)外国からの参加者がいたなあ。 まあこれはその「開放厳禁」が日本語でしか書かれてなかったからどうしようもないけど (こういうのも多言語化せんといかんのですかねえ)。 さすがに教えないとと思って近づこうとしたらすぐに諦めてたんでなにもしなかった。

今日はYAPC::Asia Tokyo 2013の1日目です - 北海道苫小牧市出身のPGが書くブログ この辺が印象強かった。→ 正規表現の文字集合の演算 Python的な局所サブルーチン → my sub Perl5.20 での新機能もなかなか。

今日はYAPC::Asia Tokyo 2013の1日目です - 北海道苫小牧市出身のPGが書くブログ Q. CGI.pmは消える? A. コアからは消えます

■_

チューリングの名前が書名にあるのでとりあえずちぇっく。

■_

Edward C++Hands : haskell Edward C++Hands |   Bartosz Milewski's Programming Cafe

Edward C++Hands |   Bartosz Milewski's Programming Cafe

Every programmer who’s serious about concurrency and parallelism should learn enough Haskell to understand how
it deals with it. There is an excellent book by Simon Marlow, Parallel and Concurrent Programming in Haskell.
After you read it, you will either start using functional techniques in your C++ programming, or realize what
an impedance mismatch there is between parallel programming and an imperative language, and you will switch to
Haskell.

挙げられている本はこれですね。 都内で読書会もやってたような。 Parallel and Concurrent Programming in Haskell: Techniques for Multicore and Multithreaded Programming

kindle 版はこちら Parallel and Concurrent Programming in Haskell: Techniques for Multicore and Multithreaded Programming
Parallel and Concurrent Programming in Haskell: Techniques for Multicore and Multithreaded Programming

■_

2013年09月19日

■_

ささださん結婚おめでとうございます。

前夜祭には参加せず。

○経○P、どんだけメール送ってくるんだw

メタプログラミング.NET ちょっと読んだ。 なるほど欄外の注に訳語について結構な分量でなぜそうしたかの説明が。

■_ Delphi

知らん間にこんな機能までついてたのか Reference Counting and Object Harvesting in Delphi | Dr Dobb's In the new compiler, the call to Free is replaced with the assignment of the variable to nil. In the case where this was the last reference to the object, the object is removed from memory after calling its destructor. If there are other standing references when Free is called, only the reference count is decremented.

■_

盛り上がってるのであとで読む(実は元記事ちょっと読んだ) If You're Programming a Cell Phone Like a Server You're Doing it Wrong : programming High Scalability - High Scalability - If You're Programming a Cell Phone Like a Server You're Doing it Wrong

■_ プログラムはこうして作られる

全然出版情報引っかからなかったんだけどなんでだ。 一昨日書泉ブックタワーで現物見かけた(買わなかったけど)。 プログラムはこうして作られる プログラマの頭の中をのぞいてみよう|書籍情報|秀和システム 世間一般のプログラム入門書には重大な欠陥があります。それはプログラムを自分で作るにはどのように頭を動かせばいいのかという根本の考え方を教えてくれないことです。 こういう切り口は良いと思うんですよね。

プログラムはこうして作られる プログラマの頭の中をのぞいてみ
プログラムはこうして作られる プログラマの頭の中をのぞいてみ

■_

■_

The Commodore 64 Spike — Code adventures — Medium

2013年09月18日

■_

あー明後日からかー(前夜祭はカウントせず) YAPC::Asia 2013 に参加される全ての皆さんへ、タイムスケジュールと注意事項 | Things You Should Know Before Coming To The Venue | YAPC::Asia Tokyo 2013

■_ P6

なにやら

Material from the Rakudo and NQP Internals course | 6guts

One aim of developing the course was to help with the state of documentation of the NQP and Rakudo internals.
Typically at Edument, we only give out our material to those attending a delivery of our courses, and even then
not the original source! However, for this course, we’ve made an exception and released the course material
under a Creative Commons license. So, while I hope that we’ll be able to put together future “live”
deliveries of the material for other new (or potential) contributors, this means it will now always be available
to the community at large. :-)

これかー edumentab/rakudo-and-nqp-internals-course

■_

■_

書いてる内容がないよう

■_

状況が断片的にしか分からないんだけど たぶん夜が明ける頃にはまた reddit とか HN でもりあがってんだろか。 ところで Ruby 以外のカンファレンスでこういう話題が出ることってあまりない?

2013年09月17日

■_

stack overflow が5周年とかなんとか Five years ago, Stack Overflow launched. Then, a miracle occurred. : programming Five years ago, Stack Overflow launched | Hacker News

■_

■_

まーとまらねー

2013年09月16日

■_

天候がアレなので昨日今日とほとんど外出してなかったんですが 積ん読の解消もあまり進んでなかったり。 論文も家だとなんか読む速度が上がらないんだよなー。

.NETでメタプログラミング - L'eclat des jours(2013-09-16) コミュニティによってブレ(日本語の訳語が複数あったりカタカナにしたり決定されていない)がある各種用語については初出の脚注で、 辞書的な意味やカタカナを使う場合と日本語を使う場合についての使い分けについて説明している (基本的にはカタカナを使っているが、翻訳書を読んでいる多くの読者は、そもそもそのカタカナが通じない可能性があるわけだから、 元の綴りと辞書的な意味を示すのは良いことなのだろう)。 へー、ちょっと読んでみよう。

今年も行[かけ]なかったなあ。 なんか見えない壁を感じるんだよなあ(意識しすぎです) PyCon JP Blog: PyCon APAC 2013 in Japan が開催されました

■_ 比較

例によって比べてみると面白い。 優秀すぎるスター開発者は会社にとって本当に必要なのか | スラッシュドット・ジャパン デベロッパー Ask Slashdot: Are 'Rock Star' Developers a Necessity? - Slashdot ところで 「Rock Star developer」を「(優秀すぎる)スター開発者」と訳すのはいいんだろかと 気になったり。

向こうのコメントの一つによれば

Ask Slashdot: Are 'Rock Star' Developers a Necessity? - Slashdot

From Urban Dictionary: Rock Star Programmer - A computer programmer with such strong skills and so much specific
experience that they are the equivalent of a rock star in the domain of software. Many people play guitar pretty
well, but only a few become rock stars. These programmers can develop more software than 5 - 10 newly hired
regular programmers because they know what needs to be done and how to do it. They also might set the
architecture of the product that dozens will build upon. Usually associated with dot com websites.

Usage: Jeff was the guy behind ebay.com He's a rockstar programmer.

Yes they exist, typically large IT organizations have a few of them just in case. Many are like the fictional TV
personality, House. If you can tolerate them, they are nice to have around for large, unsolvable problems that
need to be fixed now. Many can deduce, diagnose, analyze, and fix things before your standard programmers can
even formulate the problem. I have witnessed this on several occasions. If time is money, they are great
insurance but be prepared for arrogance. The one I formerly worked with brought his dog to work and forced a
fortune 500 company to give the dog a swipe badge. It was pretty hilarious.

わかったようなわからないような>後半

■_ Developers Voice on Mobile Application Scenarios

なんか見覚えあると思ったら Reality for Windows developers: Users want Android, iOS apps | Mobile development - InfoWorld The report was authored by Dimensional Research and sponsored by software development tools vendor Embarcadero Technologies. こいつと情報元は同じなのね → Developers Voice on Mobile Application Scenarios で、それに対する反応。 Reality for Windows developers: Users want Android, iOS apps | Mobile development : programming

■_ FILE_SHARE_DELETE

FILE_SHARE_DELETE ってなんだっけ? と調べてみると

CreateFile 関数

dwShareMode
    オブジェクトの共有方法を指定します。0 を指定すると、オブジェクトを共有できません。このハンドルを閉じない限り、それ以降にこのオブジェクトを開こうとしても失敗します。

    オブジェクトを共有するには、次の値のいずれかまたは任意の組み合わせを指定します。
    値	                意味
    FILE_SHARE_DELETE	Windows NT/2000:これ以降、オブジェクトを開こうとしたときに削除アクセスを要求した場合のみ、その操作を許可します。
    FILE_SHARE_READ	これ以降、オブジェクトを開こうとしたときに読み取りアクセスを要求した場合のみ、その操作を許可します。
    FILE_SHARE_WRITE	これ以降、オブジェクトを開こうとしたときに書き込みアクセスを要求した場合のみ、その操作を許可します。

オブジェクトを開こうとしたときに削除アクセスを要求 ってどゆこと? でさらに調べる

Use FILE_SHARE_DELETE in your shell extension | mg.to

Use FILE_SHARE_DELETE in your shell extension | mg.to

There's an easy way to fix this for Windows NT, 2000, and XP. In the CreateFile() call that opens the file, use
FILE_SHARE_READ | FILE_SHARE_DELETE in the dwShareMode parameter.

The MSDN documentation doesn't make it clear at all, but FILE_SHARE_DELETE works with MoveFile() in the same way
it does with DeleteFile(). In other words, it gives you Unix-style delete/rename semantics. Even while you have
the file open, Windows can delete it or rename it right out from under you, but you can keep reading it—your
handle to the file remains valid until you close it.

ああ、そういう。

しかしNT からあったとか全然記憶になかったわー

■_

lsを読まずにプログラマを名乗るな!|書籍情報|秀和システム この本結構話題になっているっぽい。昨日今日のついったでもよく見かけたし。 はてなブックマーク - lsを読まずにプログラマを名乗るな!|書籍情報|秀和システム

最近、各種OSのlsの実装比較した記事なかったっけかと思ったら echo の間違いだった。 UNIX V5, OpenBSD, Plan 9, FreeBSD, and GNU coreutils implementations of echo.c

■_ 補完

見かけたやり取り。

「原理主義」とはどういう意味でしょうか - お気軽Q&A [原理主義]の意味をわかりやすく教えてください。 | 国語のQ&A【OKWave】

■_

ひさびさの重箱の隅。

バーチャルパネル: 低レイテンシ環境でJavaを使う

Q2: Javaを使う利点として、豊富なライブラリ、フレームワーク、アプリケーションサーバなどへのアクセスや、使える
プログラマが多いことが挙げられます。こうした利点は低レイテンシコードにも当てはまるのでしょうか? もし当てはま
らないなら、C++よりも何か利点はあるのでしょうか?


    Thompson氏: Javaで書かれた低レイテンシシステムは、サードパーティ製ライブラリや、標準ライブラリすら使っていな
    いことが多いです。これには大きく2つの理由があります。1つは、多くのライブラリはパフォーマンスを考慮して書かれ
    ておらず、スループットや応答時間が不十分であるためです。もう1つは、並行動作にロックを使っていることが多く、
    大量のGCを引き起こすためです。ロックの競合とGCのために、応答時間はかなりばらついてしまいます。

    Javaは言語のなかでもツールのサポートがすぐれており、生産性を大きく高めてくれます。取引システムを構築する場合、
    市場に出すまでの時間が重要な要件であることが多く、Javaを使うことで開発期間を短縮することができるでしょう。

Virtual Panel: Using Java in Low Latency Environments

Thompson: Low latency systems written in Java tend to not use 3rd party or even standard libraries for two major
reasons.  Firstly, many libraries have not been written with performance in mind and often do not have
sufficient throughput or response time.  Secondly, they tend to use locks when concurrent, and they generate a
lot of garbage. Both of these contribute to highly variable response times, due to lock-contention and garbage
collection respectively.

Java has some of the best tooling support of any language which results in significant productivity gains.  Time
to market is often a key requirement when building trading systems, and Java can often get you there sooner. 

「大量のGCを引き起こす」って原文にはないと思うんだけど。 they generate a lot of garbage は (GCの対象となる)ごみを大量に作るのであって、 それによってGCがどのように起きるか(そりゃあゴミの量に比例はするでしょうけど)は書いてないんじゃないでしょか。

■_

Ken Thompson の regexp のつづき。 Implementing Regular Expressions にいろいろと。 ここ、前にも見てるはずなんだがなあ。

Implementing Regular Expressions

Ken Thompson, “Regular expression search algorithm,” Communications of the ACM 11(6) (June 1968), pp. 419–422.
http://doi.acm.org/10.1145/363347.363387 (PDF)

The first efficient regular expression search. Four pages but dense: every time I read it I learn something new.
Take an IBM 7094 cheat sheet with you. See also old slides from a lecture about the paper. 

一つめのが前に紹介したやつ。 んで、old slides のリンク先(上記引用ではリンクになってません)を見ると色々解説が。 あと IBM 7094 について。 こいつ Lisp が最初に実装された 709 と近いのね。道理でレジスター構成に見覚えが。 IBM 7094 Cheat Sheet んで、

IBM 7094 Cheat Sheet

ACL addr

add and carry logical word: AC <- AC + M[addr]

AXC addr, index

address to index complement: XR[index] <- 215 - addr
(note that addr, not M[addr], is being used.) 

いろいろな命令で、オペランドの complement を~ ってなってるんだけどなんでわざわざ complement とってるのかわからんちん。 add and carry ってのも add with carry とは違うんだよね。たぶん。 IBM 7090/94 Architecture Home Page IBM 709 - Wikipedia

■_

2013年09月15日

■_

実写版パトレイバー。 押井メルマガでちょっと話がでてきたんですが、25日になにやら発表のイベントがあるとか

折りたたみ傘。 デパートやらの傘袋に入れるのもサイズがあわないし、 傘立ても… ということで使用済みの折りたたみ傘はどうするのがよいのでしょー。 なんか「格納袋」つきの折りたたみ傘ってのをどこかで見かけた気がするのだけど

■_ Rust

文脈が気になる…

■_ 七つの

7 Ways More Methods Can Improve Your Program | Henrik Warne's blog

7 Ways More Methods Can Improve Your Program | Henrik Warne's blog

A lot of code I come across consists of relatively few, but long, methods. The code does what it is supposed to
do. However, it could be improved a lot. Refactoring to use more methods can produce better structured programs
that are easier to understand, easier to modify, easier to test and easier to debug. Below are 7 reasons why
using more methods can be a good idea.

七つの項目は以下の通り。詳しくは元記事。

  1. Hide Details
  2. Avoid Duplication
  3. Group Related Behavior
  4. Create “Funnels”
  5. Simplify Testing
  6. Simplify Logging and Debugging
  7. Self-Documenting Code

■_

■_

これ、もうちょっと面白い書き方できると思うんだけど面倒なのでやらない Ruby での日付のあらわし方について | RubyのQ&A【OKWave】

■_

この記事はすぐにでも訳されるかなあ Developers Voice on Mobile Application Scenarios

Developers Voice on Mobile Application Scenarios

Embarcadero Technologies in collaboration with Dimensional Research recently conducted a global survey
comprising of over 1300 Windows developers from around the world to measure their interest in the rapidly
changing mobile application development. These developers comprised of those who have experience in the
development of Windows based applications.

お、このパラグラフは

Developers Voice on Mobile Application Scenarios

I can't believe this but as per the tabulated survey results, nearly 83% of Windows developers prefer Android
platform and only 33% vouched for Windows Phone. Apple iOS was positioned at 67% and placed in the second spot.
While 14% of developers preferred blackberry, only 4% voted for other platforms such as Symbian. Nearly 83% of
developers preferred Android platform for the development of mobile apps for their users. The results have been
divided among those with and without mobile responsibility.

2013年09月14日

■_

三菱東京UFJ。 ATM (コンビニに設置のそれを含む) での現金引き出しや振り込みのときの料金改定 とかでお手紙が。 話には聞いてたけどずいぶんとまあ変わるのねえキツイ方に。

待ち行列。 某書店1Fのレジの順番待ちで、前に人が全然いない状態で会計始めたら(レジ自体はほぼ埋まってたけど) 終わる頃には待ち行列が結構な長さになっててびっくり。 ポアソン分布やら指数分布を使って…となるのは職業病w G/G/1型<待ち行列<オペレーションズ・リサーチ<Web教材<木暮

■_

■_

  .,,..,,,,_
/ ,’ 3  `ヽーっ
l   ⊃ ⌒_つ
`’ー—‐””’”  

2013年09月13日

■_

プログラマーの日 Programmers' Day - Wikipedia, the free encyclopedia

irb(main):012:0> Time.now.strftime("%j")
=> "256"

こっちの方がいいか

irb(main):022:0> Time.local(2013,9,13).strftime("%j")
=> "256"

■_ TIOBE INDEX

なんかこう、書き方がおとなしくなった? 9月プログラミング言語人気 | マイナビニュース とりあえず見出しだけ列挙。

C/Objective-C下がる - TIOBEプログラミング言語人気調査 [2013/8/9]
7月プログラミング言語人気 - PHP急上昇 [2013/7/9]
6月プログラミング言語人気 [2013/6/11]
C言語、人気継続で1位 - 5月プログラミング言語人気 [2013/5/10]
C言語、人気1位へ - 4月プログラミング言語人気 [2013/4/12]
Bashが急上昇 - 3月プログラミング言語人気 [2013/3/12]
Javaが首位に返り咲く - 2月プログラミング言語人気 [2013/2/13]
Objective-CがTIOBE人気言語アワードを受賞 - 1月プログラミング言語人気 [2013/1/10]
Cが1位を維持、Objective-Cの人気が続く - 12月プログラミング言語人気 [2012/12/7]
Objective-Cの勢い止まらず - 11月プログラミング言語 [2012/11/7]
上位は変わらず、Dartが初のトップ50入り - 10月プログラミング言語 [2012/10/10]
順位の変動は見られず - 9月プログラミング言語人気 [2012/9/12]
C#の下落が続く - 8月プログラミング言語人気 [2012/8/15]
Objective-CがC++を抜く - 7月プログラミング言語人気 [2012/7/10]
Visual BasicがPHPを抜く - 6月プログラミング言語人気 [2012/6/14]
CとObjective-Cが好調 - 5月プログラミング言語人気 [2012/5/11]
首位が交代、CがJavaを抜き1位に - 4月プログラミング言語人気 [2012/4/9]

まあ以前のは大げさすぎる感じがあったし

■_ Advanced UNIX Programming

インタビュー記事。 Advanced UNIX Programming: An Interview with Stephen Rago

Advanced UNIX Programming: An Interview with Stephen Rago

Advanced Programming in the UNIX Environment (APUE) is highly regarded as a solid reference for programming in
the UNIX-based environments. The book is designed to provide a comprehensive knowledge of programming in C for
the UNIX environment. Topics covered include file I/O, processes, signals, threads, interprocess communication,
and sockets among many others. For this edition of the book these concepts are discussed as they relate to
FreeBSD 8, Linux 3.2.0, OS X 10.6.8, and Solaris 10.

The 3rd edition of APUE was recently published and InfoQ had the opportunity to speak with author Stephen Rago
about his latest edition and UNIX development in general.


InfoQ: Given C’s historical relationship with UNIX, C is used for all of the examples. Do you see any viable
challengers on the horizon to this language? Is C good enough or do you think a newer language could improve
systems programming?

    Rago: C has sufficed for 40 years. I've worked at places that have used C++ as a "better" C because
    of the stronger type-checking it does, but the C++ language is so large and complex that using it is really
    a chore. I can write C programs without needing to constantly check some reference book to see how
    such-and-such a feature should be used; not so with C++. I prefer C because you can do both high-level and
    low-level things with one language, and the language specification is simple enough to keep in your head.
    Operating systems need to interact with hardware and provide features based on higher-level constructs, so C
    fits the bill nicely. And using the same language for systems programming that is used by the underling
    operating system makes life easier. I haven't had a chance to look at Go yet, but it's on my list of things
    to do, because it tries to address some of the software engineering problems with building large software
    projects in languages like C and C++.

これか。前の版も翻訳されてないよねえ。 Advanced Programming in the UNIX Environment (3rd Edition) (Addison-Wesley Professional Computing Series)
Advanced Programming in the UNIX Environment (3rd Edition) (Addison-Wesley Professional Computing Series) 前の版は買ったけど読み切らなかったなあ(そして人にあげた) Advanced Programming in the UNIX® Environment (Addison-Wesley Professional Computing Series)
Advanced Programming in the UNIX® Environment (Addison-Wesley Professional Computing Series)

Amazon に kindle版あるけど Includes EPUB, MOBI, and PDF だから電書ならこっちで買った方がよさげ。 Advanced Programming in the UNIX Environment, 3rd Edition | InformIT

■_ 改行のないファイル最終行のsedでの扱い

GNU sed でなぜああしてるという決定打はみつからなかったんだけど。 editors.sed.user - What should the "p" command do? - msg#00031 - Recent Discussion OSDir.com

editors.sed.user - What should the "p" command do? - msg#00031 - Recent Discussion OSDir.com

Folks,

I have recently had a problem with sed's p command and I'd be glad to
hear your thoughts about it.

The sed faq, section 5.10, and my reading of various books says:

Sed works like this: sed reads one line at a time, chops off the
terminating newline, puts what is left into the pattern space where
the sed script can address or change it, and when the pattern space
--------------------------
is printed, appends a newline to stdout (or to a file). If the
---------------------------------------
pattern space is entirely or partially deleted with 'd' or 'D', the
newline is *not* added in such cases.

I've underlined the part with which I have been having problems.

If I do something like this:

$ echo -e "abc\ndef\nghi" | sed -n p
abc
def
ghi

$

sed works as I expect and the last line of input is output from the
pattern space followed by a newline (my prompt supplies a newline
before the "$"). On my system the -e parameter to echo is required to
enable escapes and echo automatically supplies a trailing newline. All
well, or so I thought, but when I do:

$ echo -e "abc\ndef\nghi\c" | sed -n p
abc
def
ghi
$

In this example the "\c" suppresses echo's trailing newline and sed
_doesn't_ add a newline to the pattern space for the last line when it
is output.

$ sed --version
GNU sed version 4.0.7
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There
is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE, to the extent permitted by law.

$

This looks like a bug, or, at least, an inconsistency with the FAQ
pages, to me insofar as sed appears to remember whether the last line
of input was terminated by a newline and then use that information to
decide whether or not to add one when outputting the pattern space for
the last time, or am I way off beam?

In some of the man pages on various UNIX systems I note that it says
that the p command is defined as "Print. Copy the pattern space to the
standard output." without mentioning the addition of a newline to the
pattern space (Solaris and HP-UX both give this definition). GNU sed's
man page says this for the p command: "Print the current pattern
space."

Issuing the second of my attempts above on Solaris results in:

$ echo "abc\ndef\nghi\c" | sed -n p
abc
def
sed: Missing newline at end of file standard input.
ghi
$

and on HP-UX :

$ echo "abc\ndef\nghi\c" | sed -n p
abc
def
$

So the /usr/xpg4/bin/sed, which is the one I used on Solaris, and the
HP-UX /usr/bin/sed give different results when standard input isn't
terminated by a newline: Solaris complains, but processes the line, and
HP-UX simply ignores the last line! So much for Sun's and HP's claims
that their systems are POSIX compliant (they aren't even consistent so
how can they be compliant?)

Interestingly, I notice that the Open Group's Base Specifications at:

http://www.opengroup.org/onlinepubs/007904975/utilities/sed.html

says nothing about adding a newline to the pattern space as it is sent
to standard output. Its definition of the p command says: "Write the
pattern space to standard output."

I can see a reason for sed remembering whether the last input line was
terminated by a newline or not if it is to be used to copy one file to
another, otherwise the copy will contain something that differs from
the original, but then, who uses sed to make file copies anyway?

You may ask why I'm so interested in which is the correct
interpretation of how the p command works, well because I wrote some
code that assumes that the p command _does_ add a newline to the
pattern space when it prints it and it isn't working correctly on the
platforms where I need it to work. It looks as if I'll have to write
platform specific versions of the code (something that I am really
loath to do) and just add a newline to the pattern space by hand for
the last line where needed.

Thanks for your thoughts,

Peter
editors.sed.user - Re: What should the "p" command do? - msg#00032 - Recent Discussion OSDir.com

> This looks like a bug, or, at least, an inconsistency with the FAQ
> pages, to me insofar as sed appears to remember whether the last line
> of input was terminated by a newline and then use that information to
> decide whether or not to add one when outputting the pattern space for
> the last time, or am I way off beam?

I think this area is undefined. GNU sed's behavior is correct when you are
saying for
example

sed -n '5,15!p'

or

sed -n '/---/p'

But not for example when you are printing multiple copies of the same line with
p,
because then *no* newline is printed and you get defdef on the last line. :-(

> I can see a reason for sed remembering whether the last input line was
> terminated by a newline or not if it is to be used to copy one file to
> another, otherwise the copy will contain something that differs from
> the original, but then, who uses sed to make file copies anyway?

People use sed to extract parts of a file, though.

I found that a way to clear GNU sed's `suppress new line behavior' is

sed '$G; $s/\n//'

This would make the script portable between GNU sed and Solaris sed at least.

Paolo

■_

もうひとつ。

[PATCH] for review Re: Sed substitution bugs

On Wed, Jun 04, 2003 at 04:55:34PM +0100, Tony Finch wrote:
> Solaris:
> $ echo -n foo | sed y/o/O/
> sed: Missing newline at end of file standard input.
> fOO
> $
>
> GNU:
> $ echo -n foo | sed y/o/O/
> fOO$
>
> GNU is clearly the right implementation, and it's what the regression
> test says sed should do. I think sed should be fixed. (I can't do it
> right now because I'm going climbing.)

Your input is malformed. Making sed not store the newlines made it easier to fix a whole bunch of bugs, but
made it harder to deal with this kind of malformed input in the traditional (for BSD) way. See sed/process.c
rev. 1.21 and the PR's it mentions. Warning about missing newlines like Solaris sed does is probably a good
idea; I'll see if I can do that. But I don't consider following the traditional BSD behaviour of not adding
missing newlines to be a high priority.

Tim

結局 Your input is malformed. これをどうするかという話なんだよねえ。 POSIX的には行末には必ず改行があるわけで、 元から無いものをつけて出力して良いの? と。

■_

2013年09月12日

■_

自動販売機。ついったで見かけたんですが、 お金を先に入れてから希望の商品のボタンを押すというやり方は 良くないのではないか。欲しいものを先に選択しておいてからそれに必要な 金額を投入するようにした方が良いのではないかという主張。 確かに一理あるし、SUICA なんかで買うときはこういうパターンになりますよね (自販機にもよるんだろうけど)。 んでまあ、先にお金を入れて~ってのは、マイコンの類がなくて それほど複雑でない(よく知らないので要確認)、 機械的な機構だけでやってたころの事情がそうさせていたのかなあと思ったり。 そういやあ入社してすぐの研修で自動販売機の 大まかな状態遷移図を描かされたような覚えがががががw

■_ 独

ガラケーからiPhoneの国へ。ドコモの参入で、日本は世界でも類を見ないiPhone独裁国になる 「iPhone独裁国」ってどういう意味で使ってンだろうかと思いつつ本文を読むと 他にもいくつか気になる記述が かつては「ガラパゴス携帯」と言われるほどに諸外国とかけ離れた独自の携帯文化を築いてきた日本が、今度は世界でも類を見ないiPhone独占国家になろうとしています。 ここに日本トップのキャリアが参入するわけですから、下手をすると8割を超えるiPhone寡占市場が誕生することに。 以上の通り、日本はガラパゴス携帯の国から世界の中でも極端なiPhone寡占国家になることは間違いなさそうです。

…辞書をひいて、推敲した方が良くないっすかね。 どくさい【独裁】の意味 - 国語辞書 - goo辞書 どくせん【独占】の意味 - 国語辞書 - goo辞書 かせん【寡占】の意味 - 国語辞書 - goo辞書

■_ sed

シンボリックリンクなファイルに対して inplace-edit すると云々というやつ。

4.1.5 だとこうなってるのが

static void
open_next_file(name, input)
  const char *name;
  struct input *input;
{
  buffer.length = 0;

  if (name[0] == '-' && name[1] == '\0' && !in_place_extension)
    {
      clearerr(stdin);	/* clear any stale EOF indication */
      input->fp = stdin;
    }
  else if ( ! (input->fp = ck_fopen(name, "r", false)) )
    {
      const char *ptr = strerror(errno);
      fprintf(stderr, _("%s: can't read %s: %s\n"), myname, name, ptr);
      input->read_fn = read_always_fail; /* a redundancy */
      ++input->bad_count;
      return;
    }

  input->read_fn = read_file_line;

  if (in_place_extension)
    {
      int output_fd;
      char *tmpdir = ck_strdup(name), *p;
      struct stat st;

      /* get the base name */
      if (p = strrchr(tmpdir, '/'))
	*(p + 1) = 0;
      else
	strcpy(tmpdir, ".");
      
      input->in_file_name = name;

      if (isatty (fileno (input->fp)))
        panic(_("couldn't edit %s: is a terminal"), input->in_file_name);

      fstat (fileno (input->fp), &st);
      if (!S_ISREG (st.st_mode))
        panic(_("couldn't edit %s: not a regular file"), input->in_file_name);

      output_file.fp = ck_mkstemp (&input->out_file_name, tmpdir, "sed");
      output_file.missing_newline = false;
      free (tmpdir);

      if (!output_file.fp)
        panic(_("couldn't open temporary file %s: %s"), input->out_file_name, strerror(errno));

      output_fd = fileno (output_file.fp);
#ifdef HAVE_FCHMOD
      fchmod (output_fd, st.st_mode);
#endif
#ifdef HAVE_FCHOWN
      if (fchown (output_fd, st.st_uid, st.st_gid) == -1)
        fchown (output_fd, -1, st.st_gid);
#endif
    }
  else
    output_file.fp = stdout;
}


4.2 ではこう。 って diff とったほうが良かったな if (in_place_extension) のちょっとあとに if (follow_symlinks) が増えてます。

static void
open_next_file(name, input)
  const char *name;
  struct input *input;
{
  buffer.length = 0;

  if (name[0] == '-' && name[1] == '\0' && !in_place_extension)
    {
      clearerr(stdin);	/* clear any stale EOF indication */
      input->fp = ck_fdopen (fileno (stdin), "stdin", read_mode, false);
    }
  else if ( ! (input->fp = ck_fopen(name, read_mode, false)) )
    {
      const char *ptr = strerror(errno);
      fprintf(stderr, _("%s: can't read %s: %s\n"), myname, name, ptr);
      input->read_fn = read_always_fail; /* a redundancy */
      ++input->bad_count;
      return;
    }

  input->read_fn = read_file_line;

  if (in_place_extension)
    {
      int input_fd, output_fd;
      char *tmpdir, *p;
      struct stat st;

      if (follow_symlinks)
	input->in_file_name = follow_symlink (name);
      else
        input->in_file_name = name;

      /* get the base name */
      tmpdir = ck_strdup(input->in_file_name);
      if ((p = strrchr(tmpdir, '/')))
	*(p + 1) = 0;
      else
	strcpy(tmpdir, ".");

      if (isatty (fileno (input->fp)))
        panic(_("couldn't edit %s: is a terminal"), input->in_file_name);

      input_fd = fileno (input->fp);
      fstat (input_fd, &st);
      if (!S_ISREG (st.st_mode))
        panic(_("couldn't edit %s: not a regular file"), input->in_file_name);

      output_file.fp = ck_mkstemp (&input->out_file_name, tmpdir, "sed");
      output_file.missing_newline = false;
      free (tmpdir);

      if (!output_file.fp)
        panic(_("couldn't open temporary file %s: %s"), input->out_file_name, strerror(errno));

      output_fd = fileno (output_file.fp);
#ifdef HAVE_FCHOWN
      if (fchown (output_fd, st.st_uid, st.st_gid) == -1)
        fchown (output_fd, -1, st.st_gid);
#endif
      copy_acl (input->in_file_name, input_fd,
		input->out_file_name, output_fd,
		st.st_mode);
    }
  else
    output_file.fp = stdout;
}

follow_link はこういう関数(utils.c)

/* Follow symlink and panic if something fails.  Return the ultimate
   symlink target, stored in a temporary buffer that the caller should
   not free.  */
const char *
follow_symlink(const char *fname)
{
#ifdef ENABLE_FOLLOW_SYMLINKS
  static char *buf1, *buf2;
  static int buf_size;

  struct stat statbuf;
  const char *buf = fname, *c;
  int rc;

  if (buf_size == 0)
    {
      buf1 = ck_malloc (PATH_MAX + 1);
      buf2 = ck_malloc (PATH_MAX + 1);
      buf_size = PATH_MAX + 1;
    }

  while ((rc = lstat (buf, &statbuf)) == 0
         && (statbuf.st_mode & S_IFLNK) == S_IFLNK)
    {
      if (buf == buf2)
        {
          strcpy (buf1, buf2);
          buf = buf1;
        }

      while ((rc = readlink (buf, buf2, buf_size)) == buf_size)
        {
          buf_size *= 2;
          buf1 = ck_realloc (buf1, buf_size);
          buf2 = ck_realloc (buf2, buf_size);
        }
      if (rc < 0)
	panic (_("couldn't follow symlink %s: %s"), buf, strerror(errno));
      else
	buf2 [rc] = '\0';

      if (buf2[0] != '/' && (c = strrchr (buf, '/')) != NULL)
	{
	  /* Need to handle relative paths with care.  Reallocate buf1 and
	     buf2 to be big enough.  */
	  int len = c - buf + 1;
	  if (len + rc + 1 > buf_size)
	    {
	      buf_size = len + rc + 1;
	      buf1 = ck_realloc (buf1, buf_size);
	      buf2 = ck_realloc (buf2, buf_size);
	    }

	  /* Always store the new path in buf1.  */
	  if (buf != buf1)
            memcpy (buf1, buf, len);

          /* Tack the relative symlink at the end of buf1.  */
          memcpy (buf1 + len, buf2, rc + 1);
	  buf = buf1;
	}
      else
	{
	  /* Use buf2 as the buffer, it saves a strcpy if it is not pointing to
	     another link.  It works for absolute symlinks, and as long as
	     symlinks do not leave the current directory.  */
	   buf = buf2;
	}
    }

  if (rc < 0)
    panic (_("cannot stat %s: %s"), buf, strerror(errno));

  return buf;
#else
  return fname;
#endif /* ENABLE_FOLLOW_SYMLINKS */
}

■_

2013年09月11日

■_

某社の食堂での話なんですが…いややっぱ止めておこう。

kindle にちくま学芸文庫あったのか。 でも顔ぶれ見るとこう… Amazon.co.jp: ちくま学芸文庫: Kindleストア

■_ code reviewing

これ面白かったです。 コードレビューについてはあと一つ二つ抱えているものがあったはずだけどどこ行った The Art of Reviewing Code

■_ backlash

パラメトロン計算機: 微分解析機 バックラッシュ懐かしいw むかーしやってた仕事で モーターを動かして歯車まわして… という制御を行う部分があったのだけど、 あれも停止状態から順方向にちょっと動かす→逆方向にちょっと戻す→順方向に本格的に動かす。 みたいにやってたんだよな。 最初はメカの都合とか一切考えないで(というかそんな余裕なかったw)プログラム書いちゃったりして 色々苦労した覚えがw いやまあベースになるプログラムもちゃんとあったんですけどね (さすがにゼロから書かされることはなかった)。

■_

■_

かくたにさんとわださんのトークイベントはまだ申し込めるのかしらん


一つ前へ 2013年8月(上旬)
一つ後へ 2013年8月(下旬)

ホームへ


リンクはご自由にどうぞ

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