Euphoria – Library Routines

Euphoria – Library Routines ”; Previous Next A large number of library routines are provided. Some are built right into the interpreter, ex.exe, exw.exe or exu. Others are written in Euphoria and you must include one of the .e files in euphoriainclude directory to use them. To indicate what kind of object may be passed in and returned, the following prefixes are used − S.No Prefix & Description 1 x a general object (atom or sequence) 2 s a sequence 3 a an atom 4 i an integer 5 fn an integer used as a file number 6 st a string sequence, or single-character atom Predefined Types As well as declaring variables with these types, you can also call them just like ordinary functions, in order to test if a value is a certain type. integer − test if an object is an integer atom − test if an object is an atom sequence − test if an object is a sequence object − test if an object is an object (always true) Sequence Manipulation length − return the length of a sequence repeat − repeat an object n times to form a sequence of length n reverse − reverse a sequence append − add a new element to the end of a sequence prepend − add a new element to the beginning of a sequence Searching and Sorting compare − compare two objects equal − test if two objects are identical find − find an object in a sequence – start searching from element number 1 find_from − find an object in a sequence – start searching from any element number match − find a sequence as a slice of another sequence – start searching from element number 1 match_from − find a sequence as a slice of another sequence – start searching from any element number sort − sort the elements of a sequence into ascending order custom_sort − sort the elements of a sequence based on a compare function that you supply Pattern Matching lower − convert an atom or sequence to lower case upper − convert an atom or sequence to upper case wildcard_match − match a pattern containing ? and * wildcards wildcard_file − match a file name against a wildcard specification Math These routines can be applied to individual atoms or to sequences of values. sqrt − calculate the square root of an object rand − generate random numbers sin − calculate the sine of an angle arcsin − calculate the angle with a given sine cos − calculate the cosine of an angle arccos − calculate the angle with a given cosine tan − calculate the tangent of an angle arctan − calculate the arc tangent of a number log − calculate the natural logarithm floor − round down to the nearest integer remainder − calculate the remainder when a number is divided by another power − calculate a number raised to a power PI − the mathematical value PI (3.14159…) Bitwise Logical Operations These routines treat numbers as collections of binary bits, and logical operations are performed on corresponding bits in the binary representation of the numbers. There are no routines for shifting bits left or right, but you can achieve the same effect by multiplying or dividing by powers of 2. and_bits − perform logical AND on corresponding bits or_bits − perform logical OR on corresponding bits xor_bits − perform logical XOR on corresponding bits not_bits − perform logical NOT on all bits File and Device I/O To do input or output on a file or device you must first open the file or device, then use the routines below to read or write to it, then close the file or device. open() will give you a file number to use as the first argument of the other I/O routines. Certain files/devices are opened for you automatically (as text files) − 0 – standard input 1 – standard output 2 – standard error open − open a file or device close − close a file or device flush − flush out buffered data to a file or device lock_file − lock a file or device unlock_file − unlock a file or device print − print a Euphoria object on one line, with braces and commas {,,} to show the structure pretty_print − print a Euphoria object in a nice readable form, using multiple lines and appropriate indentation ? x − shorthand for print(1, x) sprint − return a printed Euphoria object as a string sequence printf − formatted print to a file or device sprintf − formatted print returned as a string sequence puts − output a string sequence to a file or device getc − read the next character from a file or device gets − read the next line from a file or device get_bytes − read the next n bytes from a file or device prompt_string − prompt the user to enter a string get_key − check for key pressed by the user, don”t wait wait_key − wait for user to press a key get − read the representation of any Euphoria object from a file prompt_number − prompt the user to enter a number value − read the representation of any Euphoria object from a string seek − move to any byte position within an open file where − report the current byte position in an open file current_dir − return the name of the current directory chdir − change to a new current directory dir − return complete info on all files in a directory walk_dir − recursively walk through all files in a directory allow_break − allow control-c/control-Break to terminate your program or not check_break − check if user has pressed control-c or control-Break Mouse Support (DOS32 and Linux) On Windows XP, if you want the DOS mouse to work in a (non-full-screen) window, you must disable QuickEdit mode in the Properties for the DOS Window. get_mouse − return mouse “events”

