Command-line arguments, as C hands them over: MAIN may take 'argc' and 'argv', the program's name first, each word NUL-ended, a null pointer after the last.
args.zg
# Command-line arguments, as C hands them over (owner, 2026-09-29: "low-level shit, decided"): MAIN may# take 'argc' and 'argv', the program's name first, each word NUL-ended, a null pointer after the last.# Reading them is C's world, so it is no_check; a friendly list will be written in Zag on top.# examples/args.args holds the words the test passes: apples, 3, hello world.MAIN['argc':int32,'argv':ptr[ptr[uint8]]]{std::print.stored["argc = ",'argc',newln];letmut'i':int32=1;while'i'<'argc'{no_checklet'word':=ptr.read[ptr.at['argv',by'i']];letmut'k':int32=0;letmut'bytes':list[uint8]=[];loop{no_checklet'b':=ptr.read[ptr.at['word',by'k']];if'b'equal_to0{break;}list.append[lend.mut'bytes',value'b'];change'k'='k'plus1;}let'text':=to.str.utf8['bytes']otherwise"(not UTF-8)";# bytes into text (owner, 2026-09-30)std::print.stored["argument ",'i',": ",'text',newln];change'i'='i'plus1;}no_checklet'end':=ptr.read[ptr.at['argv',by'argc']];std::print.stored["argv[argc] is null: ",ptr.is_null['end'],newln];}
Output
Run with apples3hello world
argc = 4
argument 1: apples
argument 2: 3
argument 3: hello world
argv[argc] is null: true