Warning: Work in progress! Leave feedback on Zulip or Github if you'd like this doc to be updated.

Oil Language Design Notes

These informal notes may help you understand Oil.

Table of Contents
It Mostly Borrows From Other Languages
Influences
POSIX Shell
bash and ksh
Python
JavaScript
Ruby
Perl
Go (library)
awk and make, find and xargs
Aside
Tcl
Paradigms and Style

It Mostly Borrows From Other Languages

Oil's design is more conservative than that of other alternative shells. It

Influences

POSIX Shell

For the command and word syntax:

ls | wc -l                       # pipeline
echo $var "${var} $(hostname)"   # variable and command sub
echo one; echo two               # sequence of commands
test -d /tmp && test -d /tmp/foo

Oil's own shell-like extensions:

echo $[1 + 2*3]                  # Expression substitution
echo $strfunc(x, y)              # Inline Function Calls

bash and ksh

We implement many bash semantics, like "named references" for out variables:

f() {
  local -n out=$1    # -n for named reference
  out=bar
}

myvar=foo
f myvar
echo $myvar          # prints "bar"

But clean up the syntax:

proc f(:out) {       # "out param" declared with :
  setref out = 1
}

var myvar = 'foo'
f :myvar             # caller prefixes the var name with :
echo $myvar          # prints "bar"

Historical note: Usenix 93. korn shell was used for GUIs and such!

Python

For the expression language:

var i = 1 + 2*3
var s = 'yes' if mybool else 'no'

And proc signatures:

proc cp(src, dest='/tmp') {  # Python-like default value
  cp --verbose $src $dest
}

Differences:

JavaScript

For dict literals:

# Unquoted keys.  Sigil to avoid confusion with blocks.
d = %{name: 'Bob', age: 10}

d = %{[mystr]: 'value'}  # key expressions in []

And "structured programming" looks like C / Java / JavaScript:

if (x > 0) {
  echo 'positive'
} else {
  echo '0 or negative'
}

var x = 5
while (x > 0) {
  echo $x
  setvar x -= 1
}

Ruby

For blocks:

cd /tmp {
  echo $PWD  # prints /tmp
}
echo $PWD

(Julia has something like blocks too.)

And the syntax for references to variable names:

read :line                   # populate $line variable
push :myarray one two three  # append to array

Perl

For the @ character (which PowerShell also uses):

var myarray = %(one two three)
echo @myarray  # @ isn't a really sigil; it's the "splice" operator

echo @arrayfunc(x, y)

Perl can be viewed as a mixture of shell, awk, and sed. Oil is a similar agglomeration of related languages.

Go (library)

For the builtin flags syntax:

 mybuiltin --show=0  # turn a flag that's default true

It also uses a native UTF-8 representation of strings.

awk and make, find and xargs

Features influenced by these languages are planned, but not implemented.

Aside

Tcl

Oil uses proc and setvar, which makes it look a bit like Tcl:

 proc p(x) {
   setvar y = x * 2
   echo $y
 }

 p 3  # prints 6

But this is mostly "convergent evolution", and relatively superficial.

Oil isn't homoiconic like Tcl is. It avoids dynamic parsing. It also has a lot of syntax.

Paradigms and Style

Shell is already mix of:

Oil is:


Generated on Thu Sep 3 10:28:33 PDT 2020