Euphoria (programming language)

From Seo Wiki - Search Engine Optimization and Programming Languages

Jump to: navigation, search
Euphoria
Developer(s) Robert Craig
Stable release 3.1.1 / August 22, 2007
Operating system Cross-platform DOS32, WIN32, Linux, FreeBSD
Type Interpreted language
License BSD
Website www.rapideuphoria.com

Euphoria is an interpreted programming language created by Robert Craig of Rapid Deployment Software.

Contents

Introduction

Developed as a personal project to invent a programming language from scratch, Euphoria's first incarnation was created by Robert Craig on an Atari Mega-ST. It's named Euphoria as an acronym for "End-User Programming with Hierarchical Objects for Robust Interpreted Applications", although there is some suspicion that this is in fact a backronym. The first public incarnation of the language was for the 16-bit DOS platform and was released in July 1993. The original Atari version, to date, has not been released. As of the release of version 3.0.0 (October 17, 2006), it is open source.

Euphoria was developed with the following design goals:

  • Easier to learn and use than BASIC and with more-consistent high-level constructs
  • To use flat-form 32-bit memory to avoid complicated memory management and size/addressing limits
  • Debugging support and run-time error-handling
  • Subscript and type checking
  • Loose and strict variable typing
  • Programming via objects as types, user-defined or otherwise
  • Interpreted, with automatic memory management and garbage collection

With the release of version 2.5 the Euphoria interpreter was split into two sections: the front-end parser and the back-end interpreter. The front-end, open source, is now written in Euphoria instead of C. The front-end is also used with the Euphoria-to-C translator and the Binder.

Features

  • Heterogeneous collection types (sequences)
  • DOS graphics library
  • Debugger
  • Database system
  • Low-level memory handling
  • Windows API support
  • CGI programming

Execution modes

  • Interpreter
  • C translator (E2C) for standalone executables or dynamic linking
  • Bytecode compiler and interpreter (Shrouder)
  • The Binder binds the Euphoria source code to the interpreter to create an executable.

Use

Euphoria was primarily used by hobbyists for utility and computer game programming, but has proven useful for fairly diverse purposes. The primary strength seems to be the ease of handling dynamic collections of data of various types, most useful when dealing with string processing and image processing, which can be quite difficult in many languages. It has been used in artificial intelligence experiments, the study of mathematics, for teaching programming, and to implement fonts involving thousands of characters. Also, Euphoria has been proven to be a useful CGI programming language: the File Archive Search is written in Euphoria, for example.

Data types

Euphoria has two basic data types:

atom 
These are numbers, implemented as either 31-bit signed integer or 64-bit IEEE floating-point, depending on the current value. Euphoria dynamically changes the implementation to the most efficient one for the data item's current value.
sequence 
A vector which can have zero or more elements, where each element can be either an atom or another sequence. The number of elements in a sequence is not fixed; the coder can add or remove elements as required during run-time. Memory allocation and deallocation is automatically handled by reference counting. Individual elements are referenced using an index value enclosed in square brackets. The first element in a sequence has an index of one [1]. Elements inside embedded sequences are referenced by additional bracked index values, thus X[3][2] refers to the second element contained in the sequence that is the third element of X.

Additionally, Euphoria has two specialized data types:

integer 
A special form of atom, restricted to 31-bit signed integer values in the range -1073741824 to 1073741823 (-2^30 to 2^30-1). Integer data types are more efficient than the atom data types, but cannot contain the same range of values. Characters are stored as integers, eg coding ASCII-'A' is exactly the same as coding 65.
object 
A generic datatype that can contain any of the above, and can be changed during run-time. This means that if you have an object called X that is assigned the value 3.172, then later on you can assign it the value "ABC". Note that in fact, each element of a sequence is actually an object.

There is no character string data type, as these are represented by a sequence of integer values. However, because literal strings are so commonly used in programming, Euphoria interprets double-quote enclosed characters as a sequence of integers. Thus

"ABC"

is seen as if the coder had written:

{'A', 'B', 'C'}

which is the same as:

{65,66,67}

Hello World

 puts(1,"Hello World!\n")

Examples

Note: Code comments start with a double dash "--" and go through the end of line. There are no multi-line comments.

As brief examples, the following code

global function delete_item( object old, sequence group )
   integer pos
             -- Code begins --
   pos = find( old, group )
   if pos > 0 then
       group = group[1 .. pos-1] & group[pos+1 .. length( group )]
   end if
   return group
end function

looks for an old item in a group of items. If found, it removes it by concatenating all the elements prior to it with all the elements after it. The result is then returned. Note that elements in sequences are 1-based indexed. This means that the first element has an index of 1.

Simplicity is apparent in that the code clearly delineates its constructs with words. Instead of braces, semicolons, and question marks, you see phrases like 'if..then', 'end if', and 'end function'.

Flexibility is present; the item 'old' could be strings, numbers, images, or whole collections of data themselves. A different function for each data type isn't needed, nor does the programmer have to check the data types. This function will work with any sequence of data of any type, and requires no external libraries.

global function replace_item( object old, object new, sequence group )
   integer pos
             -- Code begins --
   pos = find( old, group )
   if pos > 0 then
       group[pos] = new
   end if
   return group
end function

Safety is present due to the fact that there are no pointers involved and subscripts are automatically checked. Thus the function cannot access memory out-of-bounds, and cannot go beyond the end of the sequence or before the beginning of it to corrupt the memory. There is no need to allocate or deallocate memory explicitly, and no chance of a leak.

The line

group = group[1 .. pos-1] & group[pos+1 .. length( group )]

shows some of the sequence handling facilities. A sequence can contain a collection of any types, and this can be sliced (to take a subset of the data in a sequence) and concatenated in expressions, with no need for special functions.

Version 2.5 introduces the new '$' symbol, which is used for "length(sequence)." So, the above example could be written in 2.5 as follows:

group = group[1 .. pos-1] & group[pos+1 .. $]

Parameter passing

Another feature is that all arguments to routines are always passed by value; there is no pass-by-reference facility. However, parameters are allowed to be modified locally (i.e. within the callee), which is implemented very efficiently as sequences have automatic copy-on-write semantics. In other words, when you pass a sequence to a routine, initially only a reference to it is passed, but at the point the routine modifies this sequence parameter, the sequence is copied and the routine updates only a copy of the original.

Comparable Languages

External links

Free downloads of Euphoria for the various platforms, packages, Windows IDE, Windows API libraries, a GTK+ wrapper for Linux, graphics libraries (DOS, OpenGL, etc).

cs:Euphoria (programovací jazyk) de:Euphoria (Programmiersprache) es:EUPHORIA fr:Euphoria (langage) gl:Euphoria nl:Euphoria ja:ユーフォリア (プログラミング言語) pl:Euphoria pt:Euphoria (linguagem de programação)

Personal tools

Served in 0.182 secs.