write

ここからは新カテゴリ、D言語

D言語を始めよう - D言語ツアー

標準出力はwriteで行う。

std.stdio - プログラミング言語 D 2.0

まず、

Downloads - D Programming Language

ここからダウンロード。

$ curl -fsS https://dlang.org/install.sh | bash -s dmd
Downloading https://dlang.org/d-keyring.gpg
######################################################################## 100.0%
Downloading https://dlang.org/install.sh
######################################################################## 100.0%
The latest version of this script was installed as ~/dlang/install.sh.
It can be used it to install further D compilers.
Run `~/dlang/install.sh --help` for usage information.

Downloading and unpacking http://downloads.dlang.org/releases/2.x/2.084.0/dmd.2.084.0.linux.tar.xz
######################################################################## 100.0%
Using dub 1.13.0 shipped with dmd-2.084.0

Run `source ~/dlang/dmd-2.084.0/activate` in your shell to use dmd-2.084.0.
This will setup PATH, LIBRARY_PATH, LD_LIBRARY_PATH, DMD, DC, and PS1.
Run `deactivate` later on to restore your environment.
$

で、

$ cd dlang/
$ ls
d-keyring.gpg  dmd-2.084.0  install.sh
$ cd ~
$ source $(~/dlang/install.sh dmd -a)
(dmd-2.084.0)$ dmd --version
DMD64 D Compiler v2.084.0
Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved written by Walter Bright
(dmd-2.084.0)$ dub --version
DUB version 1.13.0, built on Jan  2 2019
(dmd-2.084.0)$ deactivate
$

dlangディレクトリの下にinstall.shがあるので、使う時はsourceでactivateして、終わるときはdeactivateするみたい。
dmdコンパイラ、dubはパッケージ管理らしい。

(dmd-2.084.0)$ vi write.d 
(dmd-2.084.0)$ cat write.d 
import std.stdio; // 標準入出力
void main(){
  write("ABCDE"); // writeで"ABCDE"を出力.
}
(dmd-2.084.0)$ dmd write.d 
write.d(3): Error: function expected before (), not module write of type void
(dmd-2.084.0)$

こんな感じでstd.stdioをインポートして、writeで"ABCDE"を出力しようとしたが、なぜかコンパイルエラー・・・。
Wandboxでは、

[Wandbox]三へ( へ՞ਊ ՞)へ ハッハッ

いけたので、原因がまったくわからない・・・。

#dlang インストールスクリプトの使い方 - Kotet's Personal Blog

複数のバージョンを入れられるのでもしかしてとおもって、

$ ./install.sh install dmd-2.070.0
Downloading and unpacking http://downloads.dlang.org/releases/2.x/2.070.0/dmd.2.070.0.linux.tar.xz
######################################################################## 100.0%
Downloading and unpacking https://github.com/dlang/dub/releases/download/v1.11.0-alpha.1/dub-v1.11.0-alpha.1-linux-x86_64.tar.gz
######################################################################## 100.0%

Run `source ~/dlang/dmd-2.070.0/activate` in your shell to use dmd-2.070.0.
This will setup PATH, LIBRARY_PATH, LD_LIBRARY_PATH, DMD, DC, and PS1.
Run `deactivate` later on to restore your environment.
$

2.084.0より古い2.070.0をインストール。

$ source ~/dlang/dmd-2.070.0/activate

アクティベートして、

あらためて、これをコンパイルすると、

$ cat write.d 
// モジュールのインポート
import std.stdio; // 標準入出力

// main関数の定義
void main() // 戻り値はvoidでもいい.
{

  // "ABCDE"を出力.
  write("ABCDE\n"); // writeで"ABCDE"を出力.(writeは改行しないので"\n"を付加.)

}
$ source ~/dlang/dmd-2.070.0/activate
(dmd-2.070.0)$ ls
write.d
(dmd-2.070.0)$ dmd write.d 
(dmd-2.070.0)$ ls
write  write.d  write.o
(dmd-2.070.0)$ ./write 
ABCDE
(dmd-2.070.0)$ deactivate
$

このようにコンパイルも実行も成功した。
最新のはなぜかダメだった・・・。根本的な原因はなんだろうか・・・。
しばらくは安定している2.070.0でやっていき、問題なければ2.084.0でもやろう。

Sample/d/write/write/src/write at master · bg1bgst333/Sample · GitHub

(追記)

随分と時間が経ってしまいましたが、Twitterでのご指摘で解決しました。