ときどきの雑記帖'

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

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

ホームへ

2013年10月10日

■_

moleskin のノート新調。

1010 ということで銭湯へ。

あら割と近くだ。 活版印刷と三軒茶屋の夫婦の物語 - デイリーポータルZ:@nifty

昨今日本でよく見かけるのとは違う意味で 「eat in」というイディオムがあるのを知って驚く (どんな意味かは各自で調べること :)

■_

■_

「GNUは衰退しました」「自由都市としてのフリーソフトウェア」、あるいは「『ハッカーはクラッカーじゃない。』の30年」──GNUについて知るワークショップ | サイボウズ式 岸田さんの講演資料が面白かった。なるほどねえ。

2013年10月09日

■_

半袖をもう一度引っ張り出す

そういえば孔明が退場>しばちゅーさん

■_

■_ なんだろうこのもやもや感

GNU Make 4.0 released : programming 本を読む GNU make 4.0で組み込みScheme

GNU Make 4.0 released

Some new features available in this release of GNU Make:

* New feature: GNU Guile integration
This version of GNU make can be compiled with GNU Guile integration.
GNU Guile serves as an embedded extension language for make.
See the "Guile Function" section in the GNU Make manual for details.
Currently GNU Guile 1.8 and 2.0+ are supported.

■_

色々ダメ。

2013年10月08日

■_

ちょっと前についったで言及しているのを見かけたんですが、 ギガビット対応のバカハブ(リピータハブ)なんてあるんですか! ギガビット バカハブ - Google 検索

こんなん見つけた。 日本語で書かれた論文ではこういう方向のは見たことないんだよなあ。 大抵「本論文の手法を用いれば云々」てな感じで。 Assessment of Distribution Based SRGM with the Effect of Change-Point and Imperfect Debugging Incorporating Irregular Fluctuations – Ompal Singh, Adarsh Anand, Jagvinder Singh and P.K. Kapur | Natthan Lal Sevarth Samiti

■_ GNU APL

include 部分をみるとですね

Complex.cc で

#include "ComplexCell.hh"
#include "Error.hh"
#include "FloatCell.hh"
#include "IntCell.hh"
#include "Output.hh"
#include "Value.hh"
#include "Workspace.hh"

FloatCell.cc で

#include "ComplexCell.hh"
#include "Error.hh"
#include "FloatCell.hh"
#include "IntCell.hh"
#include "UTF8_string.hh"
#include "Value.hh"
#include "Workspace.hh"

IntCell で

#include "Value.hh"
#include "Error.hh"
#include "PointerCell.hh"
#include "ComplexCell.hh"
#include "FloatCell.hh"
#include "IntCell.hh"
#include "Workspace.hh"

のように、他の *Cell.hh を include してるんですが これってどうにかならんのですかね。 いやまあコード部分を見ると、それらのクラスの定義をわかってないといけないような記述なんですけど。

こういうのとか

bool
FloatCell::greater(const Cell * other, bool ascending) const
{
const APL_Float this_val  = get_real_value();

   switch(other->get_cell_type())
      {
        case CT_NONE:
        case CT_BASE:
             Assert(0);

        case CT_CHAR:
             {
               const Unicode other_val = other->get_char_value();
               if (this_val == other_val)   return !ascending;
               return this_val > other_val ? ascending : !ascending;
             }

        case CT_INT:
             {
               const APL_Integer other_val = other->get_int_value();
               if (this_val == other_val)   return !ascending;
               return this_val > other_val ? ascending : !ascending;
             }

        case CT_FLOAT:
             {
               const APL_Float other_val = other->get_real_value();
               if (this_val == other_val)   return this > other;
               return this_val > other_val ? ascending : !ascending;
             }

        case CT_COMPLEX:
        case CT_POINTER:
             DOMAIN_ERROR;

        default:
           Assert(0);
      }
}

なんかこうもうちょういなんとかならんのかと。

■_ Tessel

/. でも取りあげられてた(8月) JavaScriptでプログラミングできる小型マイコン | スラッシュドット・ジャパン デベロッパー

コメント#2445974 | JavaScriptでプログラミングできる小型マイコン | スラッシュドット・ジャパン

MMU付きのCPUで最初からキーボードやディスプレイが接続できる Raspberry Pi より下で
8bit CPU の Arduino より上、JavaScriptでプログラミングできることが最大の売り。
確かに「キワモノ」と呼ぶのがぴったりですね。

インタプリタで動くコントローラって古くはIntelの i8051に BASICを載せたi8052 など、
一部で話題にはなっても、実物が流行ったことは無いように思います。

アマチュア向けのハードウェア開発環境が充実するのは嬉しいのですが、徒花ばかり
目立つようになると、本当の成熟に至る前にアタリショック的な衰退に陥るのではないか
と個人的には少し危惧しています。

知らなかった>i8052 MCS51 SBC: Yoshiのブログ i8052 datasheet & application note - Datasheet Archive

■_

C++11 の正規表現ライブラリの曖昧さ

■_

2013年10月07日

■_

あらかた半袖のものは片付けてしまったのになんだこの陽気。

■_ InfoQ

今日のオススメ :) Growing C++ Software Guided by Tests Effective GoF Patterns with C++11 and Boost

■_ classic

What Every Computer Scientist Should Know About Floating-Point Arithmetic でまあ知ってる人は知ってるアレなんですが

What every programmer should know about memory, Part 1 : programming

All time classic, here's full pdf: http://people.redhat.com/drepper/cpumemory.pdf

Someone should post "what every computer scientist should know about floating-point arithmetic" so I can
read about all the people that have been software craftsmen their entire lives and have never needed to know
what a floating point number is.


