Presentation is loading. Please wait.

Presentation is loading. Please wait.

Euphoria Programming Language CSC 507 Kasilingam Vimalan.

Similar presentations


Presentation on theme: "Euphoria Programming Language CSC 507 Kasilingam Vimalan."— Presentation transcript:

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 Created by Robert Craig from Rapid Deployment Software First released in 1993 for 32-bit DOS platform. 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 Interpreter is available for Windows, DOS, Linux and FreeBSD can be downloaded freely form http://www.rapideuphoria.comhttp://www.rapideuphoria.com Can develop various applications such as Windows GUI programs, and Linux X Windows programs, CGI programs etc 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 Very simple language Interpreted language Interpreted language Automatic memory management and garbage collection. Automatic memory management and garbage collection. Runtime type checking ( it can be turned off at runtime). 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 it a collection of numeric value or atoms can have zero or more elements can have zero or more elements each element is either an atom or a sequence each element is either an atom or a sequence it can grow dynamically at runtime it can grow dynamically at runtime The first element in a sequence has an index of one [1] The first element in a sequence has an index of one [1] Example : sequence a, b, c, d, e, f sequence a, b, c, d, e, f a = {2, 3, 5, 7, 11, 13, 17, 19} 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} e = {} -- the 0-element sequence f = {x+6, 9, y*w+2, sin(0.5)}

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 : Arithmetic Operators : unary-, unary+, *, /, +, - Relational Operators: Relational Operators: = = != = = != Note: for string use equal() or compare() Logical Operators : Logical Operators : and, or, xor, not Other operator : Other operator : & - concatenation operator Precedence: function/type calls unary- unary+ not / + - & = = != = = != and or xor {,,, }

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 = 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} w = not {1, 5, -2, 0, 0} -- w is {0, 0, 0, 1, 1} w = {1, 2, 3} = {1, 2, 4} -- w is {1, 1, 0}

10 Subscripting/Slicing of Sequences x = {5, 7.2, 9, 0.5, 13} x[2] = {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}} } y[2][3][1] is 9 Array of strings: s = {"Hello", "World", "Euphoria", "", "Last One"} s = {"Hello", "World", "Euphoria", "", "Last One"} s[3] is "Euphoria" s[3][1] is 'E' Slicing of Sequences x = {1, 1, 2, 2, 2, 1, 1, 1} x = {1, 1, 2, 2, 2, 1, 1, 1} y = x[3..5] -- y is {2,2,2} y = x[3..5] -- y is {2,2,2} x[3..5] = {9, 9, 9} -- x is {1, 1, 9, 9, 9, 1, 1, 1} x[3..5] = {9, 9, 9} -- x is {1, 1, 9, 9, 9, 1, 1, 1}

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

12 If statement 1.if then <statement> end if 2. if then <statement>else<statement> end if 3. if then <statement> elsif then <statement>.. end if Example: if a < 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 = to [by ] do <statement> 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

14 while statement while do <statement> end while Example: i = 1 a = “hello” while i <= length(a) do ? a[i] 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. All arguments to routines are always passed by value. There is no pass-by-reference facility. There is no pass-by-reference facility. Sequences use copy-on-write semantics. Sequences use copy-on-write semantics.

16 Procedure procedure ([ ]) procedure ([ ]) 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 ([ ]) function ([ ])<statement> return return end function end function function max(atom a, atom b) if a >= b then return a else return b end if end function

18 function swap(sequence list, integer x, integer y) object tmp tmp = list[x] list[x] = list[y] list[y] = tmp return list end function procedure permute(sequence list, integer start) if start < 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 permute({1,2,3},1) Out put: {1,2,3}{1,3,2}{2,1,3}{2,3,1}{3,2,1}{3,1,2}

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

20 Bibliography 1. Euphoria programming language document http://www.rapideuphoria.com/manual.htm http://www.rapideuphoria.com/manual.htm 2. Wikipedia, the free encyclopedia http://en.wikipedia.org/wiki/Euphoria_programming_language


Download ppt "Euphoria Programming Language CSC 507 Kasilingam Vimalan."

Similar presentations


Ads by Google