YSH Expressions vs. Python

The YSH expression language borrows heavily from Python. In fact, it literally started with Python's Grammar/Grammar file.

This doc describes the differences, which may help Python users learn YSH.

If you don't know Python, A Tour of YSH explains the language from the clean-slate perspective.

(TODO: A separate doc could compare commands/statements like for and if.)

Table of Contents
Background
Literals
Like Python: numbers and lists
Changed: booleans, strings, dicts
Added
Omitted
Operators
Note: YSH Does Less Operator Overloading
Like Python
Changed
Added
Omitted
Syntax Compared With JavaScript
Semantics Compared
Versus Python
Versus JavaScript

Background

YSH has dynamic types, much like Python. These are the main data types:

Null Bool Int Float List Dict

Quick example:

var x = null
var y = f(true, 42, 3.14)
var z = [5, 6, {name: 'bob'}]

Literals

Every data type can be written as a literal. Literals generally look like Python, so this section describes what's the same, and what's changed / added / and removed.

Like Python: numbers and lists

Changed: booleans, strings, dicts

Added

Omitted

Operators

Like literals, YSH operators resemble Python operators. The expression 42 + a[i] means the same thing in both languages.

This section describes what's the same, and what's changed / added / removed.

Note: YSH Does Less Operator Overloading

YSH doesn't overload operators as much because it often does automatic StrInt conversions (like Awk):

Like Python

Changed

Added

Omitted

Syntax Compared With JavaScript

This section may be useful if yo know JavaScript.

Semantics Compared

The runtime behavior of YSH is also similar to Python and JavaScript.

Versus Python

Versus JavaScript

Generated on Mon, 18 Nov 2024 05:42:37 +0000