Is that information still up to date?


Pretty close. All consumer systems have now adopted integrated memory controllers (exemplified in the article by
Intel's then-new Nehalem architecture, and AMD's Opterons), so the stuff about FSBs is now only of historical
interest. FB-DIMMs didn't work out, the upcoming DDR4 isn't covered, and DDR3 clock speeds went a bit further
than predicted (and server-class processors actually did implement quad-channel DDR3). Other than that, part 1
is all still relevant. The later parts are much less hardware-specific, and are pretty much all still relevant.
Transactional memory as described in part 8 ("Future technologies") is now available on some Intel
Haswell processors.

確かに繰り返し流されるのは大事かも。 そういや 浮動小数点~ を取りあげたのも見かけたけどどこだー。 アレって、原文はOracleのドメインに移ってますけど 日本語訳はどうなってんすかね。

■_ GNU APL

めも。

Cell.cc
Cell.hh
CharCell.cc
CharCell.hh
ComplexCell.cc
ComplexCell.hh
FloatCell.cc
FloatCell.hh
IntCell.cc
IntCell.hh
LvalCell.cc
LvalCell.hh
NumericCell.cc
NumericCell.hh
PointerCell.cc
PointerCell.hh
RealCell.cc
RealCell.hh
         +---- CharCell 
         |
 Cell ---+                                +-- FloatCell
         |                                |
         |                  +--- RealCell +
         |                  |             |
         |                  |             +-- IntCell
         +---- NumberCell --+
         |                  |
         |                  |
         |                  +--- ComplexCell
         |
         +---- PointerCell
         |
         |
         +---- LVarCell

数値のCellの継承構造がなんとなく気になる。

■_

しかしこの手の作りのページはなんとかならんものか。 10 programming languages to make a developer pull his or her hair out - Network World

10 programming languages to make a developer pull his or her hair out : programming

I fucking hate these sites that put ten little tiny bits of text on ten pages.


They won't die, they just won't die. My total visit time was around 500ms.


I took a look at the page source and between the plethora of advertiser js crapfest was the JSON description of
the presentation.