Euphoria – Date & Time

Euphoria – Date & Time ”; Previous Next Euphoria has a library routine that returns the date and time to your program. The date() Method The date() method returns a sequence value composed of eight atom elements. The following example explains it in detail − #!/home/euphoria-4.0b2/bin/eui integer curr_year, curr_day, curr_day_of_year, curr_hour, curr_minute, curr_second sequence system_date, word_week, word_month, notation, curr_day_of_week, curr_month word_week = {“Sunday”, “Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”} word_month = {“January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December”} — Get current system date. system_date = date() — Now take individual elements curr_year = system_date[1] + 1900 curr_month = word_month[system_date[2]] curr_day = system_date[3] curr_hour = system_date[4] curr_minute = system_date[5] curr_second = system_date[6] curr_day_of_week = word_week[system_date[7]] curr_day_of_year = system_date[8] if curr_hour >= 12 then notation = “p.m.” else notation = “a.m.” end if if curr_hour > 12 then curr_hour = curr_hour – 12 end if if curr_hour = 0 then curr_hour = 12 end if puts(1, “nHello Euphoria!nn”) printf(1, “Today is %s, %s %d, %d.n”, {curr_day_of_week, curr_month, curr_day, curr_year}) printf(1, “The time is %.2d:%.2d:%.2d %sn”, {curr_hour, curr_minute, curr_second, notation}) printf(1, “It is %3d days into the current year.n”, {curr_day_of_year}) This produces the following result on your standard screen − Hello Euphoria! Today is Friday, January 22, 2010. The time is 02:54:58 p.m. It is 22 days into the current year. The time() Method The time() method returns an atom value, representing the number of seconds elapsed since a fixed point in time. The following example explains it in detail − #!/home/euphoria-4.0b2/bin/eui constant ITERATIONS = 100000000 integer p atom t0, t1, loop_overhead t0 = time() for i = 1 to ITERATIONS do — time an empty loop end for loop_overhead = time() – t0 printf(1, “Loop overhead:%dn”, loop_overhead) t0 = time() for i = 1 to ITERATIONS do p = power(2, 20) end for t1 = (time() – (t0 + loop_overhead))/ITERATIONS printf(1, “Time (in seconds) for one call to power:%dn”, t1) This produces the following result − Loop overhead:1 Time (in seconds) for one call to power:0 Date & Time Related Methods Euphoria provides a list of methods which helps you in manipulating date and time. These methods are listed in Euphoria Library Routines. Print Page Previous Next Advertisements ”;

Euphoria – Short Circuit

Euphoria – Short Circuit Evaluation ”; Previous Next When a condition is tested by if, elsif, until, or while using and or or operators, a short-circuit evaluation is used. For example − if a < 0 and b > 0 then — block of code end if If a < 0 is false, then Euphoria does not bother to test if b is greater than 0. It knows that the overall result is false regardless. Similarly − if a < 0 or b > 0 then — block of code end if if a < 0 is true, then Euphoria immediately decides that the result true, without testing the value of b, since the result of this test is irrelevant. In General, whenever you have a condition of the following form − A and B Where A and B can be any two expressions, Euphoria takes a short-cut when A is false and immediately makes the overall result false, without even looking at expression B. Similarly, whenever you have a condition of the following form − A or B Where A is true, Euphoria skips the evaluation of expression B, and declares the result to be true. Short-circuit evaluation of and and or takes place for if, elsif, until, and while conditions only. It is not used in other contexts. For example − x = 1 or {1,2,3,4,5} — x should be set to {1,1,1,1,1} If short-circuiting were used here, you would set x to 1, and not even look at {1,2,3,4,5}, which would be wrong. Thus, short-circuiting can be used in if, elsif, until, or while conditions, because you need to only care if the result is true or false, and conditions are required to produce an atom as a result. Print Page Previous Next Advertisements ”;

