ときどきの雑記帖 RE* (新南口)
The Magic Goes Away
訃報
今年は個人的に直接の知り合い(ほぼ同世代)が亡くなっていることもあるせいか、 訃報をいつになく目に(耳に)したような気がする。
- 漫画家・御厨さと美さん死去 74歳 『裂けた旅券』『イカロスの娘』など | ORICON NEWS
- 漫画家・聖悠紀さん、10月30日に亡くなっていた 享年72 SF漫画『超人ロック』手掛ける | ORICON NEWS
Bosque
ふと、MicrosoftのBosqueってどうなっているんだろうか気になったので リポジトリを見に行ったところ
GitHub - microsoft/BosqueLanguage
This repository has been archived by the owner before Nov 9, 2022. It is now read-only.
とあって、え? となったがよく読むと
This repository is archived and active development of the Bosque Language is moving to an external open-source repository under @BosqueLanguage (github repo is here)!
お引越ししたらしい。
引っ越し先は BosqueLanguage/BosqueCore
gawk
New PROCINFO elements, “mb_cur_max” and “utf8”. で入った機能がすぐに取り除かれていた。
Remove “mb_cur_max” and “utf8” PROCINFO entries.
diff --git a/ChangeLog b/ChangeLog
index 2c2fb8a..8e150f9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2022-12-11 Arnold D. Robbins <arnold@skeeve.com>
+ * main.c (load_procinfo): Remove "mb_cur_max" and "utf8"
+ entries, they're not of any real use.
+
+2022-12-11 Arnold D. Robbins <arnold@skeeve.com>
+
* main.c (get_pma_version): Add declaration.
(load_procinfo): Use it to set PROCINFO["pma"] if PMA is in use.
Thanks to J Naman for the feature suggestion.
そうかなあ? 拡張で使う機会がありそうな気もするけど>they're not of any real use.
ところでgawkと言えば
以前書いた gitのlocale初期化の話 の後に書いたけど放置してたものを貼り付け (年末だし(謎))。
locale初期化
GNU的なプログラムの書き方の例と言えばGNU hello hello.git - hello - GNU greeting package だよね。ということでコードを見るとlocaleの設定もきちんと行っている。 具体的には以下の通り。
hello - GNU greeting package
hello.c\src - hello.git - hello - GNU greeting package
int
main (int argc, char *argv[])
{
const char *greeting_msg;
wchar_t *mb_greeting;
mbstate_t mbstate = { 0, };
size_t len;
set_program_name (argv[0]);
/* Set locale via LC_ALL. */
setlocale (LC_ALL, "");
#if ENABLE_NLS
/* Set the text message domain. */
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
#endif
/* Having initialized gettext, get the default message. */
greeting_msg = _("Hello, world!");
/* Even exiting has subtleties. On exit, if any writes failed, change
the exit status. The /dev/full device on GNU/Linux can be used for
testing; for instance, hello >/dev/full should exit unsuccessfully.
This is implemented in the Gnulib module "closeout". */
atexit (close_stdout);
parse_options(argc, argv, &greeting_msg);
len = strlen(greeting_msg) + 1;
mb_greeting = xmalloc(len * sizeof(wchar_t));
len = mbsrtowcs(mb_greeting, &greeting_msg, len, &mbstate);
if (len == (size_t)-1)
error (EXIT_FAILURE, errno, _("conversion to a multibyte string failed"));
/* Print greeting message and exit. */
wprintf (L"%ls\n", mb_greeting);
free(mb_greeting);
exit (EXIT_SUCCESS);
}
ん、mbstateの初期化の書き方がちょっとひっかかるな。 なんだこれ。
もうちょっと複雑な例としてgawkからも。
こっちだとset_locale_stuff()
という関数にlocaleの初期化をまとめている。
set_locale_stuff()/main.c
set_locale_stuff()/main.c - gawk.git - gawk
/* set_locale_stuff --- setup the locale stuff */
static void
set_locale_stuff(void)
{
#if defined(LC_CTYPE)
setlocale(LC_CTYPE, locale);
#endif
#if defined(LC_COLLATE)
setlocale(LC_COLLATE, locale);
#endif
#if defined(LC_MESSAGES)
setlocale(LC_MESSAGES, locale);
#endif
#if defined(LC_NUMERIC) && defined(HAVE_LOCALE_H)
/*
* Force the issue here. According to POSIX 2001, decimal
* point is used for parsing source code and for command-line
* assignments and the locale value for processing input,
* number to string conversion, and printing output.
*
* 10/2005 --- see below also; we now only use the locale's
* decimal point if do_posix in effect.
*
* 9/2007:
* This is a mess. We need to get the locale's numeric info for
* the thousands separator for the %'d flag.
*/
setlocale(LC_NUMERIC, locale);
init_locale(& loc);
setlocale(LC_NUMERIC, "C");
#endif
#if defined(LC_TIME)
setlocale(LC_TIME, locale);
#endif
/* These must be done after calling setlocale */
(void) bindtextdomain(PACKAGE, locale_dir);
(void) textdomain(PACKAGE);
}
もうひとつ、locale設定とは別の話(でも一応localeに関係している)で オプション文字列のところを見て気がついたのだけど
static const struct option optab[] - gawk.git - gawk
static const struct option optab[] - gawk.git - gawk
/* Sorted by long option name! */
static const struct option optab[] = {
{ "assign", required_argument, NULL, 'v' },
{ "bignum", no_argument, NULL, 'M' },
{ "characters-as-bytes", no_argument, & do_binary, 'b' },
省略
{ "load", required_argument, NULL, 'l' },
#if defined(LOCALEDEBUG)
{ "locale", required_argument, NULL, 'Z' },
#endif
{ "non-decimal-data", no_argument, NULL, 'n' },
{ "no-optimize", no_argument, NULL, 's' },
{ "nostalgia", no_argument, & do_nostalgia, 1 },
省略
{ "use-lc-numeric", no_argument, & use_lc_numeric, 1 },
{ "version", no_argument, & do_version, 'V' },
{ NULL, 0, NULL, '\0' }
};
デバッグ用オプションなので自前でビルドしないと使えないものなのだろうけど コマンドラインオプションでlocaleの指定ができるようになってたのね。 デバッグ時でなくても使えるようにしてもいいような気もするけど それはそれで面倒があるのかもなあ。
ところでソースコード(のコメント)に自分の名前を見つけて、嬉しいやら恐縮するやら (今まで気がつかなかった)。
for
からサイトの過去記事を眺めていったら「for」に言及しているエントリを発見。
Is “for” the best term for a loop? – The Craft of Coding
The use of the term for to designate counting loops likely evolved from the use of für in Superplan. It has caught on in most programming languages, but is it the most appropriate term for a loop? The problem with the widely adapted for is that it is just not expressive. Consider the use of for in the following C statement:
Superplan – groovy! – The Craft of Coding
Some languages just never made it into the limelight. Sad really, but history is often written from a one sided perspective. In 1951, Swiss mathematician and computer scientist Heinz Rutishauser (1918-1970) proposed an algebraic, algorithmic language called Superplan [1], a “program that produces programs“, or compiler. One of the core contributions of Superplan was that it was likely the first language to incorporate the structure that would become the for loop in subsequent languages – für. In fact it was the only non-sequential control structure in the language. Superplan had a for loop, 1D arrays, but no if, goto or I/O statements.
It allowed for the evaluation of simple formulae. The addition of a for loop (für in German) was a pivotal development in programming languages, as even Fortran lacked this (it had DO). Some of the concepts in Superplan would later surface in Algol, as Rutishauser was one of the architects of ALGOL-58 and later ALGOL-60. Figure 1 shows an example of a piece of a Superplan program (3.2) from [1]. It shows the use of three well-structured nested loops. The for loop constructor was of the form:
まあ新しい情報はなかったわけですが。
FORTRAN Compiler on IBM 704
忘れたころにべき乗と単項マイナスの優先順位の話。
FORTRAN IV
http://bitsavers.informatik.uni-stuttgart.de/pdf/dec/pdp9/DEC-9A-KFZA-D_FORTRANIV.pdf のp.22に以下のような記述を発見。
2.4.1.2 Hierarchy of Operations - The order in which the operations of an arithmetic expression are to be computed is based on a priority rating. The operator with the highest priority takes precedence over other operators in the expression. Parentheses may be used to determine the order of computcltion. If no parentheses are used, the order is understood to be as follows:
a. Function reference
b. **(Exponentiation)
c. Unary minus evaluation
d. * and/{multipl ication and division)
e. + and -(addition and subtraction)
a.のFunction reference
はここでは
要するに関数呼び出しのこと。
んで、ここに書いてある順序だと
単項マイナスよりもべき乗の方が優先順位が高いですねえ。
ところで演算子の結合規則(右結合か左結合かあるいは結合しないか)に
関する記述はなかった。
FORTRAN66
さらにFORTRAN IVのあとのFORTRAN 66のドキュメントを見ると BNFのような形では書かれていないけど https://wg5-fortran.org/ARCHIVE/Fortran66.pdf の11ページにはこんな記述があった。
6.1 Arithmetic Expressions. An arithmetic expression is formed with arithmetic operators and arithmetic elements. Both the expression and its constituent elements identify values of one of the types integer, real, double precision, or complex. The arithmetic operators are:
Operator Representing + Addition, positive value (zero + element) - Subtraction, negative value (zero - element) * Multiplication / Division ** Exponentiation The arithmetic elements are primary, factor, term, signed term, simple arithmetic expression, and arithmetic expression.
A primary is an arithmetic expression enclosed in parentheses, a constant, a variable reference, an array element reference, or a function reference.
A factor is a pimary or a construct of the form:primary**primary
A term is a factor or a construct of one of the forms:
term/factor
or:
term*term
A signed arithmetic expression is a term or two simple arithmetic expression separated by a + or -.
An arithmetic expression is a simple arithmetic expression or a sigened term or either of the preceding forms immediately followed by a + or - immediately followed by a simple arithmetic expression.
A primary of any type may be exponentiated by an integer primary, and the resultant factor is of the same type as that of the element being exponentiated. A real or double precision primary may be exponentiated by a real or double precision primary, and the resultant factor is of type real if both primary are of real and otherwise of type double precision. These are the only cases for which use of the exponentiation operator is defined.
ん、除算が右結合している? >term/factor
べき乗含めた他の演算子も右結合なのか左結合なのかこれでは判断できないけど、
他で見たところ(どこでだったかは忘れた😓)では
べき乗に関しては
a ** b ** c
のようには書けなくて、
a ** (b ** c)
や(a ** b) ** c
のようにしなければならないらしい。
FORTRAN 0
以前ちょっと言及した
THE EARLY DEVELOPMENT OF PROGRAMMING LANGUAGES
を読んでいたら、FORTRAN 0
というのが出てきた。
p.63にあるサンプルプログラムによればこう。
DIMENSION A(11)
READ A
2 DO 3,8,11 J=1,11
3 I=11-J
Y=SQRT(ABS(A(I+1)))+5*A(I+1)**5
IF (400.>=Y) 8,4
4 PRINT I,999.
GO TO 2
8 PRINT I,Y
11 STOP
DO文やIF文のFORTRAN Iと違いが気になりますな
(READとPRINTもちょっと違う)。
しかし704(で使っていた文字コード)には>
は
なかったと思うけど?🤔
p.88にはFORTRAN Iバージョンもあってこんな感じ。
C THE TPK ALGORITHM, FORTRAN STYLE
FUNF(T) = SQRTF(ABSF(T))+5.0*T**5
DIMENSION A(11)
1 FORMAT(6F12.4)
READ 1, A
DO J = 1,11
I = 11-J
Y = FUNF(A(I+1))
IF (400.0-Y)4,8,8
4 PRINT 5, I
5 FORMAT(I10, 10H TOO LARGE)
GO TO 10
8 PRINT 9, I, Y
9 FORMAT(I10, F12.7)
10 CONTINUE
STOP 52525
このドキュメントではMATH-MATICにも言及されていて、 サンプルプログラムもある(機能はFORTRANのそれと同じ)。 これは漂うCOBOLっぽさが印象的。
p.89
MATH-MATIC and FLOW-MATIC
Meanwhile, Grace Hopper(s programming group at UNIVAC had also been busy. They had begun to develop an algobraic language in 1955, a project htat was headed by Charles Katz, and the computer was released to two released to two instllations for experimental tests in 1956. (cf. [BE 57], p.112.) The language was originally called AT-3; but it received the catchier name MATH-MATIC in April, 1957, when its preliminary manual [AB 57] was released. The following program for TPK gives MATH-MATIC’s flavor:
(1) READ-ITEM A(11) . (2) VARY I 10(-1)0 SENTENCE 3 THRU 10 . (3) J = I+1 . (4) Y = SQR |A(J)| + 5*A(J)3 . (5) IF Y>400, JUMP TO SENTENCE 8 . (6) PRINT-OUT I, Y . (7) JUMP TO SENTENCE 10 . (8) Z = 999 . (9) PRINT-OUT I, Z . (10) IGNORE . (11) STOP .
(4) の行にある5*A(J)3
の最後の3
は正確には
上付き
A(J)3
なんだけど、どう入力していたんだろうか。
The language was quite readable; note the vertival bar and superscript 3 in sentence (4), including an extended character set that could be used with some peripherals.
The other product of Grace Hopper’s programming staff was far more influential and successful, since it broke inportant new ground. This was what she originally called the Data-Processing compiler in January, 1955; it was soon to be knows as “B-0”, later as the “Procedure Translator” [KM 57], and finally as FLOW-MATIC [HO 58, TA 60]. This language used English words, somewhat as MATH-MATIC did but more so, and its operations concentrated on business applications. The following example are typical of FLOW-MATIC operations:
(1) COMPARE PART-NUMBER (A) TO PART-NUMBER (B) ; IF GRATOR GO TO OPERATION 13 ; IF EQUAL GO TO OPERATION 4 ; OTHERWISE GO TO OPERATION 2 . (2) READ^ITEM B ; IF END OF DATA GO TO OPERATION 10 .
ばーくはつだ
色んな方のご協力で、またまた色んな事を乗り越え、本日よりTAROMAN主題歌「爆発だッ!タローマン」がダウンロード販売開始してます!#タローマン#TOROMAN https://t.co/qeoYtDT6Ob
— 柳本喜久晴 (@kiku_yan) December 17, 2022
ちょっと前に配信が始まったときも聴こうとしたけど なぜかApple MusicでもAmazon Musicでも聴けなかったので 早速ポチった😄