Comment detail

コマンドライン引数の取得 (Nested Flatten)
Limboでは、initの引数として文字列リストを得ます。
習慣的に、名前はargvまたはargs。

先頭がコマンド名、続いてa, b, c, d...

リストは、hd(先頭の値を取得)、tl(先頭を除いたリストを取得)を使って操作します。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
implement Argv;

include "sys.m";
    sys: Sys;
include "draw.m";

Argv: module
{
    init: fn(nil: ref Draw->Context, argv: list of string);
};

init(nil: ref Draw->Context, argv: list of string)
{
    sys = load Sys Sys->PATH;
    for(p := tl argv; p != nil; p = tl p)
        sys->print("%s\n", hd p);
}

Index

Feed

Other

Link

Pathtraq

loading...