Euphoria – Quick Guide

Euphoria – Quick Guide ”; Previous Next Euphoria – Overview Euphoria stands for End-User Programming with Hierarchical Objects for Robust Interpreted Applications. Euphoria”s first incarnation was created by Robert Craig on an Atari Mega-ST and it was first released in 1993. It is now maintained by Rapid Deployment Software. It is a free, simple, flexible, easy to learn, and interpreted but extremely fast 32-bit high-level programming language for DOS, Windows, Linux, FreeBSD and more. Euphoria is being used to develop Windows GUI programs, high-speed DOS games, and Linux/FreeBSD X Windows programs. Euphoria can also be used for CGI (Webbased) programming. Euphoria Features Here is the list of major features of Euphoria − It is a simple, flexible, powerful language definition that is easy to learn and use. It supports dynamic storage allocation which means variables grow or shrink without the programmer having to worry about allocating and freeing the memory. It takes care of garbage collection automatically. It is extremely faster than conventional interpreters such as Perl and Python. Euphoria programs run under Linux, FreeBSD, 32-bit Windows, and any DOS environment. Euphoria programs are not subject to any 640K memory limitations. It provides an optimizing Euphoria-To-C translator which you can use to translate your Euphoria program into C and then compile it with a C compiler to get an executable (.exe) file. This can boost your program speed by 2 to 5 times. Underlying hardware are completely hidden which means programs are not aware of word-lengths, underlying bit-level representation of values, byte-order etc. Euphoria installation comes along with a full-screen source debugger, an execution profiler, and a full-screen multi-file editor. It supports run-time error-handling, subscript, and type checking. It is an open source language and comes completely free of cost. Platform Requirements Euphoria is available on Windows, Linux, FreeBSD, and OSX. Here is the bare minimum version required with the following platforms − WIN32 version − You need Windows 95 or any later version of Windows. It runs fine on XP and Vista. Linux version − You need any reasonably up-to-date Linux distribution, that has libc6 or later. For example, Red Hat 5.2 or later works fine. FreeBSD version − You need any reasonably up-to-date FreeBSD distribution. Mac OS X version − You need any reasonably up-to-date Intel based Mac. Euphoria Limitations Here are some prominent limitations of Euphoria − Even though Euphoria is simple, fast, and flexible enough for the programmers; it does not provide call support for many important functionalities. For example, network programming. Euphoria was invented in 1993, and still you would not find any book written on this language. There is also not much documentation available for the language. But these days, the language is getting popular very fast and you can hope to have nice utilities and books available for the language very soon. Euphoria Licensing This product is free and open source, and has benefited from the contributions of many people. You have complete royalty-free rights to distribute any Euphoria programs that you develop. Icon files, such as euphoria.ico and binaries available in euphoriabin, may be distributed with or without your changes. You can shroud or bind your program and distribute the resulting files royalty-free. Some additional 3rd party legal restrictions might apply when you use the Euphoria- To-C translator. The generous Open Source License allows Euphoria to use for both personal and commercial purposes. Unlike many other open source licenses, your changes do not have to be made open source. Euphoria – Environment This chapter describes about the installation of Euphoria on various platforms. You can follow the steps to install Euphoria on Linux, FreeBSD, and 32-bit Windows. So you can choose the steps based on your working environment. Linux, Free BSD Installation Official website provides .tar.gz file to install Euphoria on your Linux or BSD OS. You can download your latest version of Euphoria from its official website − Download Euphoria. Once you have .tar.gz file, here are three simple steps to be performed to install Euphoria on your Linux or Free BSD machine − Step 1 − Installing Files Untar the downloaded file euphoria-4.0b2.tar.gz in a directory where you want to install Euphoria. If you want to install it in /home directory as follows, then − $cp euphoria-4.0b2.tar.gz /home $cd /home $gunzip euphoria-4.0b2.tar.gz $tar -xvf euphoria-4.0b2.tar This creates a directory hierarchy inside /home/euphoria-4.0b2 directory as follows − $ls -l -rw-r–r– 1 1001 1001 2485 Aug 17 06:15 Jamfile -rw-r–r– 1 1001 1001 5172 Aug 20 12:37 Jamrules -rw-r–r– 1 1001 1001 1185 Aug 13 06:21 License.txt drwxr-xr-x 2 1001 1001 4096 Aug 31 10:07 bin drwxr-xr-x 7 1001 1001 4096 Aug 31 10:07 demo -rw-r–r– 1 1001 1001 366 Mar 18 09:02 file_id.diz drwxr-xr-x 4 1001 1001 4096 Aug 31 10:07 include -rw-r–r– 1 1001 1001 1161 Mar 18 09:02 installu.doc drwxr-xr-x 4 1001 1001 4096 Aug 31 10:07 source drwxr-xr-x 19 1001 1001 4096 Sep 7 12:09 tests drwxr-xr-x 2 1001 1001 4096 Aug 31 10:07 tutorial NOTE − File name euphoria-4.0b2.tar.gz depends on latest version available. We are using 4.0b2 version of the language for this tutorial. Step 2 − Setting Up the Path After installing Euphoria, you need to set proper paths so that your shell can find required Euphoria binaries and utilities. Before proceeding, there are following three important environment variables you need to set up − Set PATH environment variable to point /home/euphoria-4.0b2/bin directory. Set EUDIR environment variable to point to /home/euphoria-4.0b2. Set EUINC environment variable to point to /home/euphoria-4.0b2/include. These variables can be set as follows − $export PATH=$PATH:/home/euphoria-4.0b2/bin $export EUDIR=/home/euphoria-4.0b2 $export EUINC=/home/euphoria-4.0b2/include NOTE − The above commands used to set environment variables may differ depending on your Shell. We used bash shell for executing these commands to set the variables. Step 3 − Confirmation Installation Confirm if you installed Euphoria successfully or not. Execute the following command − $eui -version If you get following result, then it means you have installed Euphoria successfully; otherwise you have to go back and

