From c8733c613455b6588fdf47c5b8350aefcd0504ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BD=88=EF=BD=89=EF=BD=8C=EF=BD=8A=EF=BD=95=EF=BD=93?= =?UTF-8?q?=EF=BD=94=EF=BD=89?= Date: Wed, 5 Jul 2023 01:01:00 -0700 Subject: [PATCH] Bump to 0.9.0, update README and other miscellany --- README.md | 74 +++++++++++++++++++++++++++++---------- build | 2 ++ build.zig.zon | 2 +- old-rust-tests/Cargo.lock | 4 +-- old-rust-tests/Cargo.toml | 4 +-- src/builtins.zig | 2 +- src/main.zig | 10 +++--- 7 files changed, 68 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 18db3e3..3ac381a 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,43 @@ # `dt` -It's duct tape for your unix pipes. Use it when you don't have a better tool. +It's duct tape for your unix pipes. A shell-friendly concatenative language +for when you don't have a better tool. In the words of [Red Green](https://www.redgreen.com): > Remember, it's only temporary... unless it works! -## For pipes: +## Explore the REPL + +``` +$ dt +dt 0.9.0 +» # Comments start with # +» +» 1 1 + println +2 +» +» # "p" is print, "pl" is print line, "pls" is print lines (i.e. of a list of values) +» # Let's define a command that consumes a value, prints it, then returns its double +» +» [ \n : n p " " p n 2 *] \print-and-double def +» +» # And let's do it... 7 times! +» +» 1 \print-and-double 7 times pl +1 2 4 8 16 32 64 128 +» +» # Also there are conditions +» +» ["hi" false ? "bye" true ?] do pl +bye +``` + +## Use in pipes + +When piping in/out, the REPL is skipped. If something is piping into `dt` then +standard input is fed into `dt` as a list of lines. ``` $ echo -e "3\n2\n1" | dt rev pls @@ -23,37 +53,43 @@ YOU PIKACHU ``` -## Running as an interactive shell: +## Use as a shebang + +When the first argument to `dt` is a file starting with `#!` it will interpret +the file. -`dt` is an experimental [concatenative](https://concatenative.org/wiki/view/Concatenative%20language) -programming language. +A naive tee implementation: + +`tee.dt` ``` -$ dt -dt 0.8.0 +#!/usr/bin/env dt -> 1 1 + print -2 +get-lines unlines \stdin : +get-args pop \file : -> [[ n ]: n print " " print n 2 *] [print-and-double] def +stdin pl +stdin file writef +``` -> 1 [print-and-double] 7 times -1 2 4 8 16 32 64 +Then use like: -> [[false] ["bye"] [true] ["hi"]] ? println -hi +``` +cat wish-list | sed 's/red/green/g' | tee.dt new-wish-list ``` ## Downloads -Download assets from [releases](https://github.com/hiljusti/dt/releases/) and put them somewhere on your PATH. +Download assets from [releases](https://github.com/hiljusti/dt/releases/) and +put them somewhere on your PATH. -## Building from source +An installation script will come soon. -Most people should not need to do this. +## Building from source -To build from source, clone the repo and run `./build` with Zig 0.11.+ and a recent -Cargo toolchain. The resulting binary will be in `./zig-impl/zig-out/bin/dt` +To build from source, clone the repo and run `./build help` for instructions. +The project currently builds with Zig 0.11.+ and a recent Cargo toolchain. The +resulting binary for your machine will be produced in `./zig-out/bin/dt` ## Credits diff --git a/build b/build index 3370f5b..f9d6135 100755 --- a/build +++ b/build @@ -11,6 +11,8 @@ help() { clean() { rm -rf ./zig-cache ./zig-out + cd "$project_root"/old-rust-tests || exit 1 + cargo clean } build() { diff --git a/build.zig.zon b/build.zig.zon index 3ae0ab9..41285f3 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,5 +1,5 @@ .{ .name = "dt", - .version = "0.8.0", + .version = "0.9.0", .dependencies = .{}, } diff --git a/old-rust-tests/Cargo.lock b/old-rust-tests/Cargo.lock index 1c610fe..68082b5 100644 --- a/old-rust-tests/Cargo.lock +++ b/old-rust-tests/Cargo.lock @@ -3,5 +3,5 @@ version = 3 [[package]] -name = "dt-tool" -version = "0.8.0" +name = "dt-tests" +version = "0.1.0" diff --git a/old-rust-tests/Cargo.toml b/old-rust-tests/Cargo.toml index 380aa23..d2ba8c5 100644 --- a/old-rust-tests/Cargo.toml +++ b/old-rust-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "dt-tool" -version = "0.8.0" +name = "dt-tests" +version = "0.1.0" authors = ["J.R. Hill "] description = "dt - it's duck tape for your unix pipes" license = "GPL-2.0-only" diff --git a/src/builtins.zig b/src/builtins.zig index c19bfd3..f5f4e21 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1000,7 +1000,7 @@ pub fn do(state: *RockMachine) !void { var jail = try state.child(); jail.nest = state.nest; - if (val.isCommand() or val.isDeferredCommand() or val.isString()) { + if (val.isCommand() or val.isDeferredCommand()) { const cmdName = try val.intoString(state); try jail.handleCmd(cmdName); diff --git a/src/main.zig b/src/main.zig index 413553a..9de0e42 100644 --- a/src/main.zig +++ b/src/main.zig @@ -17,7 +17,7 @@ const RockMachine = interpret.RockMachine; const builtins = @import("builtins.zig"); -pub const version = "0.8.0"; +pub const version = "0.9.0"; const stdlib = @embedFile("stdlib.dt"); @@ -32,13 +32,13 @@ pub fn main() !void { var toks = Token.parse(arena.allocator(), stdlib); while (try toks.next()) |token| try machine.interpret(token); - if (!std.io.getStdIn().isTty()) { + if (try readShebangFile(arena.allocator())) |fileContents| { + toks = Token.parse(arena.allocator(), fileContents); + return while (try toks.next()) |token| try machine.interpret(token); + } else if (!std.io.getStdIn().isTty()) { return handlePipedStdin(&machine); } else if (!std.io.getStdOut().isTty()) { return handlePipedStdoutOnly(&machine); - } else if (try readShebangFile(arena.allocator())) |fileContents| { - toks = Token.parse(arena.allocator(), fileContents); - return while (try toks.next()) |token| try machine.interpret(token); } return readEvalPrintLoop(&machine);