I took the liberty of skimming through it and extracting the essentials:

    Python has significant indentation, too many colons and underscores and module variable name collision.
    Avoid Google, Yahoo and NASA.

    LabVIEW is too abstracted and programming graphically is hard. Hide your kids from Lego Mindstorms.

    JavaScript is case sensitive (OMG!) and we imagine it's inconsistent between browsers and impossible to
    debug. Also, we're too stupid to understand prototypical inheritance and the this keyword. Don't be a web
    developer.

    Tcl: There's no pointers, so we can't imagine there is a way to pass by reference. Arrays are strings and
    variable scope is confusing. Don't work for Cisco, AOL or CNET.

    COBOL: Here's a link to another article where we parallelled COBOL with Star Trek. Because it needs a new
    generation, geddit?

    C++: Too many features! You can even switch between OOP and procedural code. Don't go work for these two
    randomly selected companies or the gaming industry.

    PHP has no native support for Unicode, plus you end up mixing code and presentation (Editor's note: this is
    totally unlike all the other programming languages). "If you do any web-based work it's hard to avoid" (direct quote)

    Java is slow and verbose. "Lots of other languages can do what it does, but more efficiently"
    (Editor's note: I suppose that's why it is used so little). To avoid it stay away from the Android SDK.
    Yeah, that's the ticket.

    Perl is write-only code (Ed. note: well, can't argue with that). To avoid it don't become a programmer
    (because apparently all programmers are force-fed Perl).

    Visual Basic has cryptic syntax. I can't read it. Stay away from Windows applications before 2008.

COBOL や VB、Java に対して「冗長 (verbose)」だって文句がつけられてますけど それ自体は否定しない(できない)として、 あんまり「簡潔」なのもそれはそれで問題になるわけで、 「良い感じ」ってのはどの辺りにあるんでしょうねえ。

もうひとつ、COBOL のプログラムで Add Sale-Qty-Sold TO Cust-Qty-Sold, Total-Qty-Sold みたいなのがありますけど、こんなんありましたっけ? これどういう操作なんだろう… カンマの意味がわからん。

■_ Lua で

某氏によると「Lua来る」らしいので。 a pure Lua JVM: a pure Lua JVM

a pure Lua JVM: a pure Lua JVM

luje is an experimental (read: toy) Java virtual machine written in pure Lua. It works by compiling Java
bytecode into Lua scripts on-the-fly and then running them using Mike Pall's LuaJIT 2. The result is an
extremely fast but incredibly lightweight Java virtual machine which can outperform Sun's Hotspot in some
situations. 

Lua で JVM…動機が知りたい。

■_

JavaScript でごにょごにょできる arduino みたいなヤツというのはちょっと前に話を見かけたんですが こいつだったんですね。 なんというか時代は変わったなー(老害発言) Tessel: The End of Web Development (as we know it) 面白言っちゃ面白いですが。

Technical Machine JavaScriptが動くハードウェア「Tessel」 | ソフトアンテナブログ 次世代マイコン「Tessel」はJavaScriptとNode.jsをサポートしWi-Fiからアップデート可能 - GIGAZINE

■_

2013年10月06日

■_

某所にお出かけ

■_ The Joy of Ruby, the Power of Erlang (Dave Thomas)

う、これは見たい(聞きたい)でござるよショーちゃん(誰) Rakuten Technology Conference 2013: Osaka Satellite やります! #rakutentech - Mitsuyuki.Shiiba 12:00-12:45 [TrackA] Elixir: The Joy of Ruby, the Power of Erlang (Dave Thomas)

■_ What Every Hipster Should Know About Functional Programming

とりあえずスライドだけでも見たいんだけど扱いにくいったらありゃしない (印刷できると楽なんだけどなあ…仕事の合間に読みやすいからw) What Every Hipster Should Know About Functional Programming : programming What Every Hipster Should Know About Functional Programming by Bodil Stokke on Vimeo What Every Hipster Should Know About Functional Programming

■_ GNU APL を読む sigaction

再度 main.cc

コードは以下のようになっています。


static struct sigaction old_control_C_action;
static struct sigaction new_control_C_action = { control_C, 0, 0, 0, 0 };

//-----------------------------------------------------------------------------
static void
seg_fault(int)
{
   do_Assert(0, "SEGMENTATION FAULT ", 0, 0);
   CERR << "\n\n====================================================\n";
   Command::cmd_OFF(3);
}

static struct sigaction old_segfault_action;
static struct sigaction new_segfault_action = { seg_fault, 0, 0, 0, 0 };

//-----------------------------------------------------------------------------
static void
signal_USR1_handler(int)
{
   CERR << "Got signal USR1" << endl;
}

static struct sigaction old_USR1_action;
static struct sigaction new_USR1_action = { signal_USR1_handler, 0, 0, 0, 0 };

   sigaction(SIGINT,  &new_control_C_action, &old_control_C_action);
   sigaction(SIGUSR1, &new_USR1_action,      &old_USR1_action);
// sigaction(SIGSEGV, &new_segfault_action,  &old_segfault_action);

んで、sigaction を調べると

Man page of SIGACTION

sigaction() システムコールは、特定のシグナルを受信した際の プロセスの動作を変更するのに使用される (シグナルの
概要については signal(7) を参照)。

signum には、 SIGKILL と SIGSTOP 以外の有効なシグナルをどれでも指定できる。

act が NULL 以外であれば、シグナル signum の新しい動作 (action) として act が設定される。 oldact が NULL でな
ければ、今までの動作が oldact に格納される。

sigaction 構造体は以下のような感じに定義される。

struct sigaction {
    void     (*sa_handler)(int);
    void     (*sa_sigaction)(int, siginfo_t *, void *);
    sigset_t   sa_mask;
    int        sa_flags;
    void     (*sa_restorer)(void);
};

アーキテクチャによっては共用体 (union) が用いられており、その場合には sa_handler と sa_sigaction の両方を同時に
割り当てることはできない。 

改めてコードでの変数定義とつきあわせるとこう。

  static struct sigaction new_USR1_action = {
      signal_USR1_handler,  ← sa_handler
      0,                    ← sa_sigaction
      0,                    ← sa_mask
      0,                    ← sa_flags
      0                     ← sa_restorer
  };

さてここで OS X。

sigaction(2) Mac OS X Developer Tools Manual Page

 struct sigaction {
        union __sigaction_u __sigaction_u; /* signal handler */
        sigset_t sa_mask;                  /* signal mask to apply */
        int sa_flags;                      /* see signal options below */
 };

 union __sigaction_u {
        void    (*__sa_handler)(int);
        void    (*__sa_sigaction)(int, struct __siginfo *, void *);
 };

まさにアーキテクチャによっては共用体 (union) が用いられており に該当してるわけですね。

Questions about catching Unix signals - Stack Overflow

■_

2013年10月05日

■_

ここ何日か elastic search なる言葉を良く見かける。なんじゃろこれ。

プログラマーのための数学勉強会。プログラマの為の数学勉強会 第4回 - PARTAKE 時間的やら場所的がネックで参加できないのだけど、 いちおー発表スライドは追いかけてる…んだけど 第4回に入っていくつかわからんところがあるんだけど聞けるような人がいねーなー (twitter経由などはなしで)。 例示された式の変形の途中がわからんとかだから本やら見て調べられないのよねー これまでのスライドはこちら→ プログラマの為の数学勉強会

時計。切れたベルトを修理。525円也。

北海道物産展。とある用事を片付けたあとで近くのデパートでやってたので行ってみたが人ごみに負けた

for dummies シリーズにビッグデータを題材にしたのがあってびっくりぎょーてん。 Big Data For Dummies

Manning Publications Co. から宣伝メールが来たんですが

Data Science! + 45% off selected books - hogemuta@gmail.com - Gmail

Mastering the formal academic discipline of data science can involve years of study in sophisticated mathematics,
complex pattern recognition, machine learning, uncertainty modeling, and other esoterica. For most of us
non-academics, though, it's the practical task of extracting relevant, useful information from the sea of data
generated by businesses, governments, and people. These Manning books will help you combine the programming
skills you already have with the growing number of tools and technologies that make practical data science less
daunting.

(略)

Languages

As a developer, programming languages are your bread and butter. Established languages like Python and Ruby,
along with their numerous high-quality libraries, have emerged as low-overhead ways to tackle data analysis
tasks. Functional programming languages like Scala and Clojure provide a closer match between your code and
data, and offer a scalable coding paradigm for data science.

    The Quick Python Book » pBook, PDF, ePub, and Kindle
    Hello! Python » pBook, PDF, ePub, and Kindle
    The Well-Grounded Rubyist, Second edition » MEAP
    Scala in Action » pBook, PDF, ePub, and Kindle
    Scala in Depth » MEAP
    Clojure in Action, Second Edition » MEAP
    The Joy of Clojure, Second Edition » MEAP
    Functional Programming with Scala » MEAP

your bread and butter なんて表現あるんですねえ。

■_ C の入門書

ただし洋書 :) なんかこれも最近出ていたものらしい。 C Programming Absolute Beginner's Guide (3rd Edition)