Euphoria – Flow Control

Euphoria – Flow Control ”; Previous Next Program execution flow refers to the order in which program statements get executed. By default the statements get executed one after another. However; many times the order of execution needs to be altered from the default order, to get the task done. Euphoria has a number of flow control statements that you can use to arrange the execution order of statements. The exit statement Exiting a loop is done with the keyword exit. This causes flow to immediately leave the current loop and recommence with the first statement after the end of the loop. Syntax The syntax of an exit statement is as follows − exit [ “Label Name” ] [Number] The exit statement terminates the latest and innermost loop until an optional label name or number is specified. A special form of exit N is exit 0. This leaves all levels of loop, regardless of the depth. Control continues after the outermost loop block. Likewise, exit -1 exits the second outermost loop, and so on. Example #!/home/euphoria-4.0b2/bin/eui integer b for a = 1 to 16 do printf(1, “value of a %dn”, a) if a = 10 then b = a exit end if end for printf(1, “value of b %dn”, b) This produces the following result − value of a 1 value of a 2 value of a 3 value of a 4 value of a 5 value of a 6 value of a 7 value of a 8 value of a 9 value of a 10 value of b 10 The break statement The break statement works exactly like the exit statement, but applies to if statements or switch statements rather than to loop statements of any kind. Syntax The syntax of break statement is as follows − break [ “Label Name” ] [Number] The break statement terminates the latest and innermost if or switch block until an optional label name or number is specified. A special form of break N is break 0. This leaves the outer most if or switch block, regardless of the depth. Control continues after the outermost block. Likewise, break -1 breaks the second outermost if or switch block, and so on. Example #!/home/euphoria-4.0b2/bin/eui integer a, b sequence s = {”E”,”u”, ”p”} if s[1] = ”E” then a = 3 if s[2] = ”u” then b = 1 if s[3] = ”p” then break 0 — leave topmost if block end if a = 2 else b = 4 end if else a = 0 b = 0 end if printf(1, “value of a %dn”, a) printf(1, “value of b %dn”, b) This produces the following result − value of a 3 value of b 1 The continue statement The continue statement continues execution of the loop it applies to by going to the next iteration and skipping the rest of an iteration. Going to the next iteration means testing a condition variable index and checking whether it is still within bounds. Syntax The syntax of continue statement is as follows − continue [ “Label Name” ] [Number] The continue statement would re-iterate the latest and inner most loop until an optional label name or number is specified. A special form of continue N is continue 0. This re-iterate the outer most loop, regardless of the depth. Likewise, continue -1 starts from the second outermost loop, and so on. Example #!/home/euphoria-4.0b2/bin/eui for a = 3 to 6 do printf(1, “value of a %dn”, a) if a = 4 then puts(1,”(2)n”) continue end if printf(1, “value of a %dn”, a*a) end for This would produce following result: value of a 3 value of a 9 value of a 4 (2) value of a 5 value of a 25 value of a 6 value of a 36 The retry statement The retry statement continues execution of the loop it applies to by going to the next iteration and skipping the rest of an iteration. Syntax The syntax of retry statement is as follows − retry [ “Label Name” ] [Number] The retry statement retries executing the current iteration of the loop it applies to. The statement branches to the first statement of the designated loop neither testing anything nor incrementing the for loop index. A special form of retry N is retry 0. This retries executing the outer most loop, regardless of the depth. Likewise, retry -1 retries the second outermost loop, and so on. Normally, a sub-block which contains a retry statement also contains another flow control keyword like exit, continue, or break. Otherwise, the iteration would be endlessly executed. Example #!/home/euphoria-4.0b2/bin/eui integer errors = 0 integer files_to_open = 10 for i = 1 to length(files_to_open) do fh = open(files_to_open[i], “rb”) if fh = -1 then if errors > 5 then exit else errors += 1 retry end if end if file_handles[i] = fh end for Since retry does not change the value of i and tries again opening the same file, there has to be a way to break from the loop, which the exit statement provides. The goto statement The goto statement instructs the computer to resume code execution at a labeled place. The place to resume execution is called the target of the statement. It is restricted to lie in the current routine, or the current file if outside any routine. Syntax The syntax of goto statement is as follows − goto “Label Name” The target of a goto statement can be any accessible label statement − label “Label Name” Label names must be double quoted constant strings. Characters that are illegal in Euphoria identifiers may appear in a label name, since it is a regular string. Example #!/home/euphoria-4.0b2/bin/eui integer a = 0 label “FIRST” printf(1, “value of a %dn”, a) a += 10 if a < 50 then goto “FIRST” end if printf(1, “Final value of a %dn”, a) This produces the following result − value of a 0 value of a 10 value of a 20 value of

