Hello World (E)

From LiteratePrograms

Jump to: navigation, search
Other implementations: Ada | ALGOL 68 | Alice ML | Amiga E | Applescript | AspectJ | Assembly Intel x86 Linux | Assembly Intel x86 NetBSD | AWK | bash | BASIC | Batch files | C | C, Cairo | C, Xlib | Candle | Clojure | C++ | C# | Delphi | Dylan | E | Eiffel | Erlang | Forth | FORTRAN | Fortress | Go | Groovy | Haskell | Hume | IBM PC bootstrap | Inform 7 | Java | Java, Swing | JavaScript | LaTeX | Lisp | Logo | Lua | Maple | MATLAB | Mercury | OCaml/F Sharp | occam | Oz | Pascal | Perl | PHP | Pic | PIR | PLI | PostScript | Prolog | Python | Rexx | Ruby | Scala | Scheme | Seed7 | sh | Smalltalk | SQL | Standard ML | SVG | Tcl | Tcl Tk | Visual Basic | Visual Basic .NET | XSL

E is an object-oriented language for secure distributed programming. This article presents a simple example of E's basic syntax. To run this example, you will need to install E - see ERights.org, the E language website, for more information.

This is a simple E program that prints the classic "Hello World!" string to the console, then prints the integers 1 through 10 using a simple for loop.

Printing a greeting is as simple as

<<print greeting>>=
println("Hello World!")

Printing the first 10 integers can be implemented (using a range) like this:

<<print first ten integers>>=
for i in 1..10 {
  println(i)
}

Presently, E is primarily used as a scripting language via the rune interpreter. To complete the E script, we add a shell declaration which indicates the script should be run using rune, and a pragma.syntax line to define which version of the E language we are assuming:

<<hellowworld.e>>=
#!/usr/bin/env rune
pragma.syntax("0.9")
print greeting
print first ten integers

The script will also work on platforms that don't have a Unix-style shell (e.g. Windows), but must be invoked in a more roundabout fashion:

java -jar %EHOME%\e.jar --rune helloworld.e

where %EHOME% is the directory in which E was installed.

Regardless of which way helloworld.e is run, the output should look like this:

$ ./helloworld.e 
Hello World!
1
2
3
4
5
6
7
8
9
10

References

  • ERights.org - the E language website
  • Wikipedia entry on the E programming language
Download code
Views
Personal tools