Pyli/Built-in Types

From Jonathan Gardner's Tech Wiki
Jump to: navigation, search

Introduction

Pyli is a strongly typed, dynamic environment. This means that every value has a type that cannot change, but variables may point to different types of values upon assignment.

Internal Structure

The internal structure follows Python's internal object structure, roughly.

Every value has a type and a value. The type declares what the value of the value means.

The following are the various types:

  • Object: Includes all Objects, Object itself, as well as any extensions of other types.
  • Integer
  • Float
  • Decimal
  • Vector
  • Dict
  • Set
  • File
  • ... user extended types ...

They are each handled in a unique way for the various methods.

Type vs. Parent

The concept of 'type' is different than that of 'parent'. The 'parent' declares only what object the object was extended from. The 'type' declares how the internal data is stored. In general, the type is meaningless to the programmer and is not exposed in Pyli. In general, the parent may not correspond to the type of an object.

Attributes

You can access, assign, and delete attributes of an object.

  • (attr object attribute-name): Returns the value for the attribute, or signals an "attribute-error".
  • (set-attr object attribute-name value): Sets the attribute to the value.
  • (delete-attr object attribute-name): Deletes the attribute or signals an "attribute-error".

You can enumerate the attributes as well:

  • (attrs-of object): Returns an iterator for all the attribute names of an object.



Object

The most fundamental object is Object.

  • parent: Object
  • get-attr: Default get-attr.
  • set-attr: Default set-attr.
  • delete-attr: Default delete-attr.

NOTE: You should not make changes to this object, as 'everything will change.

Internally, all objects are instances of Pyli_Object_Class. Object itself is pyli_Object.




Truth

New instances of Truth cannot be instantiated. Only True and False are instances of Truth.

A call to Truth will return True or False, depending on its truth value. Note that everything but False is considered True.

True
False
(Truth False) # False
(Truth True)  # True
(Truth 0)     # True
(Truth [])    # True
(type False)  # Truth
(type True)   # Truth
(Int True)    # 1, same as float, decimal.
(Int False)   # 0, same as float, decimal.
(Bytes True)  # (Bytes '\x01')
(Bytes False) # (Bytes '\x00')

Attributes:

  • parent: Object
  • call: Returns True or False depending on the truth of the item. May call item.truth to figure it out.

Internally, Truth is an instance of Pyli_Truth_Class. Truth itself is pyli_Truth.

NOTE: You should not make changes to this object as True and False may change their behavior.

Integer

Integers can represent any whole number of any magnitude.

See /Integer

Float

Floats are floating-point numbers in base-2 and are limited by the platform.

See /Float

Decimal

Decimals are floating-point numbers in base-10 and do not lose precision.

Why decimals? Because floats are not enough for handling exact transactions with fractions. Rationals would be more than enough---most people don't care about anything but base-10 and the rational algorithms are fundamentally slower than the decimal ones. Until our culture changes, decimals will be useful.

10.00d # Decimal 10.00
(Decimal 5)

Text

Text represents a series of unicode code points.


Bytes

Bytes represents a series of bytes--8 bit numbers.

Vector

A vector is an array of items of any type. See /Vector.

Dict

A dict is a hash table of keys and items of any type. See /Dict.

Functions and Macros

A function takes parameters, evaluates them, and returns a result. See /Function

A macro takes parameters as expressions (Lists) and returns a result. See /Macro

Both functions and macros can be compiled into code. Code can be executed, but it is not passed the parameters already evaluated. That means that a function has, included, the code to evaluate its arguments.

Environment

Environments are a special type used to represent the environment associated with a scope. See /Environment.

Stack-Frame

Stack-Frames represent a frame on the stack. See /Stack-Frame

Iterators

The built-in iterators are:

See /Iterators.

Extended Types

Types may be extended as needed. See Pyli/Object-Oriented Programming.