April 22, 2008 § Leave a comment
Import statement is always different among programming languages. Not only the syntax, but also the concept of how codes are managed and called. Below are import statements from a couple of languages for your entertainment.
Python keeps track of its own modules (via PYTHONPATH) and perform import on those modules.
In Python, a module is just a file with definitions and statements. A module can also be a directory with __init__.py in it.
There are multiple ways of using import syntax in Python:
- import [identifier] #identifier can be Class, variable, or function name
- from [module_name] import [identifier] #specify which module do you want to import from
- from [module_name] import [identifier] as [alias] #alias your imported identifier
- from [package_name.submodule_name] import [identifier] #in Python you can have modules inside a package
Interestingly, Modula-3 seemed to have the same style of importing as Python.
Now let’s move on to Ruby’s require.
Ruby found its libraries, and all modules inside them, by checking each directory inside $LOAD_PATH.
At first glance, Ruby seemed to just know where all its modules are. The require statement doesn’t need any description about path/location at all. Passing the path helps readability though.
There’s not much to say here.
In short, when PHP interprets, it will appends all the imported files and evaluates them all at once.
To import, use:
Perl import statement is called use. I am not a Perl expert, but here is the syntax:
use [module_name] [list_of_imported_things]
Disclaimer: I am not LISP expert, these are things that I’ve read.
LISP codes are broken into packages. To import those packages, use this syntax:
Basically the syntax is:
- Python Reference Manual
- Dive into Python
- Modula-3 Reference
- The many facets of RubyGems
- LISP Package Concept