Types in the Oils Runtime - OSH and YSH

Here are all types of values in the Oils runtime, organized for understanding.

Table of Contents
Eight Atoms
Five Mutable Types
Obj is for User-defined Types
Five Units of Code
Five Types for Reflection
Appendix
The JSON Data Model
Why Isn't Everything an Object?
Implementation Details
Related

Eight Atoms

Values of these types are immutable:

A type with one value:

The Str type is the only type shared between OSH and YSH.

Five Mutable Types

YSH containers:

A special YSH type for "out params":

Containers for bash compatibility in OSH:

Obj is for User-defined Types

Objects allow polymorphism. See YSH Objects.

Modules and types are represented by Obj instances of a certain shape, not by primitive types.

  1. Modules are Obj with attributes, and an __invoke__ method.
  2. Types are Obj with a __str__ method, and are often compared for identity.

In general, Objects are mutable. Do not mutate modules or types!

Five Units of Code

Values of these types are immutable:

Five Types for Reflection

Values of these types are immutable:

A handle to a stack frame:

Appendix

The JSON Data Model

These types can be serialized to and from JSON:

Why Isn't Everything an Object?

In YSH, the Obj type is used for polymorphism and reflection.

Polymorphism is when you hide different kinds of data behind the same interface.

But most shell scripts deal with concrete textual data, which may be JSON-like or TSV-like. The data is not hidden or encapsulated, and shouldn't be.

Implementation Details

These types used internally:

Related

Generated on Sun, 10 Nov 2024 13:11:50 -0500