LoginSignup
1
0

<4> 動作の概念 (標準 Pascal 範囲内での Delphi 入門)〔裏〕

Last updated at Posted at 2021-02-16

4. 動作の概念

4.1. 代入文と式

・論理評価 (拡張 Pascal の場合)

拡張 Pascal では、このあいまいな論理評価を避けるために and_thenor_else という論理演算子を新たに追加しています。これらの演算子は短絡論理評価する事が保証されています。

・論理評価 (MPW Pascal の場合)

MPW Pascal では、andor とは別に &| が 使えます。これらは 短絡演算子 と呼ばれます。但し、一つの式の中でこれらを混在させる事はできません。

See also:

4.2. 手続き呼び出し文

4.3. 複合文と空文

4.4. 繰り返し文

4.4.1. while 文

4.4.2. repeat 文

4.4.3. for to do 文

・制御変数に値を代入

制御変数に値を代入することは許されませんが、Turbo Pascal では可能でした。
image.png

See also:

(4.4.4.) for in do 文

・for in do (拡張 Pascal の場合)

この構文は拡張 Pascal にもありました。

program ForInDo(output);
var
  i: Integer;
begin
  for i in [100, 200, 100] do
    Writeln(i);
end.

・for in do (Pascal 8000 の場合)

Pascal 8000 には forall in do がありました。

forall i in [1, 3, 4, 6] do
  flag[i] := True;

See also:

(4.4.4.1.) 配列式を使った反復処理

(4.4.4.2.) 文字列式を使った反復処理

(4.4.4.3.) 集合式を使った反復処理

(4.4.4.4.) コレクション式を使った反復処理

(4.4.5.) break と continue

・break と continue の由来

この拡張は Turbo Pascal 7.0 以降のようです。MPW Pascal にはそれ以前に leavecycle が存在しました。

C Apple Borland
break leave Break
continue cycle Continue

そもそもの由来は C 言語だと思います。

標準 Pascal でこれらに近い事をやりたいのであれば、制御変数ともう一段のループを使うか goto 文を使います。

・類似の機能

Pascal 8000 には無限ループを構成する loop~end 構文と、それから脱出するための exit がありました。

loop
  i := i + 1;
  if a[i] = 0 then
    exit;
  j := j - 1;
end;

この構文は Modula-2 にもあります。

See also:

4.5. 条件式

4.5.1. if 文

4.5.2. case 文

case 文のケースセレクタの最後には空のケースセレクタが許されます。

  case i of
    1: a := 1; 
    2: a := 2;
    3: a := 3
  end

  case i of 1:a:=1 ; 2:a:=2 ; 3:a:=3 end

つまりは end の前のセミコロンが許されます。

  case i of
    1: a := 1; 
    2: a := 2;
    3: a := 3; (* 空のケースセレクタ *)
  end

  case i of 1:a:=1 ; 2:a:=2 ; 3:a:=3 ; (* 空のケースセレクタ *) end

古い規格では、ケースセレクタ間に空のケースセレクタが許されていました。

・case 文の else の由来

case 文の拡張ですが、 Turbo Pascal には 1.0 から else が、その前身である BLS Pascal には others が、OS-9 PascalMPW Pascal には otherwise がありました。

// Turbo Pascal / Delphi
case n of
  1: v := 100;
  2: v := 200;
else
  v := 0;
end;

// BLS Pascal
case n of
  1:
    v := 100;
  2: 
    v := 200;
  others:
    v := 0;
end;

// OS-9 Pascal
case n of
  1:
    v := 100;
  2: 
    v := 200;
  otherwise:
    v := 0;
end;

// MPW Pascal
case n of
  1: v := 100;
  2: v := 200;
otherwise
  v := 0;
end;

otherwise 拡張は標準 Pascal の策定中にも検討されていたようです。

See also:

4.6. with 文

4.7. goto 文

(4.7.1.) Pascal と goto

・主語の大きな話をすべきではない

Linus Torvalds 氏が Linux カーネルで goto 文が使われている事に対する議論の中で

Of course, in stupid languages like Pascal,
where labels cannot be descriptive, goto's can be bad.

と述べています。意訳すると**「Pascal のようにラベルに識別子が使えないクソ言語で goto 使っちゃダメだろうけどね」**という事なのですが、先述の通り Delphi ではラベルに識別子が使えますし、Turbo Pascal でも使えました。

Linus 氏の発言は 2003 年の事ですが Pascal という大きな主語で語ってはいけませんよね。既に Delphi 誕生から 8 年、Turbo Pascal 誕生からなら 20 年経っていますので、氏の Pascal に対する知識はアップデートされていない事が伺い知れます (アップデートする必要もなかったのでしょうけれど)。

少なくともこの話をもって**「Linus 氏が言ってるから Pascal はクソ言語」と言ってはいけません。
image.png
Ed Post 氏の "Real Programmers Don't Use PASCAL (本物のプログラマはPascalを使わない)" にしても、デバッガを使わずにバグを修正するような
凄腕の Fortran 使い以外に言われる筋合いはない**話です。他の言語を使ってる人がこれを言ってきたら、まず中身を読んでいません。

"Why Pascal is Not My Favorite Programming Language (何故 Pascal はお気に入りのプログラミング言語ではないのか)" にしても、書いてるのは K&R の Brian W. Kernighan 氏ですので、話半分で聞いた方がいいかもしれません。前提が標準 Pascal なら言ってる事は正しいのですが Pascal という大きな主語だと正しくありません。

例えば MPW や MacApp の開発に携わった Dan Allen 氏は次のように述べています。

MPW Pascal overcomes most of Brian Kernighan's objections to Pascal included in his famous memo "Why Pascal Is Not My Favorite Programming Language."

拡張 Pascal の仕様からの反論もあります。

The criticisms in Kernighan's paper have become outdated and mostly irrelevant with the implementation of Extended Pascal. The paper would not have been mentioned at all, except that the criticisms contained within the paper are used by many in the field today against current implementations of Pascal.

よって、今時この話を持ち出す人もまず中身を読んでいません。あるいは標準 Pascal と Delphi 等のモダンな Pascal との違いを説明できないでしょう。

この件に限りませんが、**"とあるものを持ち上げるために別のものを貶める"**という手法は悪手だと思います。

(4.8.) 文の正確な定義

索引

:ramen: [ ← 3. プログラムヘッダと宣言部〔裏〕 ] [ ↑ 目次へ ] [ → 5. 列挙型と部分範囲型〔裏〕) ]

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0