Sleep (programming language)
Sleep | |
---|---|
Paradigms : | procedural , functional |
Publishing year: | 2004 |
Developer: | Raphael Mudge |
Current version : | 2.1 update 4 (April 30, 2009) |
Typing : | dynamic |
Influenced by: | Perl , Objective-C |
Operating system : | platform independent |
License : | LGPL |
sleep.dashnine.org |
Sleep is a procedural scripting language inspired by Perl and Objective-C . The only known implementation is written in Java and designed for easy integration with Java applications.
The Sleep Java API allows the language to be expanded to include new operators, functions and “environments”.
Sleep is for example in the IRC client jIRCii and the IRC - Bot SleepyBot used.
Overview
The properties of language
Dates, structures and types
Sleep has three different types of data: scalars, arrays, and hashes ( associative arrays ). Scalars start with a dollar sign ( $ ), arrays start with an at sign ( @ ), and hashes start with a percent sign ( % ).
Scalars
For example, a scalar can represent a character string or a number . Strings are literals or "parsed literals". Numbers are either integers or floating point numbers . Moreover, scalars can also represent any object references, for example when HOES are used.
Arrays
An array is a collection of scalars, hashes, or other arrays that can be addressed using a numeric index, starting with zero (0).
Hashes
Hashes are associative arrays and map keys to values. Keys can be numbers or strings.
Dynamic typing
Like many scripting languages, Sleep uses dynamic typing . This means that variables are not declared before use and must have been assigned a data type. This has certain advantages, but also certain disadvantages.
HOES
HOES (Haphazard Object Extensions for Sleep) are new in Sleep 2.0. These enable the creation and use of Java objects.
Code examples
"Hello World"
# Gibt "Hallo Welt" auf der Standardausgabe aus
println('Hallo Welt');
Strings
Literals
# Zuweisung eines Literals an einen Skalar
$string = 'Diese Zeichenkette ist ein Literal';
"Parsed literals"
$str1 = 'Variablen';
$str2 = 'werden';
$str3 = 'in geparsten Zeichenketten';
$str4 = 'ersetzt';
$string = "Prima, $str1 $str2 $str3 $str4";
println($string);
Output:
Prima, Variablen werden in geparsten Zeichenketten ersetzt
Concatenation
Strings are concatenated with the dot operator.
$punkt = '.';
$ende = 'verkettet.';
$string = 'Zeichenketten ' . 'werden mit dem ' . $punkt . " $ende";
println($string);
Output:
Zeichenketten werden mit dem . verkettet.
Arrays
@namen = array('Thomas','Michael','Andreas');
println( join( ', ', @namen ) );
Output:
Thomas, Michael, Andreas
Hashes
%person = hash( vorname => 'Thomas', nachname => 'Müller', alter => 33 );
println( 'Name: ' . %person['vorname'] . ' ' . %person['nachname'] );
println( 'Alter: ' . %person['alter'] . ' Jahre' );
Output:
Name: Thomas Müller
Alter: 33 Jahre
HOES
# Erzeugt einen JFrame und zeigt diesen an
import javax.swing.*;
$jframe = [new JFrame: 'Sleep HOES Beispiel'];
[$jframe setDefaultCloseOperation: [JFrame EXIT_ON_CLOSE]];
[[$jframe getContentPane] add: [new JLabel: 'Erstellt mit Sleep HOES']];
[$jframe pack];
[$jframe show];
Applications
Sleep is currently used in the following applications:
- jIRCii - Java IRC client
- SleepyBot - IRC bot
- After the Deadline - Open Source Speech Checking Technology