source | all docs for version 0.10.0 | all versions | oilshell.org
Warning: Work in progress! Leave feedback on Zulip or Github if you'd like this doc to be updated.
Oil's expression language borrows heavily from Python. In fact, it literally
started with Python's Grammar/Grammar
file.
This doc describes some differences, which may help Python users learn Oil.
If you don't know Python, see A Tour of the Oil Language.
123
, 1_000_000
, 0b1100_0010
, 0o755
, 0xff
1.023e6
(not in the first cut of Oil)['pea', 'nut']
true
, false
, and null
(like JavaScript) rather than True
, False
,
and None
(like Python). In Oil, types are spelled with capital letters."hello $name"
r'c:\Program Files\'
$'line\n'
.
\u{3bc}
instead of \u03bc
and \U000003bc
{age: 42}
{[myvar + 1]: 'value'}
{age}
\u{03bc}
\n
\\
\'
#'a'
%(pea nut)
is equivalent to ['pea', 'nut']
^(ls | wc -l)
^[1 + a[i] + f(x)]
^{42, verbose = true}
Oil doesn't overload operators as much because it often does automatic string <-> int conversion (like Awk):
a + b
is for addition, while a ++ b
is for concatenation.a < b
does numeric comparison (with conversion). cmp()
could be for
strings.+ - * / // %
, and **
for exponentiation< > <= =>
& | ~ ^ << >>
and or not
0 if cond else 1
s[i]
evaluates to an integer?s[i:j]
evaluates to a stringin not in
f(x, y)
*
and **
?=== !==
because we also have ~==
++
(not +
, which is always addition)s ~ /d+/
s ~~ '*.py'
42 ~== '42'
$
and @
mydict->key
as an alias for mydict['key']
%
. Use ${x %.3f}
instead.@
for matrix multiply.1:5:2
because 0::2
conflicts with
module::name
. This was only necessary for Tea, not Oil.==
and ~==
for exact and type-converting equality, while JS uses
===
and ==
.mydict->key
instead of mydict.key
. We want to distinguish between
attributes and keys (like Python does).and or not
while JS uses && || !
. In shell, && || !
are already used in the command language (but they're somewhat less
important than in Oil).0 if cond else 1
, while in JS it's cond ? 0 : 1
.s ++ t
for string concatenation rather than s + t
Oil's syntax is a mix of Python and JavaScript, but the semantics are closer to Python.
s[i]
returns an integer code point ("rune").runeAt()
and byteAt()
?true !== 1
. In Python, they are equal: True == 1
.in
for array/list membership. Only dict membership.++=
operator on strings doesn't exist.100 MiB
? This should be multiplication?