Euphoria Programming Language - PowerPoint PPT Presentation

About This Presentation
Title:

Euphoria Programming Language

Description:

Created by Robert Craig from Rapid Deployment Software ... Linux and FreeBSD can be downloaded freely form http://www.rapideuphoria.com ... – PowerPoint PPT presentation

Number of Views:135
Avg rating:3.0/5.0
Slides: 21
Provided by: Lena171
Learn more at: https://www.nku.edu
Category:

less

Transcript and Presenter's Notes

Title: Euphoria Programming Language


1
Euphoria Programming Language
  • CSC 507
  • Kasilingam Vimalan

2
Euphoria
  • End-User Programming with Hierarchical Objects
  • for Robust Interpreted Applications
  • Created by Robert Craig from Rapid Deployment
    Software
  • First released in 1993 for 32-bit DOS
    platform.
  • Interpreter is available for Windows, DOS,
    Linux and FreeBSD can
    be downloaded freely form
    http//www.rapideuphoria.com
  • Can develop various applications such as
    Windows GUI programs, and Linux X Windows
    programs, CGI programs etc

3
  • Key Features of Euphoria
  • Very simple language
  • Interpreted language
  • Automatic memory management and garbage
    collection.
  • Runtime type checking ( it can be turned off at
    runtime).

4
  • Two main Data Types
  • 1. Atom is a number that can be either 31-bit
    integer or 64-bit floating-point.
  • Example
  • atom a, b, c, d, e
  • a 'B' -- equivalent to the atom 66
  • b 0
  • c 1000
  • d 98.6
  • e -1e6

5
  • 2. sequence
  • it a collection of numeric value or atoms
  • can have zero or more elements
  • each element is either an atom or a sequence
  • it can grow dynamically at runtime
  • The first element in a sequence has an index of
    one 1
  • Example
  • sequence a, b, c, d, e, f
  • a 2, 3, 5, 7, 11, 13, 17, 19
  • b "abcd" - this is actually 97, 98,
    99,100
  • c 1, 2, 3, 3, 3, 4, 5, 6
  • d "jon", "smith", 52389, 97.25

6
  • Euphoria has two additional
  • specialized data types
  • 1. Integer is a special form of atom, restricted
    to 31-bit integer values in the range -1073741824
    to 1073741823.
  • 2. Object is a generic data type that can contain
    any of the above, and can be changed during
    run-time

7
  • Operators
  • Arithmetic Operators
  • unary-, unary, , /, , -
  • Relational Operators
  • lt   gt   lt   gt     !
  • Note for string use equal() or compare()
  • Logical Operators
  • and, or, xor, not
  • Other operator
  • - concatenation operator
  • Precedence
  • function/type calls

8
  • Expressions
  • In Euphoria one can perform an operation on
    entire sequences of data with one expression.
  • Examples
  • x 1,2,3 5
  • -- x is 6, 7, 8
  • x -1, 2, 3, 4, 5
  • --x is -1, -2, -3, -4, -5
  • x 5, 6, 7, 8 10, 10, 20, 100
  • -- x is 15, 16, 27, 108
  • w 1, 2, 3, 4, 5 4, 5, 6
  • -- w is 4, 8, 15, 20, 30

9
  • Logical Expression
  • Example
  • 5 and -4 -- 1 (true)
  • not 6 -- 0 (false)
  • Short-circuit evaluation of and and or takes
    place for if, elsif and while conditions only. It
    is not used in other contexts.
  • Examples with logical and relational
  • operators
  • x 1 or 1,2,3,4,5
  • -- x is 1,1,1,1,1
  • w 1, 0, 0, 1 and 1, 1, 1, 0
  • -- w is 1, 0, 0, 0

10
  • Subscripting/Slicing of Sequences
  • x 5, 7.2, 9, 0.5, 13
  • x2 11,22,33
  • Then x becomes 5, 11,22,33, 9, 0.5, 13
  • y
  • 1,1, 3,3, 5,5,
  • 0,0, 0,1, 9,1,
  • -1,9,1,1, 2,2
  • y231 is 9
  • Array of strings
  • s "Hello", "World", "Euphoria", "",
    "Last One"

11
  • user-defined types
  • type hour(integer x)
  • return x gt 0 and x lt 23
  • end type
  • hour h1, h2
  • h1 10 -- ok
  • h2 25 -- error! program aborts with a message

12
  • If statement
  • 1. if ltlogical expressiongt then
  • ltstatementgt
  • end if
  • 2. if ltlogical expressiongt then
  • ltstatementgt
  • else
  • ltstatementgt
  • end if
  • 3. if ltlogical expressiongt then
  • ltstatementgt
  • elsif ltlogical expressiongt then
  • ltstatementgt
  • elsif ltlogical expressiongt then

Example if a lt b then x 1 end if
if a 9 then x 4 y 5 else z 8
end if if char 'a' then x 1 elsif char
'b' then x 2 elsif char 'c' then x 3
else x -1 end if
13
  • for statement
  • for ltvariablegt ltstartgt to ltendgt by ltstepgt do
  • ltstatementgt
  • end for
  • Example
  • for i 1 to 10 do
  • ? i -- ? is a short form for print
  • end for
  • for i 10.0 to 20.5 by 0.3 do
  • for j 20 to 10 by -2 do
  • ? i, j
  • end for
  • end for

14
  • while statement
  • while ltlogical_expressiongt do
  • ltstatementgt
  • end while
  • Example
  • i 1
  • a hello
  • while i lt length(a) do
  • ? ai
  • i i 1
  • end while

15
  • Subprograms or routines
  • There are two types of routines Procedure and
    Function.
  • Parameters
  • All arguments to routines are always passed by
    value.
  • There is no pass-by-reference facility.
  • Sequences use copy-on-write semantics.

16
  • Procedure
  • procedure ltprocedure namegt(ltargumentsgt) ltstatem
    entgt
  • end procedure
  • Example
  • procedure plot(integer x, integer y)
  • position(x, y)
  • puts(1, '')
  • end procedure
  • Note Dose not allows to declare local variable

17
  • Functions
  • Function is very similar to procedure, but it
    returns a value, and can be used in an
    expression.
  • function ltfunction namegt (ltargumentsgt)
  • ltstatementgt
  • return ltreturn objectgt
  • end function
  • function max(atom a, atom b)
  • if a gt b then
  • return a
  • else
  • return b
  • end if
  • end function

18
  • function swap(sequence list, integer x, integer
    y)
  • object tmp
  • tmp listx
  • listx listy
  • listy tmp
  • return list
  • end function
  • procedure permute(sequence list, integer start)
  • if start lt length (list) then
  • for i start to length(list) do
  • permute(swap(list, start, i), start 1)
  • end for
  • else
  • ? list
  • end if
  • end procedure

19
  • Short comes
  • No object oriented programming support.
  • No exception handling.
  • No concurrency support.

20
  • Bibliography
  • 1. Euphoria programming language document
    http//www.rapideuphoria.com/manual.htm
  • 2. Wikipedia, the free encyclopedia
  • http//en.wikipedia.org/wiki/Euphoria_programming
    _language
Write a Comment
User Comments (0)
About PowerShow.com