■_ quick select

某スレ。

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

440 デフォルトの名無しさん [sage] 2013/10/04(金) 18:16:39.31 ID: Be:
    要素が20~30個のデータに対して
    高速なソートアルゴリズムの名前を教えてください。

    78K0Rという16bit CPUを13.5MHzで動かしていますが
    中央値を求めるために4ms以下にしたいです。

    バブルソートにしたら8ms以上かかってしまいました。

    データは
    struct{ int x, y; } v1, v2;
    比較式は
    (long)v1.y * v2.x < (long)v2.y * v1.x

    intは2バイト、データはint x, y;
    ポインタは4バイトです。 

442 デフォルトの名無しさん [sage] 2013/10/04(金) 18:32:21.47 ID: Be:
    >>440
    ソートは自前で実装してる?
    inline化するとか、変数をregisterに割り付けるとか、どうだろうか 

443 デフォルトの名無しさん [sage] 2013/10/04(金) 18:32:36.65 ID: Be:
    >>440
    それって
    A>B かつ B>C のときに A>C が成り立たないから
    ソート結果に意味がなさそうな気がする 

444 デフォルトの名無しさん [sage] 2013/10/04(金) 18:53:29.95 ID: Be:
    ごめん
    >>443 は勘違い 

445 440 [sage] 2013/10/04(金) 19:03:02.79 ID: Be:
    みなさんありがとうございます。

    >>441
    クイックソートでしょうか。
    とりあえず、探してきます。

    >>442
    自前です。ライブラリは使えません。
    比較式はソート関数内に直接書いています。
    registerも使ってみます。カウンタに使えば良いでしょうか?

    >>443
    条件を書き忘れてました。すいません。
    データの範囲は0≦xです。
    もとは以下の式です。
    v1.y / v1.x < v2.y / v2.x (実数として) 
    傾きの大きさを比較します。 

446 デフォルトの名無しさん [sage] 2013/10/04(金) 19:08:57.14 ID: Be:
    >>445
    コムソートがお手軽で省メモリ 

447 デフォルトの名無しさん [sage] 2013/10/04(金) 19:55:45.67 ID: Be:
    >>445
    inlineっつうのは、C89ならマクロ関数で書くってことだ
    展開されたアセンブリコード見て、サイクル数足していけばそれが本当に出来るか分かるんじゃないかね 

448 デフォルトの名無しさん [sage] 2013/10/04(金) 20:00:30.18 ID: Be:
    シェルソートもあるよ 

455 440 [sage] 2013/10/04(金) 21:31:32.67 ID: Be:
    >>446 >>448
    コムソートとシェルソート使えそうなので試してみます。

    >>447
    マクロ関数というのが使えるか調べてみます。

    みなさん、ありがとうございます。 

457 ◆QZaw55cn4c [sage] 2013/10/04(金) 21:57:04.75 ID: Be:
    >>455
    http://toro.2ch.net/test/read.cgi/tech/1313183984/425 にコムソートを書いておきましたリストのソートにも適用しやすいのがよいところ
    しかし高々20~30なら選択ソートや挿入ソートも検討の余地があると 

458 ◆QZaw55cn4c [sage] 2013/10/04(金) 21:58:31.13 ID: Be:
    半分おわったところで打ち切っていいしね 

460 デフォルトの名無しさん [sage] 2013/10/05(土) 08:18:13.20 ID: Be:
    >>440

    > (long)v1.y * v2.x < (long)v2.y * v1.x
    意味不明
    > (long)v1.y * v1.x < (long)v2.y * v2.x
    ならわかるが。
    こういう事ならソートする前に積を計算しとけ。
    中央値を求めるならば全部ソートする必要はなくて、クイックセレクトと呼ばれるアルゴリズムが存在する。

    こんなのに喜々として公開オナニーを見せつけるゴミクズはいつまで生きているんだろう。
    とっとと死ねばいいのに。 

463 ◆QZaw55cn4c [sage] 2013/10/05(土) 09:32:36.11 ID: Be:
    >>460
    >クイックセレクト
    thx4 keywords これはいいね 

466 デフォルトの名無しさん [sage] 2013/10/05(土) 10:55:54.49 ID: Be:
    >>445
    >比較式はソート関数内に直接書いています。

    ソート関数にしないで、main内に比較式を書く。 

468 デフォルトの名無しさん [sage] 2013/10/05(土) 11:12:32.98 ID: Be:
    >>466
    コールとリターンで9サイクル浮くな
    0.7usくらいか 

469 440 [sage] 2013/10/05(土) 12:12:25.76 ID: Be:
    コムソートとシェルソートを試して、5msくらいになりました。

    >>457 >>458
    charやintのインデックスのソートに置き換えてみましたが、
    インデックス構築とアドレス演算のコストがバカにならないらしく
    遅くなってしまいましたのでリストも使えなそうです。

    あとは、代入回数を減らすとか、そういう最適化になりそうです。

    ありがとうございました。 

487 デフォルトの名無しさん [sage] 2013/10/05(土) 22:18:19.91 ID: Be:
    >>440>>445
    > v1.y / v1.x < v2.y / v2.x (実数として) 

    比較関数で毎回この計算していたら遅くなるね。
    最初に20~30個の y / x を求めて、それに対してソートすれば
    ずいぶん早くなるんじゃないの。 

488 デフォルトの名無しさん [sage] 2013/10/05(土) 22:20:33.20 ID: Be:
    >>445
    > データの範囲は0≦xです。
    > v1.y / v1.x < v2.y / v2.x (実数として) 

    x == 0.0 の時もあるのか… 

