ときどきの雑記帖 RE* (新南口)
Chariots of Fire
ビックロ
新宿の「ビックロ ユニクロ 新宿東口店」が6月19日で閉店 | SEVENTIE TWOは、世界各地のファッション&ビューティ情報を多言語で毎日配信するインターナショナル・メディアです。
「ビックロ ユニクロ 新宿東口店」はもともと10年間の定期建物貸借契約であり、 「ユニクロ」は新宿エリアに新宿フラッグス店と新宿三丁目店を今秋にオープンする予定だ。
ここってかつてジュンク堂が入ってたフロアのあるところだったよね? ということはなくなってからもう10年になるのか…😱
クレジットカード
何枚か持っているクレジットカードのなかにアスキーカード (ASCII CARD) というのがあって長いこと使っているのだけど、 ちょっと前にお知らせの封書が届いて 次回の利用期限(実はもうすぐ)の後の(アスキーカードとしての)更新はないとあった。
会社としてのアスキーはアレだし 今までよくもったというべきなのかもしれないけど VISAのカードとしても使えたので ちょっと困るかと思ったが、 本体(?)としてのNICOSカードに引き継がれるらしい。 ただ、カード番号などが変わったりするので 支払いに登録しているものには注意が必要と。
三菱UFJニコスのアスキーカードは、2021年8月2日に新規募集を終了いたしました。
去年の8月に新規募集が終了していたってことは だいぶ前に決まってたんですかね。
Bosuque
ちょっと前に話題になった(か?) Microsoft、理解の容易なコード記述のためのプログラム言語 Bosque を公開 って今はどうなっているんだろうか とふと気になった。
実は去年本も出ていたりするのだけど。
- Bosque (programming language) - Wikipedia
- Bosque Programming Language - Microsoft Research
- microsoft/BosqueLanguage: The Bosque programming language is an experiment in regularized design for a machine assisted rapid and reliable software development lifecycle.
止まってはいない。かな?
ピタゴラスイッチ
明日5月21日(土)朝のピタゴラは「かわりものでれんしゅうします」のまき。なにかを練習するとき、本物がつかえないこと、ありますよね? そんな「代わり」のもので練習する様子をご紹介します!
— ピタゴラ通信(by ユーフラテス) (@pitagora_web) May 20, 2022
放送はEテレ5月21日(土)朝7:35〜
再放送は 23日(月)夕方6:40〜
銀行員が紙幣を数える練習をするのに使う「偽札」が面白かった。 そりゃあ本物ではやりづらいわなあ(手触りとかは影響しないんだろうか? 材質は違うもののようだけど)。
カツオの一本釣りも、練習するというのは言われてみれば納得だけど ちょっと驚いた。
「かわりのものでれんしゅうします」 - ピタゴラスイッチ - NHK
初回放送日: 2022年2月12日
-3**2
という記事で
JavaScript
JavaScript の場合、なんと
console.log(-3**2); // Error: unparenthesized unary expression can't appear on the left-hand side of '**'
エラーになる。 ** の左辺にマイナスがついているとエラー。びっくりした。
とあったのが気になったのでちと調べた (コメントにChromeだとエラーメッセージが親切になってて理由がわかるとあるけれど)。
PHP や Python など、べき乗演算子 (**) を持つほとんどの言語では、べき乗演算子は単項演算子 (単項 + や単項 - など) よりも優先順位が高いと定義されていますが、いくつかの例外があります。例えば、Bash では ** 演算子は 単項演算子よりも優先順位が低いと定義されています。
JavaScript では、あいまいなべき乗式を記述することはできません。 つまり、基数の直前に単項演算子 (+/-/~/!/delete/void/typeof) を置くことはできません。 これを行うと、SyntaxError が発生します。
-2 ** 2; // Bashでは 4 他の言語では -4 // JavaScript では演算があいまいなため無効 -(2 ** 2); // JavaScript では意図が明白なため -4
なるほどねえ。
bash
bash の計算、不穏すぎるw pic.twitter.com/rk2cErPJFC
— mattn (@mattn_jp) May 18, 2022
「不穏」という言葉をどういう意味で使っているのかよくわからない (不穏とは - コトバンク) けど意図的にそうしているのは間違いなさそうで、 ソースコードのコメントにこんな記述があった。
All arithmetic is done as intmax_t integers with no checking for overflow (though division by 0 is caught and flagged as an error). The following operators are handled, grouped into a set of levels in order of decreasing precedence. "id++", "id--" [post-increment and post-decrement] "-", "+" [(unary operators)] "++id", "--id" [pre-increment and pre-decrement] "!", "~" "**" [(exponentiation)] "*", "/", "%" "+", "-" "<<", ">>" "<=", ">=", "<", ">" "==", "!=" "&" "^" "|" "&&" "||" "expr ? expr : expr" "=", "*=", "/=", "%=", "+=", "-=", "<<=", ">>=", "&=", "^=", "|=" , [comma]
zsh
コメントでzshもそうだというのがあったので(ry
* Opeator recedences: in reverse order, i.e. lower number, high precedence.
* These are the C precedences.
*
* 0 Non-operators: NUM (numeric constant), ID (identifier),
* CID (identifier with '#'), FUNC (math function)
* 1 Opening parenthesis: M_INPAR '(' (for convenience, not an operator)
* 2 Unary operators: PREPLUS/POSTPLUS '++', PREMINUS/POSTMINUS '--',
* NOT '!', COMP '~', UPLUS '+', UMINUS '-'
* 3 POWER '**' (not in C but at high precedence in Perl)
* 4 MUL '*', DIV '/', MOD '%'
* 5 PLUS '+', MINUS '-'
* 6 SHLEFT '<<', SHRIGHT '>>'
* 7 GRE '>', 'GEQ' '>=', LES '<', LEQ '<='
* 8 DEQ '==', NEQ '!='
* 9 AND '&'
* 10 XOR '^'
* 11 OR '|'
* 12 DAND '&&'
* 13 DXOR '^^' (not in C)
* 14 DOR '||'
* 15 QUEST '?'
* 16 COLON ':'
* 17 EQ '=', PLUSEQ '+=', MINUSEQ '-=', MULEQ '*=', DIVEQ '/=',
* MODEQ '%=', ANDEQ '&=', XOREQ '^=', OREQ '|=',
* SHFLEFTEQ '<<=', SHRIGHTEQ '>>=', DANDEQ '&&=', DOREQ '||=',
* DXOREQ '^^='
* 18 COMMA ','
* 137 M_OUTPAR ')' (for convenience, not an operator)
* 200 EOI (end of input: for convenience, not an operator)
確かにbashと同じ。 ただ、 zsh: 11 Arithmetic Evaluation に
11 Arithmetic Evaluation
With the option C_PRECEDENCES the precedences (but no other properties) of the operators are altered to be the same as those in most other languages that support the relevant operators: Note the precedence of exponentiation in both cases is below that of unary operators, hence ‘-3**2’ evaluates as ‘9’, not ‘-9’. Use parentheses where necessary: ‘-(3**2)’. This is for compatibility with other shells.
とあるのでzsh起源ではない。 一方bashの 6.5 Shell Arithmetic にもbashの拡張という記述は見当たらない (bash起源ならbash(GNU)による拡張だとか書く気がする)。
ちなみにopengroupでの記述はどうかというと
(( ))
による計算の言及はあるけどべき乗演算子(**
)は見当たらず
(Shell Command Language の2.6.4 Arithmetic Expansio)、
これの起源については面倒なので(ry
FORTRAN
ところで記憶をたどるとむかーし(大学で)使ったFORTRANでも -3**2 が9にならなかったか?という覚えがあって、 たとえばFortran-operators-precedence - Dev Guides でも
Category | Operator | Associativity |
---|---|---|
Logical NOT and negative sign | .not. (-) | Left to right |
Exponentiation | ** | Left to right |
Multiplicative | */ | Left to right |
Additive | + - | Left to right |
Relational | < <= > >= | Left to right |
Equality | ==/= | Left to right |
Logical AND | .and. | Left to right |
Logical OR | .or. | Left to right |
Assignment | = | Right to left~ |
のように書かれている。
そこで実際のコンパイラーで確かめてみるかと (しかしインストールは面倒くさいので) Wandboxを使おうと思ったところ 残念ながらFORTRANコンパイラーは見当たらず、 では他にないかと探して見つかった Online Fortran Compiler - online editor で試してみると…
あれ?😓
BASIC
FORTRANのお仲間(謎)のBASICはというと
演算子 | 処理 | サンプル式 |
---|---|---|
- | 否定 | -X |
^ ** |
累乗 | X ^ Y X ** Y |
* | 乗算 | X * Y |
/ | 除算 | X / Y |
+ | 加算 | X + Y |
- | 減算 | X - Y |
というのもあるんだけど 演算子の優先順位 - Visual Basic | Microsoft Docs や Quick Basic文法の基礎 のように逆(べき乗演算子の優先順位の方が高い)になってるものもあるんだよねえ。
bc, Tcl, Pangaea
そこそこ書いた後で元記事を再確認しに行ったら追記がされていて、
単項の-
の優先順位がべき乗のそれよりも高い例として
bc, Tcl, Pangaeaが追記されていた。
Pangaea
最後のPangaeaってナニ? と思ったのだけどこれ Syuparn/Pangaea: A programming language for one-liner method chain lovers! ですか。
A programming language for one-liner method chain lovers!
ふむ。さらに Pangaea/design_concepts.md at master · Syuparn/Pangaea には
Pangaea is designed for general-purpose programming language. It especially aims at comfortable one-liner script.
という説明もあった。 それはさておき Pangaea/operators.md at master · Syuparn/Pangaea によれば
Precedence
(from highest to lowest)
Precedence indexing a[b] grouping () calling a.b prefix operators chain ** *, /, //, % +, - «, » /& / <=>, ==, !=, <=, >=, <, >, ===, !== && || left assign a := 1, compound assign a += 1 right assign 1 => a jump statements return x ternary a if b else c
で、prefix operators
は具体的には
Prefix
operator meaning ! not + plus - minus ~ bit invert
ということなので、意図的なものですね。 なぜこの言語が取り上げられたのか(聞き覚えのない名前だったし)不思議に思ったのだけど
話題の「-3の2乗」、Pangaeaでは9になります😇
— syuparn (@syuparn) May 18, 2022
(-3はリテラルとして扱われるので)https://t.co/WpPY93Df1y pic.twitter.com/bBjFJQjM1X
作者の売り込み(違)があったのか😄
bc
次にbcだけど bc Command Manual によると
The expression precedence is as follows: (lowest to highest)
|| operator, left associative && operator, left associative ! operator, nonassociative Relational operators, left associative Assignment operator, right associative + and - operators, left associative *, / and % operators, left associative ^ operator, right associative unary - operator, nonassociative ++ and -- operators, nonassociative
と、こちらも単項-の方が優先順位が上。
ところで上記の表に続いて興味深い記述があった。
This precedence was chosen so that POSIX compliant bc programs will run correctly. This will cause the use of the relational and logical operators to have some unusual behavior when used with assignment expressions. Consider the expression:
a = 3 < 5
Most C programmers would assume this would assign the result of “3 < 5” (the value 1) to the variable “a”. What this does in bc is assign the value 3 to the variable “a” and then compare 3 to 5. It is best to use parentheses when using relational and logical operators with the assignment operators.
なるほどねえ。
opengroup的にはどうかというとこう (最初これに気がつかなくて定義されてない? と勘違いしそうになったのはナイショ)。
The following table summarises the rules for precedence and associativity of all operators. Operators on the same line have the same precedence; rows are in order of decreasing precedence.
Operator Associativity ++, – not applicable unary - not applicable ^ right to left *, /, % left to right +, binary - left to right =, +=, -=, *=, /=, %=, ^= right to left ==, <=, >=, !=, <, > none
Tcl
次にTcl。 expr manual page - Tcl Built-In Commands に
Unless otherwise specified, operators accept non-numeric operands. The value of a boolean operation is 1 if true, 0 otherwise. See also string is boolean. The valid operators, most of which are also available as commands in the tcl::mathop namespace (see mathop(n)), are listed below, grouped in decreasing order of precedence:
- + ~ !
Unary minus, unary plus, bit-wise NOT, logical NOT. These operators may only be applied to numeric operands, and bit-wise NOT may only be applied to integers.**
Exponentiation. Valid for numeric operands. The maximum exponent value that Tcl can handle if the first number is an integer > 1 is 268435455.* / %
Multiply and divide, which are valid for numeric operands, and remainder, which is valid for integers. The remainder, an absolute value smaller than the absolute value of the divisor, has the same sign as the divisor.When applied to integers, division and remainder can be considered to partition the number line into a sequence of adjacent non-overlapping pieces, where each piece is the size of the divisor; the quotient identifies which piece the dividend lies within, and the remainder identifies where within that piece the dividend lies. A consequence of this is that the result of “-57 / 10” is always -6, and the result of “-57 % 10” is always 3.
と、これもbcと同様。 bcやTclのこの仕様はどういう経緯でこうなったんだろう?
Ruby
といったところで今回の本命Rubyの話を… と行きたいところだったけど、 意外に深みにはまったり 勘違いがあったりしたので次回以降に。
links
- Exponentiation operator - Rosetta Code
- Exponential operator - D Programming Language Discussion Forum
- Exponentiation operator precedence
- How to Calculate Negative Exponents: 10 Steps (with Pictures)
- programming languages - Why was the caret used for exponentiation in BASIC? - Software Engineering Stack Exchange
- Exponentiation - Wikipedia
- 冪乗 - Wikipedia
- c# - Calculate power of a negative number - Stack Overflow
- -3^2 - Wolfram|Alpha
Mel’s Loop
あ、Melの話だ。
- Mel’s Loop – A Comprehensive Guide to The Story of Mel (celebrating 39 years to the publishing of the story on Usenet!) : programming
- Mel’s Loop - Home
出だしの部分をちょっと。
Maybe they do now,
in this decadent era of
Lite beer, hand calculators, and "user-friendly" software
but back in the Good Old Days,
when the term "software" sounded funny
and Real Computers were made out of drums and vacuum tubes,
Real Programmers wrote in machine code.
Not FORTRAN. Not RATFOR. Not, even, assembly language.
Machine Code.
Raw, unadorned, inscrutable hexadecimal numbers.
Directly.
Lest a whole new generation of programmers
grow up in ignorance of this glorious past,
I feel duty-bound to describe,
as best I can through the generation gap,
how a Real Programmer wrote code.
I'll call him Mel,
because that was his name.
以下略。
訳してもいいんだけど 「ハッカーズ大辞典」に載っていた訳にはかなわないよなあ。
Pike
プログラミング言語Pike。C風の文法をもつインタプリタ言語で、用途はPythonに似ているがPythonよりも速いらしい。ひとつのプログラムがクラスとしても扱えるという特徴をもつ。Rob Pikeとはおそらく無関係。https://t.co/xCPBRljjBK
— 新山祐介 (Yusuke Shinyama) (@mootastic) May 22, 2022
Pike。懐かしい名前だ。 まだ続いてたのね。
うぃきぺにも項目があるんだけど、 英語版だとリダイレクトされてしまう。
From Wikipedia, the free encyclopedia (Redirected from Pike (programming language))
locale
ISO C locale はもう壊れてるので何らかの方法で捨てられないものか
— AoiMoe a.k.aしお兄P (@AoiMoe) May 18, 2022
という前提は脇に置いといて。
思った通りに sort されない (LC_COLLATE=en_US.UTF-8 の罠) | ず@沖縄
よくよく調べてみると、en_USの場合は、辞書式順序で並び替えを行うらしい。 その場合、 ハイフン “-" を抜いた残りで並べ替えるようだ。 なるほど確かに、先のsort結果は – を抜いてみると d r t の順に並んでいて正しいようだ。
ちなみに、arch LinuxのWikiのロケールの項目には「潜在的な問題を回避するため、Arch では以前 /etc/profile で LC_COLLATE=C と設定していましたが、現在は使われなくなっています」と書かれている。
Ubuntu (Pop!_OS) で ls -l の出力を sort に食わせたらアルファベットの間に記号が来た。壊れてるのは誰だ。 - はてなの鴨澤
とはいえ困るのはハイフンの扱いを選択できないことだけなので、 これはsortコマンドの方で(より根本的にはロケール情報を処理するlibcに)選択オプションを設けるべきであろう。
ls(ls -l
)の出力をsortに食わせる目的が良くわからないのだけど
(それと「libcにオプション」てどういうことだろう?)、
通常のファイルを先にまとめ、次にディレクトリをまとめて
という形にしたかったんだろうか?🤔
ディレクトリを後にではなく先にまとめるならそれ用のオプションがあるにはあるんだけど。
‘–group-directories-first’
Group all the directories before the files and then sort the directories and the files separately using the selected sort key (see –sort option). That is, this option specifies a primary sort key, and the –sort option specifies a secondary key. However, any use of –sort=none (-U) disables this option altogether.
まあそれはそれとして glibcのソースを見るに
glibc/en_US at master · lattera/glibc
comment_char %
escape_char /
% This file is part of the GNU C Library and contains locale data.
% The Free Software Foundation does not claim any copyright interest
% in the locale data contained in this file. The foregoing does not
% affect the license of the GNU C Library as a whole. It does not
% exempt you from the conditions of the license if your use would
% otherwise be governed by that license.
% Locale for English locale in the USA
LC_IDENTIFICATION
title "English locale for the USA"
source "Free Software Foundation, Inc."
address "https:////www.gnu.org//software//libc//"
contact ""
email "bug-glibc-locales@gnu.org"
tel ""
fax ""
language "American English"
territory "United States"
revision "1.0"
date "2000-06-24"
category "i18n:2012";LC_IDENTIFICATION
category "i18n:2012";LC_CTYPE
category "i18n:2012";LC_COLLATE
category "i18n:2012";LC_TIME
category "i18n:2012";LC_NUMERIC
category "i18n:2012";LC_MONETARY
category "i18n:2012";LC_MESSAGES
category "i18n:2012";LC_PAPER
category "i18n:2012";LC_NAME
category "i18n:2012";LC_ADDRESS
category "i18n:2012";LC_TELEPHONE
category "i18n:2012";LC_MEASUREMENT
END LC_IDENTIFICATION
LC_CTYPE
copy "en_GB"
END LC_CTYPE
LC_COLLATE
% Copy the template from ISO/IEC 14651
copy "iso14651_t1"
END LC_COLLATE
LC_MONETARY
以下略
glibc/iso14651_t1 at master · lattera/glibc
omment_char %
escape_char /
% This file is part of the GNU C Library and contains locale data.
% The Free Software Foundation does not claim any copyright interest
% in the locale data contained in this file. The foregoing does not
% affect the license of the GNU C Library as a whole. It does not
% exempt you from the conditions of the license if your use would
% otherwise be governed by that license.
LC_COLLATE
copy "iso14651_t1_common"
script <HAN>
order_start <HAN>;forward;forward;forward;forward,position
<U4E00> <U4E00>;IGNORE;IGNORE;IGNORE
.. ..;IGNORE;IGNORE;IGNORE
<U9FA5> <U9FA5>;IGNORE;IGNORE;IGNORE
order_end
END LC_COLLATE
glibc/iso14651_t1_common at master · lattera/glibc
escape_char /
comment_char %
% This file is part of the GNU C Library and contains locale data.
% The Free Software Foundation does not claim any copyright interest
% in the locale data contained in this file. The foregoing does not
% affect the license of the GNU C Library as a whole. It does not
% exempt you from the conditions of the license if your use would
% otherwise be governed by that license.
LC_COLLATE
% Decomment the lines above to create an
% LC_COLLATE definition in the style of ISO/IEC TR 14652:2004.
% Note that ISO/IEC TR 14652:2004 has been replaced by ISO/IEC TR 30112:2014.
% Autogenerated Common Template Table
% created from unidata-9.0.0.txt
Unicodeコンソーシアムが大きな力を持ってるとしても ISOの規格にもなってますがな。 ということでUnicodeを「ワルモノ」に仕立てるのは筋違いじゃなかろうか (そもそもcollation orderと文字コードは別物だよねえ)。
- ISO - ISO/IEC TR 14652:2004 - Information technology — Specification method for cultural conventions
- ISO - ISO/IEC 30112:2020 - Information technology — Specification methods for cultural conventions
で、-
がcollationで無視されるってのはこの辺ですかね。
order_start <SPECIAL>;forward;backward;forward;forward,position
% Note: The following list of symbol_element's has been generated in
% sorted order, to assist in understanding the string ordering that
% results from use of this Common Template Table.
% <Uxxxx> <Base>;<Accent>;<Case>;<Special>
<U0000> IGNORE;IGNORE;IGNORE;<U0000> % NULL (in ISO 6429)
<U0001> IGNORE;IGNORE;IGNORE;<U0001> % START OF HEADING (in ISO 6429)
<U0002> IGNORE;IGNORE;IGNORE;<U0002> % START OF TEXT (in ISO 6429)
(略)
<U002B> IGNORE;IGNORE;IGNORE;<U002B> % PLUS SIGN
<U002C> IGNORE;IGNORE;IGNORE;<U002C> % COMMA
<U002D> IGNORE;IGNORE;IGNORE;<U002D> % HYPHEN-MINUS
<U002E> IGNORE;IGNORE;IGNORE;<U002E> % FULL STOP
あとcoreutilsのsortでは、比較のためにstrxfrm を使っているのでそういうこと(謎)なのです。
coreutils/sort.c at master · coreutils/coreutils
/* This is like strxfrm, except it reports any error and exits. */
static size_t
xstrxfrm (char *restrict dest, char const *restrict src, size_t destsize)
{
errno = 0;
size_t translated_size = strxfrm (dest, src, destsize);
if (errno)
{
error (0, errno, _("string transformation failed"));
error (0, 0, _("set LC_ALL='C' to work around the problem"));
die (SORT_FAILURE, 0,
_("the untransformed string was %s"),
quotearg_n_style (0, locale_quoting_style, src));
}
return translated_size;
}
ところで utf 8 - Gnu sort UTF-8 incorrect collation order - Stack Overflow で問題にされてるのは合字っぽいですね。
アルファベット表示形
Alphabetic Presentation Forms
EF AC 80
物は試しと WSL上のUbuntu でやってみたけど en_US.UTF-8でも期待通り並ぶぞ?🤔