ときどきの雑記帖 RE* (新南口)
Battle Programmer Shirase
(オフィスの)人口密度
例のアレで申し訳程度に行われていたリモートワークも基本的には廃止となり、 オフィスの人口密度が高くなって以下略
GNU Pascal
ちょっと前のHNのスレッド。
GNU Pascal (2005) | Hacker News
121 comments
結構伸びてるなあ。
Seems abandoned. But Lazarus is doing well, although I doubt there are many Pascal users.
まあ、そうだよねえ>(GNU Pascalが)Seems abandoned
民芸的プログラミング
【メモ帳】ロスアラモスの「Fortran は、この先生きのこれるか」レポート - fortran66のブログ
どういう意味合いで使ったのかがいまひとつわからないのだけど、 なんか響くものがあった>「 民芸的プログラミング」
沢庵のおもしに茶袋
- 糠に釘ソング - Eテレ2355 - NHK
- 『0655』新曲「ぬかにくぎソング」が2023年5月8日初公開。阿佐ヶ谷姉妹のお二人が歌います - ディスディスブログ
- 沢庵のおもしに茶袋(タクアンノオモシニチャブクロ)とは? 意味や使い方 - コトバンク
知らなかったことわざがいくつかあった😄
今日の重箱の隅
「宇宙は我々スペースノイドの庭。昨日今日飛ぶことを覚えたアースノイドなど衆寡敵せず、質を持って打ち破る」というドクトリンはソロモンで潰えた。僕の二次創作における主人公・エレナは部下も戦友も全て失い、転科者とポンコツばかりで編成された大隊でア・バオア・クーを戦うことになった。
— ウチューじん・ささき (@uchujin17) May 10, 2023
「衆寡敵せず」の使い方がおかしいような。 「衆寡敵せず」って「少数では多数に勝てない」といった意味合いじゃなかったっけ?
ひょっとして自分が間違って覚えていたのかと辞書をひくと
英語でも同じような意味合いの言葉があるのか
Providence is always on the side of the big battalions.
MID$
まだまだ続くよ。 とは言っても本題(mid statement(代入可能なMID$関数)の初出)の 調査は進んでいないのだけど。
さて、前回までで hp(ヒューレットパッカード)の名前がでてきたが 自分にはあまり basicとhpが結びついている印象はない。
ので、ちょいと検索してみるとこういうものが見つかった
HP-BASIC
ASCII.jp:HP 9000シリーズでワークステーションのシェアを獲得したHP 業界に多大な影響を与えた現存メーカー (3/4)
1972年に登場した後継のHP 9830Aではそのプログラミング機能のためにBASICインタプリタを搭載する。
HP 9845の延長として、内蔵するCPUを8MHzのMC68000に切り替えたのが1982年11月にリリースされたのがHP 9816だ。 HP Pro-BASICとPASCALが動くほか、CP/M 68Kも動作したそうで、もう完全にPCという体裁になっている。
へー。
さらに探してみるとbitsaversにいろいろドキュメントがあった。 いくつか読んでみると確かにMicrosoft系(というかDEC系?)のBASICとは色々違う部分があり、 とくに部分文字列の扱いに関しては全然違うものだった。
たとえば BASIC 5.0/5.1 Program.m.ing Techniques によれば
Substrings
A subscript can be appended to a string variable name to define a substring. A substring may comprise all or just part of the original string. Brackets enclose the subscript which can be a constant, variable, or numeric expression. For instance: StringS [4] Specifies a substring starting with the fourth character of the original string.
The subscript must be in the range: 1 to the current length of the string plus 1. Note that the brackets now indicate the substring’s starting position instead of the total length of the string as when reserving storage for a string. Subscripted strings may appear on either side of the assignment.
以前にもちょっと話が出ていたように、 MID(MID$)のような文字列から部分文字列を取り出す関数はなくて、 文字列型変数に対して特別な添え字をつけることによって 得るということらしい。
この、「特別な添え字」のつけ方には二種類(細かく分ければ三種類)あって、 ひとつはブラケットのなかに一つだけ数値(というか数値として評価される式)があるもの
Single-Subscript Substrings
When a substring is specified with only one numerical expression, enclosed with brackets, the expression is evaluated and rounded to an integer indicating the position of the first character of the substring within the string.
The following examples use the variable A$ which has been assigned the literal “DICTIONARY”.
Statement Output PRINT A$ DICTIONARY PRINT A$[O] (error) PRINT A$ [1] DICTIONARY PRINT A$[5] IONARY PRINT A$[10] Y PRINT A$ [11] (null string) PRINT A$[12] (error) When a single subscript is used it specifies the starting character position, within the string, of the substring. An error results when the subscript evaluates to zero or greater than the current length of the string plus 1. A subscript that evaluates to 1 plus the length of the string returns the null string ("") but does not produce an error.
もう一つはブラケットの中に二つの数値があるもの。 これはさらに、ふたつの数値の間に カンマが置かれるものとセミコロンが置かれるものに分けられる (それぞれで意味が違う)
Double-Subscript Substrings
A substring may have two subscripts, within brackets, to specify a range of characters. When a comma is used to separate the items within brackets, the first subscript marks the beginning position of the substring, while the second subscript is the ending position of the substring. The form is: A$[Start,End]. For example, if A$ = “JABBERWOCKY”, then
A$[4,6] Specifies the substring: BER
When a semicolon is used in place of a comma, the first subscript again marks the beginning position of the substring, while the second subscript is now the length of the substring. The form is: A$[Start;Length]. A$[4;6] Specifies the substring: BERWOC In the following examples the variable B$ has been assigned the literal “ENLIGHTENMENT”:
Statement Output PRINT B$ ENLIGHTENMENT PRINT B$[1,13] ENLIGHTENMENT PRINT B$[1;13] ENLIGHTENMENT PRINT B$[1,9] ENLIGHTEN PRINT B$[1;9] ENLIGHTEN PRINT B$[3,7] LIGHT PRINT B$[3;7] LIGHTEN PRINT B$[13,13] N PRINT B$[13;1] N PRINT B$[13,26] (error) PRINT B$[13;13] (error) PRINT B$[14;1] (null string) An error results if the second subscript in a comma separated pair is greater than the current string length plus 1 or if the sum of the subscripts in a semicolon separated pair is greater than the current string length plus 1. Specifying the position just past the end of a string returns the null string.
MID STATEMENT(MID$関数の戻り値に対する代入) と違うのは次のような使い方ができるという点
Special Considerations
All substring operations allow a subscript to specify the first position past the end of a string. This allows strings to be concatenated without the concatenation operator. For instance:
10 A$="CONCAT" 20 A$[7]="ENATION" 30 PRINT A$ 40 END Produces: CONCATENATION
ただしこの辺は同じ?
The substring assignment is only valid if the substring already has charaders up to the specified position. Access beyond the first position past the end of a string results in the error:
ERROR 18 String ovfl. or substring err
A good practice is to dimension all strings including those shorter than the default length of eighteen characters. Some very interesting assignments can be attempted. For example, a 14-character string can be assigned to a 3-character substring.
10 Big$="Too big to fit" 20 Small$="Little string" 30 ! 40 Small$[l,3]=Big$ 50 60 PRINT SmallS 70 END Prints: Tootle string
When a substring assignment specifies fewer charaders than are available, any extra trailing characters are truncated
The alternate assignment is shown in the next example. Here a 4-character string is assigned to a 8-character substring.
10 Big$="A large string" 20 Small$="tiny" 30 ! 40 Big$[3.10]=Small$ 50 60 DISP Big$ 70 END Prints: A tiny ring
Since the subscripted length of the substring is greater than the length of the replacement string, enough blanks (ASCII spaces) are added to the end of the replacement string to fill the entire specified substring
その他
他のマニュアルで同様な記述が見つかった。
HP BASIC Language Processor Programmer’s Reference Guide
p.133-136(3-93)
BASIC Language Reference Volume 1: A-N
b-14
BASIC Language Reference for the HP 9826 Computer
p.280(285)
おまけ
この BASIC Language Reference for the HP 9826 Computer でも演算子の優先順位についての記述を見つけたので紹介。
p.273(278)
MATH Hierarchy
Parentheses; they may be used to force any order of operations. Functions, both user-defined and machine-resident Expoonentiation: ^ Multiplication and division * / MOD DIV Addition, subtraction, monadic plus and minus: + - Relational operators: = <> < > <= >= NOT AND OR EXOR
単項のマイナスがない?
それと「排他的論理和」がXOR
でもEOR
でもなくEXOR
なんですな。
64000
hpの64000と言えば わたしの最初の配属先で メインで使われていた開発機材だったりする。
もっとも人数分の台数はなかったので、 ぺーぺーのわたしが使うこと(使わせてもらえる)ことは ほとんどなかったのだった(遠い目)。
pascal
なんか面白い特徴があったりするんだろうか、このPascal。
switch
うぃきぺ(英語版)にエントリ Switch statement - Wikipedia があった。
それによると
Fallthrough
In many languages, only the matching block is executed, and then execution continues at the end of the switch statement. These include the Pascal family (Object Pascal, Modula, Oberon, Ada, etc.) as well as PL/I, modern forms of Fortran and BASIC dialects influenced by Pascal, most functional languages, and many others. To allow multiple values to execute the same code (and avoid needing to duplicate code), Pascal-type languages permit any number of values per case, given as a comma-separated list, as a range, or as a combination.
Languages derived from C language, and more generally those influenced by Fortran’s computed GOTO, instead feature fallthrough, where control moves to the matching case, and then execution continues (“falls through”) to the statements associated with the next case in the source text. This also allows multiple values to match the same point without any special syntax: they are just listed with empty bodies. Values can be special conditioned with code in the case body. In practice, fallthrough is usually prevented with a break keyword at the end of the matching body, which exits execution of the switch block, but this can cause bugs due to unintentional fallthrough if the programmer forgets to insert the break statement. This is thus seen by many[2] as a language wart, and warned against in some lint tools. Syntactically, the cases are interpreted as labels, not blocks, and the switch and break statements explicitly change control flow. Some languages influenced by C, such as JavaScript, retain default fallthrough, while others remove fallthrough, or only allow it in special circumstances. Notable variations on this in the C-family include C#, in which all blocks must be terminated with a break or return unless the block is empty (i.e. fallthrough is used as a way to specify multiple values).
やっぱりFORTRANの計算型GOTOに関連があった?> influenced by Fortran's computed GOTO
links
- McCarthy Formalism - Wikipedia
- Goto - Wikipedia
- Branch table - Wikipedia
- Multiway branch - Wikipedia
FORTRAN Compiler on IBM 704
以前からそんなに進捗出ていなかったけど このところさらに以下略な状態に。
レベルアナリシスのルーチンで参照しているALPHA
という領域が気になって調べてみたら
ORG 2701+4096 4F14188
ARGREG BSS 50 4F14189
CBAR BSS 1 4F14190
ABAR BSS 1 4F14191
FSTYPE BSS 1 4F14192
FSBITS BSS 1 4F14193
FNBITS BSS 1 4F14194
FNCTR BSS 1 4F14195
ALPHA BSS 139 4F14196
LAMBDA BSS 1200 4F14197
というところにあってこれはまあ引っかかることはなかったのだけど、 レベルアナリシスを含むARITHMETIC STATEMENTを処理するサブルーチンの 先頭で初期化している
STZ ARGCTR CLEAR 4F13462
STZ CHSAVE X 4F13463
STZ 3LBAR X 4F13464
STZ NBAR X 4F13465
STZ CBAR X 4F13466
STZ ABAR X 4F13467
STZ FSTYPE X 4F13468
LXD 1BAR,4 SET NBAR=-1 4F13469
SXD NBAR,4 X 4F13470
といった領域でこのALPHAを含むグループとは別の「まとまり」にあるものもあって
3LBAR BSS 1 STORAGE USED BY ARITHMETIC. 4F10270
...
NBAR BSS 1 STORAGE USED BY ARITHMETIC. 4F10292
とくに*BAR
なんて同じようなもの(なのか?)なんだから
なんで分かれているのだろうという疑問が。
メーテルさん
メーテルぅ、昔のネットジャンキーって何してたの。ツイッタも無いのに」「そうね鉄郎。fj.beginnersで新参をいじめ、jokesで下ネタを書き、lala-zと罵倒合戦しているうちに、」「朝になるんだよな、わかる」「就業時間が終わるのよ…」「ちょっと待って何言ってるかわかんない
— メーテル (@_maeter) May 29, 2014
fj.beginnersやfj.jokesには行かなかったけど、 言ってることはわかってしまう😓
あるたとえ話
あるたとえ話 (A parable) - ダイクストラによる、プログラマの魂をもった技師の話。https://t.co/E5wo4ZxEAG
— 新山祐介 (Yusuke Shinyama) (@mootastic) May 9, 2023
リンク先のgithubのリポジトリ、新山さんのアカウント?
ところで
私は異なる人々にこの話をしてきましたが、プログラマは一様にこの話を聞くと 歓喜するのに対して、 経営者は目に見えて不機嫌になりました。 いっぽう純粋な数学者は、なにが面白いのか理解できないようでした。
この話を聞いて、 プログラマーが「歓喜する」のはわかる。 純粋な数学者が 「なにが面白いのか理解できないようでした」 というのもまあなんとなく推測できる(ような気がする)。 でも経営者が 「目に見えて不機嫌になりました」 という理由がピンとこない😓
awk
awk の QA 。OFMT で指数形式を指定しているのに、整数形式で出力されるのは何故か、という質問。
— IT勉強中 (@IT41408082) May 8, 2023
次の二点がこの QA の答えだ。
・ 大きな桁数の数値(15,16桁以上)は、小数であっても整数に強制変換される。
・整数は OFMT の指定に関係なく、%dで変換される。https://t.co/1LrfxoJHym pic.twitter.com/VRyTncZZrX
QAだとQuestion and Answersではなくて Quarity Assuranceになってしまうような気がするのだけど それはさておき
・ 大きな桁数の数値(15,16桁以上)は、小数であっても整数に強制変換される。
これは勘違いじゃないかなあ。 おそらく
bash - Awk not outputting in scientific notation despite %e - Stack Overflow の
Any sufficiently large floating-point value is exactly equal to an integer.
と
$ cat foo.awk
#!/usr/bin/awk -f
BEGIN {
OFMT="%.16e"
for (i = 50; i <= 55; i ++) {
x = 2 ** i - 0.5
printf("2**%d - 0.5 = %.3f = ", i, x)
print(x)
}
}
$ ./foo.awk
2**50 - 0.5 = 1125899906842623.500 = 1.1258999068426235e+15
2**51 - 0.5 = 2251799813685247.500 = 2.2517998136852475e+15
2**52 - 0.5 = 4503599627370495.500 = 4.5035996273704955e+15
2**53 - 0.5 = 9007199254740992.000 = 9007199254740992
2**54 - 0.5 = 18014398509481984.000 = 18014398509481984
2**55 - 0.5 = 36028797018963968.000 = 36028797018963968
$
でそう考えたような気がするのだけど、そもそもIEEEの64bit浮動小数点数では
2**53 - 0.5
のような数値を「きちんと」表現(あるいは保持)できないのであって、
整数に強制変換されるというのは意味合いがちょっと違うと思う。
awkのこの動作に関しては桁数がぐっと小さな数値でも
kbk@toybox4:~$ gawk -vOFMT='%.15e' '{print $0*1}'
123
123
123.4
1.234000000000000e+02
123.4e0
1.234000000000000e+02
123.4e1
1234
123.4e2
12340
kbk@toybox4:~$
となるわけで。
このへんの「からくり」は gawkのメーリングリストでのやりとりでも言及されていたので 興味のある向きは以下略。
Re: Incorrect output with OFMT="%.15e"
The manual is frozen for the upcoming 5.2.2 release, but I will add a paragraph in the OFMT section (which is super old) pointing at the section that discusses CONVFMT; this will be there going forward.
In any case, both OFMT and CONVFMT convert integral values as integers. All awks work that way (or they should!).
This makes sense for most use cases. For example, foo[1] is really foo[“1”]; a %e conversion in CONVFMT would really cause confusion if the integral conversion rule were not in place.
I don’t have POSIX chapter and verse handy, nor the time to go looking right now, but I suspect that it says something like OFMT works the same as CONVFMT and is used for the print statement, which would cover the integral conversion rule.