Sleep programming language
From Wikipedia, the free encyclopedia
Sleep (as of Simple Language for Environment Extension Purposes) is a procedural scripting language inspired by Perl and Objective-C. The only known implementation of the language is written in Java and is intended for embedding into existing Java applications to provide scripting services.
The Sleep Java API allows the language to be extended with new constructs, operators, functions, and variable containers, making it easy to integrate it into applications.
Sleep is currently utilized in the IRC client JIRCii and the IRC bot SleepyBot.
Contents |
[edit] Overview
Sleep is very easy to learn in its basic form, and anyone familiar with Perl or PHP will feel right at home. In addition to being embeddable, Sleep can also be used stand-alone on the command line or using an interactive shell.
[edit] Language features
[edit] Data structures and types
Sleep has native support for three widely different data types: scalars, arrays, and hashes. Scalars are prefixed with a dollar sign ($), arrays with 'at'-signs (@) and hashes with percentage signs (%).
[edit] Scalars
Scalars represent either a string, or a number. Strings can be specified in run-time as literals or as parsed literals. Numbers are either integers, or floating point. Scalars can also contain references to objects when utilizing the HOES subsystem.
[edit] Arrays
Arrays are a collection of scalars, hashes or other arrays referenced by an index number, starting at 0.
[edit] Hashes
Hashes are similar to arrays, but maps keys to values. Keys can be both strings and numbers.
[edit] Dynamic typing
Sleep is a dynamically typed language. This means that variables doesn't have to be declared, or typed, before being used. There are certain advantages to this, and also certain disadvantages.
[edit] Input/output
Included in Sleep is support for basic input/output. This includes readng and writing from/to files and sockets.
[edit] Serialization
Parsed Sleep scripts can be serialized and saved to disk. This means faster execution of scripts since the script interpreter can skip the parser and scanner steps.
[edit] HOES
HOES is a feature that lets the scripter manipulate Java objects using a syntax similar to Objective-C. Objects and primitives can be referenced via ordinary Sleep scalars.
[edit] Easy integration
Sleep is integrated into Java applications using the concept of "programmatical bridges". These bridges act as a proxy between the Sleep scripts and the application they're run for. Bridges are written in Java, and there is extensive documentation and tutorials on how to write them.
Sleep supports the following bridge types:
- Loadable bridges
- Function bridges
- Operator bridges
- Predicates bridges
- Evaluation bridges
- Variable bridges
- Environment bridges
- Filtered environment bridges
- Predicate environment bridges
Bridges can also act as "modules", as in expanding the API available to the scripts. For example, a JDBC module is underway, providing advanced database connectivity to Sleep scripters. Several other similar modules are also being planned to expand Sleep with XML/XSLT capabilities, improved sockets with support for UDP, Swing GUI, and more.
[edit] Applications
Sleep is currently being used actively in the following applications:
[edit] Code examples
[edit] "Hello world"
# This example outputs "Hello world!" to stdout println("Hello World!");
# Usage: format(subject, repl1, repl2, ...,); # Example: format('a {0} c', 'b'); # returns 'a b c' sub format { local('$subject @args $idx $match'); @args = @_; $subject = removeAt(@args, 0); foreach $i => $arg (@args) { $match = '{' . $i . '}'; $subject = strrep($subject, $match, $arg); } return $subject; }
[edit] =
[edit] Arrays and hashes
[edit] Loops
[edit] I/O
[edit] HOES
[edit] Status and History
Sleep first version appeared in a week-end of coding in April 2002. Since then Sleep has been developed in parallel with a Java IRC Client which heavily uses its features called jIRCii. The current stable 2.0 version is available since July 2005. The new 2.1 development version is still in the Beta cycle phase.