490 デフォルトの名無しさん [sage] 2013/10/05(土) 22:51:13.59 ID: Be:
    >>487
    割り算入れたくないんだろ 

491 487 [sage] 2013/10/05(土) 22:57:40.84 ID: Be:
    >>490
    ああ、そうか。
    > v1.y / v1.x < v2.y / v2.x (実数として) 
    を計算するわけじゃないね。
    俺の書き込みは見なかったことにしてください。 


なんかタイミングよく reddit にこういうのが。 The quickselect algorithm is now available as a task on the Rosetta Code site. : programming Quickselect algorithm - Rosetta Code

リンク先を見たらサンプルプログラムがいくつかの言語で書かれている中に Perl 6 があったので大笑い。

Quickselect algorithm - Rosetta Code

my @v = <9 8 7 6 5 0 1 2 3 4>;
say map { select(@v, $_) }, 1 .. 10;

sub partition(@vector, $left, $right, $pivot-index) {
    my $pivot-value = @vector[$pivot-index];
    @vector[$pivot-index, $right] = @vector[$right, $pivot-index];
    my $store-index = $left;
    for $left ..^ $right -> $i {
        if @vector[$i] < $pivot-value {
            @vector[$store-index, $i] = @vector[$i, $store-index];
            $store-index++;
        }
    }
    @vector[$right, $store-index] = @vector[$store-index, $right];
    return $store-index;
}

sub select( @vector where +@vector,
    $k is copy where $k > 0,
    $left is copy where (0 <= $left <= @vector) = 0,
    $right is copy where ($left <= $right <= @vector) = @vector.end ) {

    loop {
        my $pivot-index = ($left..$right).pick;
        my $pivot-new-index = partition(@vector, $left, $right, $pivot-index);
        my $pivot-dist = $pivot-new-index - $left + 1;
        given $pivot-dist <=> $k {
            when Same {
                return @vector[$pivot-new-index];
            }
            when Decrease {
                $right = $pivot-new-index - 1;
            }
            when Increase {
                $k -= $pivot-dist;
                $left = $pivot-new-index + 1;
            }
        }
    }
}

select の引数のところの書き方が見慣れない書式だけどなんだろこれ (最近まともに追いかけてないからなあ)。 is やら copy やらはなんか見覚えあるけど where ねえ。

■_

2013年10月04日

■_

ぐはっ。気づくのが遅かったーーーっ NHK オックスフォード白熱教室 MIT~のあとは今ひとつ興味をひかないのが続いていたので油断してた○| ̄|_

で、MIT白熱教室(だけじゃないけど)のDVDが出ていたのにも気がついた NHK DVD MIT白熱教室 DVD BOX
NHK DVD MIT白熱教室 DVD BOX

BOX だけでなく、単体も。 NHK DVD MIT白熱教室 DVD1 NHK DVD MIT白熱教室 DVD2 NHK DVD MIT白熱教室 DVD3 NHK DVD MIT白熱教室 DVD4

Hacker News RSS から自分好みのものを抜き出してくれるのないかいな (人気がないのでも面白いのがあるから困っちゃうのよねえ)

■_ GNU APL を読む

Cell.cc

//-----------------------------------------------------------------------------
void *
Cell::operator new(std::size_t s, void * pos)
{
   return pos;
}
//-----------------------------------------------------------------------------
void
Cell::init(const Cell & other)
{
   switch(other.get_cell_type())
      {
        case CT_NONE:
        case CT_BASE:
             Assert(0);

        case CT_CHAR:
             new (this) CharCell(other.get_char_value());
             return;

        case CT_INT:
             new (this) IntCell(other.get_int_value());
             return;

        case CT_FLOAT:
             new (this) FloatCell(other.get_real_value());
             return;

        case CT_COMPLEX:
             new (this) ComplexCell(other.get_complex_value());
             return;

        case CT_POINTER:
             {
               Value_P Z = other.get_pointer_value()->clone(LOC);

               new (this) PointerCell(Z);
             }
             return;

        case CT_CELLREF:
             new (this) LvalCell(other.get_lval_value());
             return;

      }

   Assert(0 && "Bad cell type");
}

この switch はどうにかならんもんですかねえ。 Delphi だときれいに書けたんだっけか。

■_

2013年10月03日

■_

晩飯食ったあと日付が変わる辺りまで寝てしまったという…

■_

What Is the Best Way for a Programmer to Learn a New Language? | InformIT

■_

興味深い? やりとり。 「ブラック企業」はIT企業が発祥? : メカAG 作り変えられていく歴史 - 酔狂人の異説 作り変えられていく歴史(2) - 酔狂人の異説 作り変えられていく歴史(3) - 酔狂人の異説 作り変えられていく歴史(4) - 酔狂人の異説

■_ GNU APL を読む

main.cc


APL_time interrupt_when = 0;
bool interrupt_raised = false;
bool attention_raised = false;

static void
control_C(int)
{
APL_time when = now();
   attention_raised = true;
   if ((when - interrupt_when) < 500000)   // second ^C within 500 ms
      {
        interrupt_raised = true;
      }

   interrupt_when = when;
}

static struct sigaction old_control_C_action;
static struct sigaction new_control_C_action = { control_C, 0, 0, 0, 0 };

//-----------------------------------------------------------------------------
static void
seg_fault(int)
{
   do_Assert(0, "SEGMENTATION FAULT ", 0, 0);
   CERR << "\n\n====================================================\n";
   Command::cmd_OFF(3);
}

static struct sigaction old_segfault_action;
static struct sigaction new_segfault_action = { seg_fault, 0, 0, 0, 0 };

