Xen / examples v0.1.0-demo.2
파일 읽기
선택한 언어나 버전에는 이 주제가 없어 같은 영역의 시작 페이지를 표시합니다.
파일 읽기
저장소나 배포본의 루트에서 실행합니다. xen을 PATH에 추가하거나 ./bin/xen으로 바꾸세요.
첫 명령은 현재 폴더의 input.txt를 만들거나 덮어씁니다. 경로가 하나 필요하며 없는 파일은 오류로 종료합니다.
printf 'one two\nthree four\n' > input.txtxen run examples/word_count.xen -- input.txt예상 출력
섹션 제목: “예상 출력”4전체 소스
섹션 제목: “전체 소스”// SPDX-License-Identifier: MIT OR Apache-2.0use std.env as env;use std.fs as fs;use std.io as io;use std.string as text;
fn count_file(path: String) -> Result<Int, io.IoError> { let contents = fs.read(path)?; return Result.Ok(text.split_ascii_whitespace(contents).len());}
fn main() { let arguments = env.args(); if arguments.len() != 1 { panic("usage: word_count <path>"); } match count_file(arguments.get(0)) { Result.Ok(count) => println(count), Result.Err(error) => { panic(io.describe_error(error)); }, };}실행 파일 만들기
섹션 제목: “실행 파일 만들기”xen build examples/word_count.xen -o app생성한 실행 파일은 호환되는 Linux에서 실행하세요.