Oil Language FAQ - oils-for-unix/oils GitHub Wiki
This is an initial cut of FAQ based on questions from lobste.rs.
You may want to read A Tour of the Oil Language before this FAQ.
Design of the Syntax
setvar
keyword?
Why is there an explicit It's more consistent to parse and explain if we say that expressions are introduced to the right of var
, const
, and setvar
. Recall that Oil has both expression mode and command mode.
The syntax is intended to be "huffman coded": mutation with setvar
is less common than const
, IMO.
Note that a bare x = 42
does work for config files in Oil, but that requires shopt --set parse_equals
(because x = 42
in shell runs a command named x
with arguments =
and 42
!).
But we want a syntax for mutation that does not change between oil:basic
and oil:all
. That is, we want two languages (OSH and Oil), not three!
In shell/OSH it's x=mystr
(no spaces); in Oil it's setvar x = 'mystr'
(quotes required).
proc
?
Why is the keyword called It's an abstraction that can be thought of as either a "procedure" or "process". Like an external binary, it can serve both purposes.
July 2021: The func
construct will likely be built on top of proc
, but it isn't done yet.
d->key
rather than d.key
?
Why I wanted to emphasize that the key may not exist. I think the d.key
syntax should be reserved for a more static record.
Also, Python has a distinction between dict keys and object attributes. (But JavaScript doesn't.)
d->key
and d['key']
?
What's the difference between The former is syntactic sugar for the latter. You could d['key']
everywhere, and the program would still work.
If you have a key like d['with spaces']
, you have to use the bracketed form. Something like d->with spaces
is a syntax error because of the space.
!
and not
?
Why is there both The !
inverts an exit code; while the not
operator inverts a Python- / JS- like boolean.
The !
is only accepted in command mode; and not
is only accepted in expression mode.
read :x
and json read :x
?
Why the colon in It's a "pseudo-sigil" that means "this variable is mutated" or "this variable is referenced". It's optional but I think it makes the code easier to read.