ときどきの雑記帖 倒行逆施編

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

一つ前へ 2016年2月(中旬)
一つ後へ 2016年3月(上旬)

ホームへ

2016年02月29日

■_

「スピリットサークル」次回が最終回らしいです。

皇帝陛下もだんだん苦しくなっていくなあ。

■_

■_

GCC 6: -Wmisleading-indentation vs “goto fail;” : programming

GCC 6: -Wmisleading-indentation vs “goto fail;” : programming

What about the reverse? I recently came across code of the form: 
 
if (! rare_condition) 
 // debug_function(); 
 
do_stuff(); 
 
...and that, kids, is why you use braces. Don't be lazy. 
 
 
This is why, in the early days of Perl, Larry Wall was absolutely insistent that the only form of
non-brace conditional would be postfix (e.g. "print while <>" instead of
"while(<>)\nprint", the latter is only legal with braces). 
 
Python's solution (making whitespace syntactic, not merely lexical) is starting to look more and more
like C's given this kind of warning... I wonder if, someday in the far future, this warning will
become an error? Probably not. I expect there's too much institutional inertia, but it would solve
many problems...

そういえば、Perl で後置の if などが導入されたのは 5 からだけど、 4 の途中まで(たぶん) は C と同じように 単文は括弧なしで置けたなあ。

■_

V8 JavaScript Engine: RegExp lookbehind assertions Look behind assertion を(実験的に)実装しました ってはなしで

V8 JavaScript Engine: RegExp lookbehind assertions

A capturing group can be referenced via back reference after it has been captured. Usually, the back reference has to be to the right of the capture group. Otherwise, it would match the empty string, as nothing has been captured yet. However, inside a lookbehind assertion, the match direction is reversed:

  /(?<=(o)d\1)r/.exec("hodor") // null 
  /(?<=\1d(o))r/.exec("hodor") // ["r", "o"]

.NET のもそうだってあるんだけど 本当に逆方向に進めてくのねえ

V8 JavaScript Engine: RegExp lookbehind assertions

ziyunfeiFebruary 27, 2016 at 6:05 AM 

Just FYI: Perl 6 also supports the variable-length lookbehind, and in the meantime, the behaviour of capturing groups in lookbehind isn't different from that in lookahead.

$ perl6 -e 'say "hodor".match(/(o)d$0 <( r/)' 
「r」 
0 => 「o」 
 