//-----------------------------------------------------------------------------
static void
signal_USR1_handler(int)
{
   CERR << "Got signal USR1" << endl;
}

static struct sigaction old_USR1_action;
static struct sigaction new_USR1_action = { signal_USR1_handler, 0, 0, 0, 0 };

んー、Windows に持ってくときはこの辺どうすっかねえ

static char APL_bin_path[PATH_MAX + 1] = "";
const char * get_APL_bin_path()   { return APL_bin_path; }

static void
set_APL_bin_path(const char * argv0)
{
   if (strchr(argv0, '/') == 0)
      {
         // if argv0 contains no / then realpath() seems to prepend the current
         // directory to argv0 (which is wrong since argv0 may be in $PATH).
         //
         // we fix this by searching argv0 in $PATH
         //
         const char * path = getenv("PATH");   // must NOT be modified
         
         if (path)
            {
              const size_t alen = strlen(argv0);
              const size_t plen = strlen(path);
              char path1[plen + 1];
              strncpy(path1, path, sizeof(path1));
              char * next = path1;
              for (;;)
                  {
                    char * semi = strchr(next, ':');
                    if (semi)   *semi = 0;
                    char filename[plen + alen + 10];
                    snprintf(filename, sizeof(filename), "%s/%s",
                             next, argv0);

                    if (access(filename, X_OK) == 0)
                       {
                         strncpy(APL_bin_path, next, sizeof(APL_bin_path));
                         return;
                       }

                    if (semi == 0)   break;
                    next = semi + 1;
                  }
            }
      }

const void * unused = realpath(argv0, APL_bin_path);
   APL_bin_path[PATH_MAX] = 0;
char * slash =   strrchr(APL_bin_path, '/');
   if (slash)   *slash = 0;

   // if we have a PWD and it is a prefix of APL_bin_path then replace PWD
   // by './'
   //
const char * PWD = getenv("PWD");
   if (PWD)   // we have a pwd
      {
        const int PWD_len = strlen(PWD);
        if (!strncmp(PWD, APL_bin_path, PWD_len) && PWD_len > 1)
           {
             strcpy(APL_bin_path + 1, APL_bin_path + PWD_len);
             APL_bin_path[0] = '.';
           }
      }
}

ポインターのアスタリスクの両側に空白置くってのはめずらしいなあ。 しかし char * semi = strchr(next, ':'); なぜ「semi」。コロン探してるのに。 strcpy は使わずに strncpy を使うと。

const char **
expand_argv(int & argc, const char ** argv)
{
bool need_expand = false;
int end_of_arg = -1;   // position of --

   // check if any argument contains spaces and remember the '--' option
   //
   loop(a, argc)
      {
        if (end_of_arg != -1)   // '--' seen
           {
             scriptname = argv[a];
             end_of_arg = -1;
           }

        if (strchr(argv[a], ' '))     need_expand = true;
        if (!strcmp(argv[a], "--"))   end_of_arg = a;
      }

   // if no argument had a space then return the original argv 
   //
   if (!need_expand)   return argv;

vector<const char *>argvec;

   end_of_arg = -1;
   loop(a, argc)
      {
        if (end_of_arg != -1)   // '--' seen
           {
             scriptname = argv[a];
             end_of_arg = -1;
           }
        end_of_arg = -1;

        if (strchr(argv[a], ' ') == 0)   // no space in this arg
           {
             argvec.push_back(argv[a]);
             if (!strcmp(argv[a], "--"))   end_of_arg = a;
             continue;
           }

        // arg has spaces, i.e. it may have multiple options
        //
        const char * arg = argv[a];

        for (;;)
            {
              while (*arg == ' ')   ++arg;   // skip leading spaces
              if (*arg == 0)        break;   // nothing left
              if (*arg == '#')      break;   // comment

              const char * sp = strchr(arg, ' ');
              if (sp == 0)   sp = arg + strlen(arg);
              const int new_len = sp - arg;   // excluding terminating 0
              if (!strncmp(arg, "--", new_len))   end_of_arg = a;

              char * new_arg = new char[new_len + 1];
              memcpy(new_arg, arg, new_len);
              new_arg[new_len] = 0;
              argvec.push_back(new_arg);
              arg = sp;
            }
      }

   argc = argvec.size();

   // the user may not be aware of how 'execve' calls an interpreter script
   // and may not have given -f as the last option in the script file.
   // In that situation argv is something like:
   //
   // "-f" "-other-options..." "script-name"
   //
   // instead of the expected:
   //
   // "-other-options..." "-f" "script-name"
   //
   // We fix this common mistake here. The downsize is, or course, that option
   // names cannnot be script names. We ignore options -h and --help since
   // they exit immediately.
   //
   for (int a = 1; a < (argc - 1); ++a)
       {
         const char * opt = argvec[a];
         const char * next = argvec[a + 1];
         if (!strcmp(opt, "-f") && ( !strcmp(next, "-d")     ||
                                     !strcmp(next, "--id")   ||
                                     !strcmp(next, "-l")     ||
                                     !strcmp(next, "--noSV") ||
                                     !strcmp(next, "-w")     ||
                                     !strcmp(next, "-T")     ||
                                     !strcmp(next, "--TM")))
            {
              for (int aa = a; aa < (argc - 2); ++aa)
                 argvec[aa] = argvec[aa + 1];
              argvec[argc - 2] = opt;   // put the -f before last
              break;   // for a...
            }
       }

const char ** ret = new const char *[argc + 1];
   loop(a, argc)   ret[a] = argvec[a];
   ret[argc] = 0;
   return ret;
}

