Skip to content
andychu edited this page Jul 21, 2021 · 13 revisions

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

Why is there an explicit setvar keyword?

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).

Why is the keyword called proc ?

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.

Why d->key rather than d.key ?

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.)

What's the difference between d->key and d['key'] ?

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.

Why is there both ! and not ?

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.

Why the colon in read :x and json read :x ?

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.

More

Clone this wiki locally