/(o)d$0 <( r/ is equivalent to /(?<=(o)d\1)r/ in JS 

 hashseedFebruary 27, 2016 at 7:52 AM 

We modelled the behavior after .NET's implementation, which imo is quite intuitive, keeping in mind that the lookbehind is matched backwards.

2016年02月28日

■_

わたしががきんちょの頃は濁って 「ヴィンセント・ヴァン・ゴッホ」だったような気がするんだけど、 オランダ語の発音にあわせてフィンセント、ファン、となったのはいつ頃からだろう フィンセント・ファン・ゴッホ - Wikipedia

お、こんなんでるんだ Amazon.co.jp: The O'reilly Animals: An Adult Coloring Book: Inc. O'reilly Media: 洋書

■_

■_

Q&A: A lost interview with ENIAC co-inventor J. Presper Eckert | Computerworld エッカート(ENIAC のあの人ね)のインタビュー。 記事の日付は2006年2月なので十年前ですか。 インタビューそのものは I recorded two days of interviews with "Pres" Eckert in 1989. 1989年と。

結構長いんで幾つか興味をひかれた質問など。

Q&A: A lost interview with ENIAC co-inventor J. Presper Eckert | Computerworld
On the the 60th anniversary of the unveiling of ENIAC, a newly discovered interview with "Pres" Eckert explodes some ENIAC myths. 
 
By Alexander Randall 5th 
 
Computerworld | Feb 14, 2006 12:00 PM PT 

I recorded two days of interviews with "Pres" Eckert in 1989. He was 70 years old. My father was Pres' best friend from childhood and I'd spent my childhood playing with his children. I visited him regularly as an adult. On that day, we spoke in his living room in Gladwyne, Pa. -- most of the time sitting on the floor. We stopped talking about computers only to fiddle with his Nova Chord electronic organ, which predated ENIAC, and we fiddled with stereo speakers. On a second occasion I recorded a conversation at his daughter's home in western Massachusetts. Eckert died in 1995. I've had the interview tapes for many years, but decided to transcribe them for ENIAC's 60th anniversary.

Was ENIAC programmable? 

Yes and no. We programmed the machine by plugging wires in from place to place. That's not hard-wired; it's not software; it's not memory. It's pluggable programming. And we had switches to set the functions.

What was the first thing you did with ENIAC?

It was designed to calculate trajectory tables, but it came too late to really help with the war effort. The first real use was Edward Teller using ENIAC to do calculations for the hydrogen bomb.

A lot of people have claimed they invented the first computer. What about John Atanasoff? 

In the course of a patent fight, the other side brought up Atanasoff and tried to show that he built an electronic computer ahead of us. It's true he had a lab bench tabletop kind of thing and John [Mauchley] went out to look at it and wrote a memo, but we never used any of it. His thing didn't really work. He didn't have a whole system. That's a big thing with an invention: You have to have a whole system that works. John and I not only built ENIAC. It worked. And it worked for a decade doing what it was designed to do. We went on to build BINAC and UNIVAC and hundreds of other computers. And the company we started is still in operation after many name changes as Unisys, and I am still working for that company. Atanasoff may have won a point in court, but he went back to teaching and we went on to build the first real electronic programmable computers, the first commercial computers. We made a lot of computers, and we still are.

And John Von Neumann? 

He came and looked at our stuff and went back to Princeton and wrote a long document about the principles. He gets a lot of credit but the inventions were ours. Someday I'll write a book on who really invented the computer. It wasn't Atanasoff or Von Neumann. We did it. Randall is a professor of communication at the University of the Virgin Islands and director of the school's new computer communication laboratory. He formerly headed the now-defunct Boston Computer Exchange and East West Education Development Foundation.

Copyright © 1994 - 2016 Computerworld, Inc. All rights reserved. 

アタナソフやノイマンに対する評はまあそうだろねえという。 ところで Someday I'll write a book っていってる本は 結局世に出てない?

■_

Cの文字列関連のアレ C String Creation

C String Creation

C String Creation 

You often need to create a string in C. It's important to use the appropriate standard library functions for this, as this avoids a number of common error prone cases. This document shows how a modern C program would best do this. Read the manual pages for the mentioned functions to learn more.

You should use the patterns described here. If you find a need to call strcpy() yourself, it's probable you're writing error prone code and one of the mentioned interfaces would be simpler. If you must roll your own string construction logic, memcpy() is often a better primitive to use.

Pick the least powerful interface below that solves the problem at hand.

Creating a string of unbounded length

The common case is needing to construct a string whose length could be arbitrary. Functions should usually allocate the memory themselves, rather than using caller provided buffers.

使用例はおいといて、関数名とその portability のところを抜き出すとこう

strdup 
/* Portability: POSIX 2001 */ 

strndup 
/* Portability: POSIX 2008 */ 

asprintf 
/* Portability: Scheduled for next POSIX, but present on all modern systems. */ 

open_memstream 
/* Portability: POSIX 2008 */ 

strlcpy 
/* Portability: All modern systems, except glibc. */ 

snprintf 
/* Portability: C99 */ 

strncpy 
/* Portability: C89. */ 

open_memstream はまだ使ったことねーな。 strndup もかな。

2016年02月27日

■_

とあるネットラジオでBGMの一曲を聴いたのだけど とても興味を惹かれたのでじゃあサントラでも買ってみるか (サントラから選曲とあったので)と思って調べたら…… こいつの初回限定版特典でした○| ̄|_ 「食戟のソーマ」第1巻<初回生産限定版> [Blu-ray]
「食戟のソーマ」第1巻<初回生産限定版> [Blu-ray] 「食戟のソーマ」第5巻<初回生産限定版> 【イベントチケット先行購入申込券付】 [Blu-ray]
「食戟のソーマ」第5巻<初回生産限定版> 【イベントチケット先行購入申込券付】 [Blu-ray] うん。アニメ(に限らないだろうけど)の サントラは商売にならないってのは以前聞いたことがあるけどね○| ̄|_

■_

2016年02月26日

■_

この本も続いてるなあ

第41回 AsiaBSDCon 2016 3/10~13 オンライン参加登録開始:BSD界隈四方山話|gihyo.jp … 技術評論社 のキーノート Keynote K02: Steve Bourne srb@acm.org Steve Bourne氏はALGOL 68Cコンパイラの開発者であり,Bourne Shellの開発者です。

AsiaBSDCon 2016 - Conference Program

13:30 - 15:00 Keynote K01: Early days of Unix and Lessons Learned 
Steve Bourne (srb@acm.org)

にまんえんかあ…

■_

2016年02月25日

■_

ホークウッド、最終巻だった○| ̄|_

■_

■_

twitter で見かけて cqlsh/cqlsh at master · bpaquet/cqlsh

cqlsh/cqlsh at master · bpaquet/cqlsh

""":" 
# bash code here; finds a suitable python interpreter and execs this file. 
# prefer unqualified "python" if suitable: 
python -c 'import sys; sys.exit(not (0x020500b0 < sys.hexversion < 0x03000000))' 2>/dev/null \ 
 && exec python "$0" "$@" 
for pyver in 2.6 2.7 2.5; do 
 which python$pyver > /dev/null 2>&1 && exec python$pyver "$0" "$@" 
done 
echo "No appropriate python interpreter found." >&2 
exit 1 
":""" 
 
from __future__ import with_statement 
 
description = "CQL Shell for Apache Cassandra" 
version = "4.1.1"

↑三連クォートでシェルスクリプト部分をくるむことで そこをPythonが評価するのを避けてるってのはわかる。 閉じの三連クォート後のPythonの部分は 閉じの直前に exit があるからシェルが評価することはない。

三連クォートの前後(後前?)に :" と ": があるのは…… """" にしちゃうと("" のペア二つで)空文字になるから?

それと。単純に"""だけだとシェルでも(シェルスクリプト部分が)文字列になる。か?

■_

みんな大好き technical debt。 Why technical debt is more like a payday loan than a mortgage. - Geektastic Blog

Why technical debt is more like a payday loan than a mortgage. - Geektastic Blog
  1. There is no crystal ball - you can't predict the true cost of the debt you are taking on.
  2. Technical debt suffers from compound growth with an increasing rate of interest. What might take a few weeks to fix in the early days can easily take months later on.
  3. Some debt is never paid off.
  4. It becomes the excuse later down the line. Teams change, the liability shifts over time. Those that took on the debt leave and newcomers are left carrying the loan, they then use this debt as a (legitimate) excuse for long delivery times.

ところで payday loan ってなんじゃろと調べてみると…

2016年02月24日

■_

「書き時計」見てきた 18万RTを集めたあの「書き時計」を生で拝める! 東京で初展示

プレゼンの練習。

■_

2016年02月23日

■_

Excel 2016、結構芸が増えてるなあ。 アレとかアレとか使ってみたい。

CVE-2016-2384: arbitrary code execution due to a double-free in the usb-midi linux kernel driver double free か。

■_

■_

Project Euler Problem 35 #シェル芸 - jarp, の seq のはなし。

Project Euler Problem 35 #シェル芸 - jarp,

そもそも最初から奇数だけ扱えばいいのでseqで奇数指定する。 
 
% time (seq 1 2 999999|grep -v '[024568]'|wc -l) 
5460 
0.31s user 0.00s system 111% cpu 0.280 total 
 
なぜか遅くなった。佐藤さんの調査によるとGNU coreutils seqは +1だけ最適化してるという話で、なかなか興味深い。

ということでソースを読んでみた。

/* seq - print sequence of numbers to standard output.
   Copyright (C) 1994-2016 Free Software Foundation, Inc.

(略)

/* Written by Ulrich Drepper.  */

あ、うるりっひの名前が!

ソースコード上での登場順は違うけどまず判定部分はこう

int
main (int argc, char **argv)
{

(略)

  /* If the following hold:
     - no format string, [FIXME: relax this, eventually]
     - integer start (or no start)
     - integer end
     - increment == 1 or not specified [FIXME: relax this, eventually]
     then use the much more efficient integer-only code.  */
  if (all_digits_p (argv[optind])
      && (n_args == 1 || all_digits_p (argv[optind + 1]))
      && (n_args < 3 || (STREQ ("1", argv[optind + 1])
                         && all_digits_p (argv[optind + 2])))
      && !equal_width && !format_str && strlen (separator) == 1)
    {
      char const *s1 = n_args == 1 ? "1" : argv[optind];
      char const *s2 = argv[optind + (n_args - 1)];
      if (seq_fast (s1, s2))
        return EXIT_SUCCESS;

      /* Upon any failure, let the more general code deal with it.  */
    }

  if ((isfinite (first.value) && first.precision == 0)
      && step.precision == 0 && last.precision == 0
      && 0 <= first.value && step.value == 1 && 0 <= last.value
      && !equal_width && !format_str && strlen (separator) == 1)
    {
      char *s1;
      char *s2;
      if (asprintf (&s1, "%0.Lf", first.value) < 0)
        xalloc_die ();
      if (! isfinite (last.value))
        s2 = xstrdup ("inf"); /* Ensure "inf" is used.  */
      else if (asprintf (&s2, "%0.Lf", last.value) < 0)
        xalloc_die ();

      if (*s1 != '-' && *s2 != '-' && seq_fast (s1, s2))
        {
          IF_LINT (free (s1));
          IF_LINT (free (s2));
          return EXIT_SUCCESS;
        }

      free (s1);
      free (s2);
      /* Upon any failure, let the more general code deal with it.  */
    }

  if (format_str == NULL)
    format_str = get_default_format (first, step, last);

  print_numbers (format_str, layout, first.value, step.value, last.value);

  return EXIT_SUCCESS;
}

すべてが数字(==整数)で、増分が1で、 出力の幅を揃えない、書式指定がない、区切りは1バイト…というところ? 二つめの判定は削ったところも見ないと正確にはわからんけど、 大体同じようなものっぽい。

んで、その「高速」なほうがこれ

/* Print all whole numbers from A to B, inclusive -- to stdout, each
   followed by a newline.  If B < A, return false and print nothing.
   Otherwise, return true.  */
static bool
seq_fast (char const *a, char const *b)
{
  bool inf = STREQ (b, "inf");

  /* Skip past any leading 0's.  Without this, our naive cmp
     function would declare 000 to be larger than 99.  */
  a = trim_leading_zeros (a);
  b = trim_leading_zeros (b);

  size_t p_len = strlen (a);
  size_t q_len = inf ? 0 : strlen (b);

  /* Allow for at least 31 digits without realloc.
     1 more than p_len is needed for the inf case.  */
  size_t inc_size = MAX (MAX (p_len + 1, q_len), 31);

  /* Copy input strings (incl NUL) to end of new buffers.  */
  char *p0 = xmalloc (inc_size + 1);
  char *p = memcpy (p0 + inc_size - p_len, a, p_len + 1);
  char *q;
  char *q0;
  if (! inf)
    {
      q0 = xmalloc (inc_size + 1);
      q = memcpy (q0 + inc_size - q_len, b, q_len + 1);
    }
  else
    q = q0 = NULL;

  bool ok = inf || cmp (p, p_len, q, q_len) <= 0;
  if (ok)
    {
      /* Reduce number of fwrite calls which is seen to
         give a speed-up of more than 2x over the unbuffered code
         when printing the first 10^9 integers.  */
      size_t buf_size = MAX (BUFSIZ, (inc_size + 1) * 2);
      char *buf = xmalloc (buf_size);
      char const *buf_end = buf + buf_size;

      char *bufp = buf;

      /* Write first number to buffer.  */
      bufp = mempcpy (bufp, p, p_len);

      /* Append separator then number.  */
      while (inf || cmp (p, p_len, q, q_len) < 0)
        {
          *bufp++ = *separator;
          incr (&p, &p_len);

          /* Double up the buffers when needed for the inf case.  */
          if (p_len == inc_size)
            {
              inc_size *= 2;
              p0 = xrealloc (p0, inc_size + 1);
              p = memmove (p0 + p_len, p0, p_len + 1);

              if (buf_size < (inc_size + 1) * 2)
                {
                  size_t buf_offset = bufp - buf;
                  buf_size = (inc_size + 1) * 2;
                  buf = xrealloc (buf, buf_size);
                  buf_end = buf + buf_size;
                  bufp = buf + buf_offset;
                }
            }

          bufp = mempcpy (bufp, p, p_len);
          /* If no place for another separator + number then
             output buffer so far, and reset to start of buffer.  */
          if (buf_end - (p_len + 1) < bufp)
            {
              fwrite (buf, bufp - buf, 1, stdout);
              bufp = buf;
            }
        }

      /* Write any remaining buffered output, and the terminator.  */
      *bufp++ = *terminator;
      fwrite (buf, bufp - buf, 1, stdout);

      IF_LINT (free (buf));
    }

  free (p0);
  free (q0);
  return ok;
}

通常のはこちら。

/* Actually print the sequence of numbers in the specified range, with the
   given or default stepping and format.  */

static void
print_numbers (char const *fmt, struct layout layout,
               long double first, long double step, long double last)
{
  bool out_of_range = (step < 0 ? first < last : last < first);

  if (! out_of_range)
    {
      long double x = first;
      long double i;

      for (i = 1; ; i++)
        {
          long double x0 = x;
          printf (fmt, x);
          if (out_of_range)
            break;
          x = first + i * step;
          out_of_range = (step < 0 ? x < last : last < x);

          if (out_of_range)
            {
              /* If the number just past LAST prints as a value equal
                 to LAST, and prints differently from the previous
                 number, then print the number.  This avoids problems
                 with rounding.  For example, with the x86 it causes
                 "seq 0 0.000001 0.000003" to print 0.000003 instead
                 of stopping at 0.000002.  */

              bool print_extra_number = false;
              long double x_val;
              char *x_str;
              int x_strlen;
              setlocale (LC_NUMERIC, "C");
              x_strlen = asprintf (&x_str, fmt, x);
              setlocale (LC_NUMERIC, "");
              if (x_strlen < 0)
                xalloc_die ();
              x_str[x_strlen - layout.suffix_len] = '\0';

              if (xstrtold (x_str + layout.prefix_len, NULL, &x_val, c_strtold)
                  && x_val == last)
                {
                  char *x0_str = NULL;
                  if (asprintf (&x0_str, fmt, x0) < 0)
                    xalloc_die ();
                  print_extra_number = !STREQ (x0_str, x_str);
                  free (x0_str);
                }

              free (x_str);
              if (! print_extra_number)
                break;
            }

          fputs (separator, stdout);
        }

      fputs (terminator, stdout);
    }
}

そういやこれ、GNU 形式のインデントだわ。

2016年02月22日

■_

火蓋は切るもので、切って落とすものじゃあない(謎)

■_

■_

今日も今日とて重箱の隅を ソースコードの記号の意味 | エンジニアへの道|リナックスアカデミー公式ブログ

ソースコードの記号の意味 | エンジニアへの道|リナックスアカデミー公式ブログ
間違いやすい記号 
「*」 
 
(略)

キーボードで 
「×」の記号が入力できないため、 
 
見た目が近い 
「*」が使用されてます。
「/」 

(略)
これも「×」同様、 
キーボードで「÷」の記号が 
入力できないためです。 

「%」 
 
読み方は 
「パーセント」 
と発音します。 
 
この記号は、 
多くのプログラミング言語で 
「剰余算(余りを求める)」 
の記号として使用されます。 

* も / も割にこういう話を聞くように思いますがどこまで本当のことなんでしょうかね。 そもそも鶏と卵で、そういう使い方をしないからキーボード(さらに遡ってタイプライター)に 刻印がなかったとかいう話はないでしょうか。 Multiplication - Wikipedia, the free encyclopedia Division (mathematics) - Wikipedia, the free encyclopedia Slash (punctuation) - Wikipedia, the free encyclopedia そして剰余。 Modulo operation - Wikipedia, the free encyclopedia mod 派も多くね?

■_

もういっちょ。 「2016年、C言語はどう書くべきか」をちょっと分析してみる (warning編) - Qiita

「2016年、C言語はどう書くべきか」をちょっと分析してみる (warning編) - Qiita

warning : -Wshadow 
 
http://d.hatena.ne.jp/aki-yam/20130718/1374163303 
がわかりやすいです。 
 
未初期化変数がある場合に、warningを出してくれ、-Wallには入っていないとのこと。

これ、コメントでも指摘されてるけどなんで未初期化に対する警告だと思ったんだろう。 -Wshadowは変数が初期化されていないときに警告を出すのではありません。 -Wshadowは、要は変数の名前被りにエラーを出す設定です。

「わかりやすい」リンク先を見ると 変数の初期化をサボるな,それから -Wshadow オプションを使え - akihiko’s tech note

変数の初期化をサボるな,それから -Wshadow オプションを使え - akihiko’s tech note

gcc の場合,-Wshadow オプションをつけてコンパイルする(-Wall には含まれない).上記の例だと, 「警告: declaration of ‘x’ shadows a previous local [-Wshadow]」という警告を出してくれる

このメッセージをどうすればそういう解釈に?

2016年02月21日

■_

人生はただ一問の質問にすぎぬと書けば二月のかもめ (寺山修司)

■_

■_

本屋で見かけたら帯と解説に注目してみよう:) ラグランジュ・ミッション | 種類,ハヤカワ文庫SF | ハヤカワ・オンライン

■_


一つ前へ 2016年2月(中旬)
一つ後へ 2016年3月(上旬)

ホームへ


リンクはご自由にどうぞ

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