Euphoria – Files I/O

Euphoria – Files I/O ”; Previous Next Using Euphoria programming language, you can write programs that read and change file data on your floppy drive or hard drive, or create new files as a form of output. You can even access devices on your computer such as the printer and modem. This chapter described all the basic I/O functions available in Euphoria. For information on more functions, please refer to standard Euphoria documentation. Displaying on the Screen The simplest way to produce output is using the puts() statement where you can pass any string to be displayed on the screen. There is another method printf() which can also be used in case you have to format a string using dynamic values. These methods convert the expressions you pass them to a string and write the result to standard output as follows − #!/home/euphoria-4.0b2/bin/eui puts(1, “Euphoria is really a great language, isn”t it?” ) This produces the following result on your standard screen − Euphoria is really a great language, isn”t it? Opening and Closing Files Euphoria provides basic methods necessary to manipulate files by default. You can do your most of the file manipulation using the following methods − open() close() printf() gets() getc() The open Method Before you can read or write a file, you have to open it using Euphoria”s built-in open()method. This function creates a file descriptor which is utilized to call other supporting methods associated with it. Syntax integer file_num = open(file_name, access_mode) Above method returns -1 in case there is an error in opening the given file name. Here are the parameters − file_name − The file_name argument is a string value that contains the name of the file that you want to access. access_mode − The access_mode determines the mode in which the file has to be opened. For example, read, write append, etc. A complete list of possible values for file opening modes is given in the following table − S.No Modes & Description 1 r Opens a text file for reading only. The file pointer is placed at the beginning of the file. 2 rb Opens a file for reading only in binary format. The file pointer is placed at the beginning of the file. 3 w Opens a text file for writing only. Overwrites the file if the file exists. If the file does not exist, creates a new file for writing. 4 wb Opens a file for writing only in binary format. Overwrites the file if the file exists. If the file does not exist, creates a new file for writing. 5 u Opens a file for both reading and writing. The file pointer is set at the beginning of the file. 6 ub Opens a file for both reading and writing in binary format. The file pointer is placed at the beginning of the file. 7 a Opens a file for appending. The file pointer is at the end of the file if the file exists (append mode). If the file does not exist, it creates a new file for writing. 8 ab Opens a file for appending in binary format. The file pointer is at the end of the file if the file exists (append mode). If the file does not exist, it creates a new file for writing. Example The following example creates a new text file in the current directory on your Linux system − #!/home/euphoria-4.0b2/bin/eui integer file_num constant ERROR = 2 constant STDOUT = 1 file_num = open(“myfile,txt”, “w”) if file_num = -1 then puts(ERROR, “couldn”t open myfilen”) else puts(STDOUT, “File opend successfullyn”) end if If file opens successfully, then it “myfile.txt” is created in your current directory and produces the following result − File opend successfully The close() Method The close() method flushes any unwritten information and closes the file, after which no more reading or writing can be done on the file. Euphoria automatically closes a file when the reference object of a file is reassigned to another file. It is a good practice to use the close() method to close a file. Syntax close( file_num ); Here the file descriptor received while opening a file is passed as a parameter. Example The following example creates a file as above and then closes it before existing the program − #!/home/euphoria-4.0b2/bin/eui integer file_num constant ERROR = 2 constant STDOUT = 1 file_num = open(“myfile.txt”, “w”) if file_num = -1 then puts(ERROR, “couldn”t open myfilen”) else puts(STDOUT, “File opend successfullyn”) end if if file_num = -1 then puts(ERROR, “No need to close the filen”) else close( file_num ) puts(STDOUT, “File closed successfullyn”) end if This produces the following result − File opend successfully File closed successfully Reading and Writing Files Euphoria provides a set of access methods to make our lives easier while reading or writing a file either in text mode or binary mode. Let us see how to use printf() and gets() methods to read and write files. The printf() Method The printf() method writes any string to an open file. Syntax printf(fn, st, x) Here are the parameters − fn − File descriptor received from open() method. st − Format string where decimal or atom is formatted using %d and string or sequence is formatted using %s. x − If x is a sequence, then format specifiers from st are matched with corresponding elements of x. If x is an atom, then normally st contains just one format specifier and it is applied to x. However; if st contains multiple format specifiers, then each one is applied to the same value x. Example The following example opens a file and writes the name and age of a person in this file − #!/home/euphoria-4.0b2/bin/eui integer file_num constant ERROR = 2 constant STDOUT = 1 file_num = open(“myfile.txt”, “w”) if file_num = -1 then puts(ERROR, “couldn”t open myfilen”) else puts(STDOUT, “File opend successfullyn”) end if printf(file_num, “My name is %s and age is %dn”, {“Zara”, 8}) if file_num = -1

