• Stars
    star
    280
  • Rank 147,492 (Top 3 %)
  • Language
    Zig
  • License
    BSD 3-Clause "New...
  • Created about 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

dt - duct tape for your unix pipes

License

dt

It's duct tape for your unix pipes. A programming language for doing small stuff fast, easy, and readable.

In the words of Red Green:

Remember, it's only temporary... unless it works!

Note: The dt User Guide exists but is still in progress. Basic usage is shown in the instructions below.

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.

$ seq 3 | dt rev pls
3
2
1

Great for aliases:

$ alias scream-lines="dt [upcase words unlines] map pls"
$ echo "hey you pikachu" | scream-lines
HEY
YOU
PIKACHU

If you want to read lines manually, use stream as the first command:

$ alias head.dt="dt stream [rl pl] args last to-int times"
$ seq 100 | head.dt 3
1
2
3

Use as a shebang

When the first argument to dt is a file starting with #! it will interpret the file. In short: dt supports shebang scripting.

A naive tee implementation:

tee.dt

#!/usr/bin/env dt

readln unlines   \stdin :
args pop   \file :

stdin pl
stdin file writef

Then use like:

cat wish-list | sed 's/red/green/g' | tee.dt new-wish-list

Interactive mode

Running dt by itself with no pipes in or out starts a read-eval-print loop (REPL).

$ dt
dt 1.x.x
Now, this is only temporary... unless it works.
» # Comments start with #
»
» 1 1 + println
2
»
» # Printing is common, so there are a bunch of printing shorthands.
» # "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   drop
1 2 4 8 16 32 64
»
»
» # You can conditionally execute code
»
» ["hi" pl] false do?
» ["bye" pl] true do?
bye
»
» quit

For a best experience, also install rlwrap and set a shell alias like so:

$ alias dtsh='rlwrap dt'
$ dtsh
dt 1.x.x
Now, this is only temporary... unless it works.
»

The above example assumes a bash-like shell. Details on the syntax and configuration files to set an alias that persists will vary by your shell.

Installing

The nerdy stuff

The dt language is a functional programming language, and a concatenative language, with a very imperative feel. For those interested, the user guide has a more in-depth discussion of the language classification.

dt is implemented in Zig with no plans to self-host or rewrite in Rust or Go. Please do suggest better strategies for memory management and optimizations! I have some experience working at this level, but still much to learn. The current implementation is still fairly naive.

Credits

Shared as open source software, distributed under the terms of the 3-Clause BSD License.

By J.R. Hill | https://so.dang.cool | https://github.com/booniepepper

More Repositories

1

z

Z is a Java library providing accessible, consistent function combinators.
Java
28
star
2

zig-data-structures

Zig
13
star
3

rank

Sigi - a tool for organizing
Rust
13
star
4

rail

Rail programming language
Rust
4
star
5

czbi

Install Zig-built-from-source executables
Shell
3
star
6

yaml2toml

Converts yaml files to toml files
Python
3
star
7

singleton

Dirt-simple Java implementation of Singleton. Great for those who don't want a number of different roll-your-own (potentially faulty) implementations.
Java
3
star
8

adventofcode-solutions

It's me solving some problems: https://adventofcode.com
Go
3
star
9

uxnbot

uxnbot for chat platforms
C
3
star
10

exercism-solutions

exercism.io solutions
Haskell
2
star
11

jumble

Java
2
star
12

findup

Find parent directories
Zig
2
star
13

stap

Rust
2
star
14

codewars-solutions

Code wars, code golf, general hacking and mayhem.
JavaScript
2
star
15

hack-assembler

Hack assembler
Crystal
1
star
16

clobar

Get a Clojure repl in your JVM project.
Clojure
1
star
17

pair

Java
1
star
18

advent-of-dt

Haskell
1
star
19

dsg-posix

Shell
1
star
20

raise-shell

Shell
1
star
21

crystal-chars-vs-codepoints-bench

Simple benchmark between using `chars` and `codepoints` in Crystal.
Crystal
1
star
22

lyle

Rust
1
star
23

hop

Higher-Order Programs
1
star
24

booniepepper

GitHub profile
1
star
25

kamajii

Haskell
1
star
26

nourish

A game about growth
JavaScript
1
star
27

dt-vscode-extension

Syntax highlighting for dt in VS Code
1
star
28

levee

Java
1
star
29

fib

A Fibonacci CLI
Haskell
1
star
30

hello

hello world in a few languages
Makefile
1
star
31

nand2tetris

Assembly
1
star
32

so.dang.cool

Website for J.R. Hill
HTML
1
star
33

shell-fiddles

1
star
34

dsg-md-posix

Dumb Site Generator (Markdown via Pandoc + POSIX)
Shell
1
star