なんで getopt_long 使わないのだろう…

/// print a welcome message (copyright notice)
static void
show_welcome(ostream & out)
{
char c1[200];
char c2[200];
   snprintf(c1, sizeof(c1), _("Welcome to GNU APL version %s"),PACKAGE_VERSION);
   snprintf(c2, sizeof(c2), _("for details run: %s --gpl."), progname);

const char * lines[] =
{
  "",
  c1,
  "",
  "Copyright (C) 2008-2013  Dr. Jテシrgen Sauermann",
  "",
_("This program comes with ABSOLUTELY NO WARRANTY;"),
  c2,
  "",
_("This program is free software, and you are welcome to redistribute it"),
_("according to the GNU Public License (GPL) version 3 or later."),
  "",
  0
};

   // compute max. length
   //
int len = 0;
   for (const char ** l = lines; *l; ++l)
       {
         const char * cl = *l;
         const int clen = strlen(cl);
         if (len < clen)   len = clen;
       }
 
const int left_pad = (80 - len)/2;

   for (const char ** l = lines; *l; ++l)
       {
         const char * cl = *l;
         const int clen = strlen(cl);
         const int pad = left_pad + (len - clen)/2;
         loop(p, pad)   out << " ";
         out << cl << endl;
       }
}

left_pad = (80 - len)/2 てサイズ決めうち?