Euphoria – Useful Resources

Euphoria – Useful Resources ”; Previous Next The following resources contain additional information on Euphoria. Please use them to get more in-depth knowledge on this topic. Useful Links on Euphoria Euphoria − Official website for Euphoria. Learn about the Euphoria language and discover the latest happenings in Euphoria arena. Euphoria Download page − Download latest version of Euphoria from sourceforge. Euphoria @ Wiki − Euphoria at Wikipedia, the free encyclopedia OpenEuphoria.org − Latest news about Euphoria, Community and much more…. Useful Books on Euphoria To enlist your site on this page, please drop an email to [email protected] Print Page Previous Next Advertisements ”;

Euphoria – Operators

Euphoria – Operators ”; Previous Next Euphoria provides a rich set of operators to manipulate variables. We can divide all the Euphoria operators into the following groups − Arithmetic Operators Relational Operators Logical Operators Assignment Operators Misc Operators The Arithmetic Operators Arithmetic operators are used in mathematical expressions in the same way that they are used in Algebra. The following table lists the arithmetic operators. Assume integer variable A holds 10 and variable B holds 20 then − Show Examples Operator Description Example + Addition – Adds values on either side of the operator A + B will give 30 – Subtraction – Subtracts right hand operand from left hand operand A – B will give -10 * Multiplication – Multiplies values on either side of the operator A * B will give 200 / Division – Divides left hand operand by right hand operand B / A will give 2 + Unary plus – This has no impact on the variable value. +B gives 20 – Unary minus – This creates a negative value of the given variable. -B gives -20 The Relational Operators There are following relational operators supported by Euphoria language. Assume variable A holds 10 and variable B holds 20 then − Show Examples Operator Description Example = Checks if the value of two operands are equal or not, if yes then condition becomes true. (A = B) is not true. != Checks if the value of two operands are equal or not, if values are not equal then condition becomes true. (A != B) is true. > Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (A > B) is not true. < Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (A < B) is true. >= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (A >= B) is not true. <= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (A <= B) is true. The Logical Operators The following table lists the logical operators. Assume boolean variables A holds 1 and variable B holds 0 then − Show Examples Operator Description Example and Called Logical AND operator. If both the operands are non zero then then condition becomes true. (A and B) is false. or Called Logical OR Operator. If any of the two operands are non zero then then condition becomes true. (A or B) is true. xor Called Logical XOR Operator. Condition is true if one of them is true, if both operands are true or false then condition becomes false. (A xor B) is true. not Called Logical NOT Operator which negates the result. Using this operator, true becomes false and false becomes true not(B) is true. You can also apply these operators to numbers other than 1 or 0. The convention is: zero means false and non-zero means true. The Assignment Operators There are following assignment operators supported by Euphoria language − Show Examples Operator Description Example = Simple assignment operator, Assigns values from right side operands to left side operand C = A + B will assigne value of A + B into C += Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand C += A is equivalent to C = C + A -= Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand C -= A is equivalent to C = C – A *= Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand C *= A is equivalent to C = C * A /= Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand C /= A is equivalent to C = C / A &= Concatenation operator C &= {2} is same as C = {C} & {2} Note − The equals symbol ”=” used in an assignment statement is not an operator, it is just a part of the syntax. Miscellaneous Operators There are few other operators supported by Euphoria Language. The ”&” Operator Any two objects may be concatenated using “&” operator. The result is a sequence with a length equal to the sum of the lengths of the concatenated objects. For example − #!/home/euphoria-4.0b2/bin/eui sequence a, b, c a = {1, 2, 3} b = {4} c = {1, 2, 3} & {4} printf(1, “Value of c[1] %dn”, c[1] ) printf(1, “Value of c[2] %dn”, c[2] ) printf(1, “Value of c[3] %dn”, c[3] ) printf(1, “Value of c[4] %dn”, c[4] ) This produces the following result − Value of c[1] 1 Value of c[2] 2 Value of c[3] 3 Value of c[4] 4 Precedence of Euphoria Operators Operator precedence determines the grouping of terms in an expression. This affects how an expression is evaluated. Certain operators have higher precedence than others; for example, the multiplication operator has higher precedence than the addition operator. For example, x = 7 + 3 * 2 Here, x is assigned 13, not 20 because operator * has higher precedence than +. Hence it first starts with 3*2 and then adds into 7. Here operators with the highest precedence appear at the top of the table, those with the lowest appear at the bottom. Within an expression, higher precedence operators is evaluated first. Category Operator Associativity Postfix function/type calls   Unary + – ! not Right to left Multiplicative * / Left to right Additive + – Left to right Concatenation & Left to right Relational > >= < <= Left to right Equality = !=

