Pyli/Modules

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

Modules

Pyli handles modules much like Python. Each Pyli file has its own namespace. The file that is being run, the main process, gets the name "main".

The core language features are all in "core".

Module Paths

Each system defines its own module paths. Modules are searched for in this manner:

  1. First, break the module name up on the '/'. The first parts represent the path from the main path that the module is located at.
  2. See if there is a file called paths/module-name.pyli
  3. If not, signal a condition.

There are several retries from that condition:

  • Try to look up and install the module globally
  • Try to look up and install the module locally
  • Substitute the module with a different one.

Note: I'd like to package modules into something like python eggs.

Module Versions

Modules should be installed with versions. How to do this? I am not sure yet, but I want to make sure you can load two different versions of the same module by giving them different names.

Functions

  • (import module...): Imports the named modules. This only assigns a global with the same name to the module object.
  • (import module version version ...): Imports the specified version. The version may be a version range, or a list of acceptable versions. If that is the case, then it needs to be a sub-expression.
  • (import module as alias ...): Imports the module with a special name.
  • (import (symbol...) from module ...) Imports the symbols from the module.

You can combine the above in a single statement for brevity.

(import
  math/rational
  math/complex as complex
  (foo bar) from baz)

Standard Library

Here are some modules that are part of the standard library:

  • core (included by default)
  • main (included by default)
  • math:
    • rational: Allows rationals
    • int: Allows ints and long ints.
    • complex: Allows complex (1+2i)
    • quaternion: Allows quats (1+2i+3j+4k)
    • matrix: Allows matrices of numbers, and accompanying matrix operations.
    • real: A real module, that handles real numbers by representing them abstractly.
  • datetime: Deal with dates and times.
  • language
    • parser: A generic parser.
    • lexer: A generic lexer.
    • regex: Regular expressions.
    • natural: Allows some standard features for dealing with writing natural languages.
  • os
    • file: Handle files.
    • socket: Handle socket programming in a semi-BSD manner.
    • env: Gather stuff from the environment.
    • optparse: Gather args from the command line and parse them.
    • exec: Run other programs.
  • media
    • image: Produce and read images.
    • video: Produce and parse movies.
    • audio: Produce and read audio.
    • ...