Skip to content

Commit

Permalink
Bump to 0.9.0, update README and other miscellany
Browse files Browse the repository at this point in the history
  • Loading branch information
booniepepper committed Jul 5, 2023
1 parent ee363df commit c8733c6
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 30 deletions.
74 changes: 55 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions build
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ help() {

clean() {
rm -rf ./zig-cache ./zig-out
cd "$project_root"/old-rust-tests || exit 1
cargo clean
}

build() {
Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.{
.name = "dt",
.version = "0.8.0",
.version = "0.9.0",
.dependencies = .{},
}
4 changes: 2 additions & 2 deletions old-rust-tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions old-rust-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dt-tool"
version = "0.8.0"
name = "dt-tests"
version = "0.1.0"
authors = ["J.R. Hill <hiljusti@so.dang.cool>"]
description = "dt - it's duck tape for your unix pipes"
license = "GPL-2.0-only"
Expand Down
2 changes: 1 addition & 1 deletion src/builtins.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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);
Expand Down

0 comments on commit c8733c6

Please sign in to comment.