Euphoria – Discussion

Discuss Euphoria ”; Previous Next This tutorial gives you basic understanding of Euphoria programming language. Euphoria is simple, flexible, easy to learn, and interpreted high-level programming language for DOS, Windows, Linux, FreeBSD, and more. This tutorial describes everything a programmer needs to know such as its environment, data types, syntax and operators, file handling, and controlling the flow of program. Print Page Previous Next Advertisements ”;

Euphoria – Data Types

Euphoria – Data Types ”; Previous Next The data stored in memory can be of many types. For example, a person”s age is stored as a numeric value and his or her address is stored as alphanumeric characters. Euphoria has some standard types that are used to define the operations possible on them and the storage method for each of them. Euphoria has following four standard data types − integer atom sequence object The understanding of atoms and sequences is the key to understanding Euphoria. Integers Euphoria integer data types store numeric values. They are declared and defined as follows − integer var1, var2 var1 = 1 var2 = 100 The variables declared with type integer must be atoms with integer values from -1073741824 to +1073741823 inclusive. You can perform exact calculations on larger integer values, up to about 15 decimal digits, but declare them as atom, rather than integer. Atoms All data objects in Euphoria are either atoms or sequences. An atom is a single numeric value. Atoms can have any integer or double-precision floating point value. Euphoria atoms are declared and defined as follows− atom var1, var2, var3 var1 = 1000 var2 = 198.6121324234 var3 = ”E” The atoms can range from approximately -1e300 to +1e300 with 15 decimal digits of accuracy. An individual character is an atom which must may be entered using single quotes. For example, all the following statements are legal − — Following is equivalent to the atom 66 – the ASCII code for B char = ”B” — Following is equivalent to the sequence {66} sentence = “B” Sequences A sequence is a collection of numeric values which can be accessed through their index. All data objects in Euphoria are either atoms or sequences. Sequence index starts from 1 unlike other programming languages where array index starts from 0. Euphoria sequences are declared and defined as follows − sequence var1, var2, var3, var4 var1 = {2, 3, 5, 7, 11, 13, 17, 19} var2 = {1, 2, {3, 3, 3}, 4, {5, {6}}} var3 = {{“zara”, “ali”}, 52389, 97.25} var4 = {} — the 0 element sequence A character string is just a sequence of characters which may be entered using double quotes. For example, all the following statements are legal − word = ”word” sentence = “ABCDEFG” Character strings may be manipulated and operated upon just like any other sequences. For example, the above string is entirely equivalent to the sequence − sentence = {65, 66, 67, 68, 69, 70, 71} You will learn more about sequence in Euphoria − Sequences. Objects This is a super data type in Euphoria which may take on any value including atoms, sequences, or integers. Euphoria objects are declared and defined as follows − object var1, var2, var3 var1 = {2, 3, 5, 7, 11, 13, 17, 19} var2 = 100 var3 = ”E” An object may have one of the following values − a sequence an atom an integer an integer used as a file number a string sequence, or single-character atom Print Page Previous Next Advertisements ”;