int
main(int argc, const char * _argv[])
{
const char ** argv = expand_argv(argc, _argv);
bool do_CONT = true;   // load workspace CONTINUE on start-up
int requested_id = 0;

   Quad_ARG::argc = argc;
   Quad_ARG::argv = argv;

   progname = argv[0];
   set_APL_bin_path(progname);
   set_APL_lib_root();

   sigaction(SIGINT,  &new_control_C_action, &old_control_C_action);
   sigaction(SIGUSR1, &new_USR1_action,      &old_USR1_action);
// sigaction(SIGSEGV, &new_segfault_action,  &old_segfault_action);

   init();

Workspace w;
bool do_sv = true;
bool daemon = false;
bool append_summary = false;
int wait_ms = 0;
int option_errors = 0;

   // init NLS so that usage() will be translated
   //
#ifdef ENABLE_NLS
   init_NLS();
#endif

   for (int a = 1; a < argc; )
       {
         const char * opt = argv[a++];
         const char * val = (a < argc) ? argv[a] : 0;

         if (!strcmp(opt, "--"))   // end of arguments
            {
              a = argc;
              break;
            }
         else if (!strcmp(opt, "--cfg"))
            {
              show_configure_options();
              return 0;
            }
         else if (!strcmp(opt, "-d"))
            {
              daemon = true;
            }
         else if (!strcmp(opt, "-f"))
            {
              ++a;
              if (val)   Input::input_file_name = val;
              else
                 {
                   CERR << _("-f without filename") << endl;
                   return 1;
                 }
            }
         else if (!strcmp(opt, "--gpl"))
            {
              show_GPL(cout);
              return 0;
            }
         else if (!strcmp(opt, "-h") || !strcmp(opt, "--help"))
            {
              usage(argv[0]);
              return 0;
            }
         else if (!strcmp(opt, "--id"))
            {
              // skip this option (handled by ProcessorID::init() below)
              //
              requested_id = val ? atoi(val) : 0;
              ++a;
              continue;
            }
#ifdef DYNAMIC_LOG_WANTED
         else if (!strcmp(opt, "-l"))
            {
              ++a;
              if (val)   Log_control(LogId(atoi(val)), true);
              else
                 {
                   CERR << _("-l without log facility") << endl;
                   return 1;
                 }
            }
#endif // DYNAMIC_LOG_WANTED
         else if (!strcmp(opt, "--noCIN"))
            {
              do_not_echo = true;
            }

(略)

   if (daemon)
      {
        if (fork())   return 0;   // parent returns
        Log(LOG_startup)   CERR << "process forked" << endl;
      }

   if (wait_ms)   usleep(1000*wait_ms);

   if (!silent)   show_welcome(cout);

   Log(LOG_startup)   CERR << "PID is " << getpid() << endl;
   Log(LOG_argc_argv)   show_argv(argc, argv);

   TestFiles::testcase_count = TestFiles::test_file_names.size();

   if (ProcessorID::init(argc, argv, do_sv))
      {
        COUT << _("*** Another APL interpreter with --id ")
             << requested_id <<  _(" is already running") << endl;
        return 4;
      }

   if (do_CONT)
      {
         UCS_string cont("CONTINUE.xml");
         vector<UCS_string> lib_file;
         lib_file.push_back(cont);
         UTF8_string path = Command::get_lib_file_path(lib_file);
         if (access((const char *)path.c_str(), F_OK) == 0)
            {
              UCS_string load_cmd(")LOAD CONTINUE");
              Command::process_line(load_cmd);
            }
      }

   for (;;)
       {
         Token t = w.immediate_execution(
                   TestFiles::test_mode == TestFiles::TM_EXIT_AFTER_ERROR);
         if (t.get_tag() == TOK_OFF)   Command::cmd_OFF(0);
       }

   /* not reached */
}
//-----------------------------------------------------------------------------

やっぱり getopt つかってない。

■_

2013年10月02日

■_

きんどる。 KADOKAWAのアレでコミック中心に買いまくったらデバイスが溢れたw コミックはデータでかいしねえ。 溢れたところでamazonからメールが届いたのはびっくりした。 不要なもの消して容量開けろとか教えてくれるのはいいんだけど、 メールが英語で書かれているのはどうなんだろうか?w

雨傘自転車

6502とARM、そしてインテルは魔法使い - Togetter むかーし、仕事で 6502ベースのマイクロコントローラーを使ったことがあるんですが (某日本メーカー製)、 8bit×8bitの乗算命令が追加されてたりしてました。 8bit×8bit だと積が16bitになりますが、積の上位8bit(だったと思う)がスタックに積まれるという楽しい仕様でした。 とはいえあまり使い道なかったよなああれ。 まあなにに使うかにもよったのかもしれませんが。

押井守メルマガ、今回もとても面白かった。 有料だとオススメも難しいわねえ。自分としては値段分は十分あるんだけど。

■_ ぺちぺ→

Taking PHP Seriously [pdf] | Hacker News の元ネタのスライドを見た。 なんつーかよくやるなーぐらいしか感想が出てこない。

Most of the criticism of php seems to contrast it with a language *plus* a frame... | Hacker News

Most of the criticism of php seems to contrast it with a language plus a framework. If you really want to
compare, compare php with ruby or python, not Django or RoR.

As for php encouraging shitty programming, a good bit of that is that so many more people program in php because
its easier to get started with. This does not mean that just because php attracts shitty programmers that it
doesn't have more or many awesome programmers than languages such as python.


Methinks the argument that PHP encourages shitty programming has been effectively countered by the amount of
crap legacy Ruby code that has appeared several years since Rails became "hip".

It should be quite obvious to anyone by now that when it comes to shitty programming, language is negligible
factor once a language has hit the mainstream.

But I'm pretty sure 5 to 10 years from now someone manages to argue that Ruby is crap, Rails is to blame for
encouraging a generation of developers to write bloated controllers full of spaghetti code, and that this
attracts shitty programmers incapable of understanding software architecture.

■_ デバッグ六段階

何を書こうにもネタバレになるので直接ご覧を→ Six Stages of Debugging // plasmasturm.org 長い文章はないので安心してどうぞ :)

■_

C Style: my favorite C programming practices : programming 今日は時間がないか mcinglis/c-style これね。

mcinglis/c-style

This document describes what I consider good C. I've found these rules to be beneficial for me, in the domains I
work in. Some rules are as trivial as style, while others are more intricate. Some rules I adhere to religiously,
and others I use as a guideline. I prioritize correctness, readability, simplicity and maintainability over
speed and backwards-compatibility, because:

    premature optimization is the root of all evil
    compilers are generally better at optimizing than humans, and they're only going to get better
    backwards compatibility holds everyone back, and we should move forward if we can (if you can't, that's OK!)

Write correct, readable, simple and maintainable software, and tune it when you're done, with benchmarks to
identify the choke points. Also, modern compilers will change computational complexities. Simplicity can often
lead you to the best solution anyway: it's easier to write a linked list than it is to get an array to grow, but
it's harder to index a list than it is to index an array.

Many of these rules are just good programming practices, and apply outside of C programming. Writing this guide
made me deeply consider, and reconsider, best C programming practices. I've changed my opinion multiple times on
many of the rules in this document.

So, I'm certain I'm wrong on even more points. This is a constant work-in-progress; issues and pull-requests are
very welcome. This guide is licensed under the Creative Commons Attribution-ShareAlike, so I'm not liable for
anything you do with this, etc.

■_ 若いプログラマーへのアドバイス

これも定期的に良くでてくる話題ですね Advice to a Young Programmer : programming Advice to a Young Programmer - GameDev.net

Advice to a Young Programmer - GameDev.net

(略)

You may not be working on the next great MMO (or maybe you are!) but I think there's 
some value in this advice for anyone who is early on in their programming career.

で、見出しだけ。

■_

2013年10月01日

■_

近代麻雀買えなかった…

イカサマータイム期間が終わったのは良いものの、 時間帯がずれたので出勤のときに会社最寄り駅から会社への移動時に 駅に向かう人が多くなってしまって以下略。 特に自転車なー。

■_

arton さんのところで Amazon.co.jp: モダンC言語プログラミング 統合開発環境、デザインパターン、エクストリーム・プログラミング、テスト駆動開発、リファクタリング、継続的インテグレーションの活用: 花井志生: 本 の書評がありましたが 今、Cで開発するためのスタンダードを知るための本 - L'eclat des jours(2013-09-30) 10月発売予定の中にC関連の本が三冊も。 うち一冊は初級者向けではないっぽいですが二冊はいかにも入門書。 For Dummies とか日本で書かれた入門書と比べてみたいなあと思ったり。 Amazon.co.jp: Advanced Topics in C: with Algorithms and Data Structures: Noel Kalicharan: 洋書 Amazon.co.jp: Beginning Programming with C For Dummies (For Dummies (Computer/Tech)): Dan Gookin: 洋書 Amazon.co.jp: C Programming in One Hour a Day, Sams Teach Yourself (7th Edition): Bradley L. Jones, Peter Aitken, Dean Miller: 洋書

C Programming: A Modern Approach も途中まで読んで放置してるなあ… ってなんでこんなとんでもない値段になってんだこれ。 …と思ったが元からして80ドルくらいしてたのか C Programming: A Modern Approach, 2nd Edition: K. N. King: 9780393979503: Amazon.com: Books

■_

今月発売予定の中から注目のものを。 全部買ったら幾らになるんだろうw

■_ 十倍

なんか色々盛り上がってるぽい The 10x developer is NOT a myth : programming Jim's Blog: The 10x developer is NOT a myth The Myth of the Rockstar Programmer - Scott Hanselman

■_

今日はあまり読めなかった>GNU APL

■_


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

ホームへ


リンクはご自由にどうぞ

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