Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Euphoria (programming language)
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Examples== Program comments start with a double hyphen <code>--</code> and go through the end of line. The following code looks for an old item in a group of items. If found, it removes it by concatenating all the elements before it with all the elements after it. Note that the first element in a sequence has the index one [1] and that $ refers to the length (i.e., total number of elements) of the sequence. <span style="color:blue;">global function</span> delete_item( <span style="color:magenta;">object</span> old, <span style="color:magenta;">sequence</span> group ) <span style="color:magenta;">integer</span> pos <span style="color:red;">-- Code begins --</span> pos = <span style="color:magenta;">find</span>( old, group ) <span style="color:blue;">if</span> pos > 0 <span style="color:blue;">then</span> group = group[1 .. pos-1] & group[pos+1 .. $] <span style="color:blue;">end if return</span> group <span style="color:blue;">end function</span> The following modification to the above example replaces an old item with a new item. As the variables ''old'' and ''new'' have been defined as objects, they could be ''atoms'' or ''sequences''. Type checking is not needed as the function will work with any sequence of data of any type and needs no external libraries. <span style="color:blue;">global function</span> replace_item( <span style="color:magenta;">object</span> old, <span style="color:magenta;">object</span> new, <span style="color:magenta;">sequence</span> group ) <span style="color:magenta;">integer</span> pos <span style="color:red;">-- Code begins --</span> pos = <span style="color:magenta;">find</span>( old, group ) <span style="color:blue;">if</span> pos > 0 <span style="color:blue;">then</span> group[pos] = new <span style="color:blue;">end if return</span> group <span style="color:blue;">end function</span> Furthermore, no pointers are involved and subscripts are automatically checked. Thus the function cannot access memory out-of-bounds. There is no need to allocate or deallocate memory explicitly and no chance of a memory leak. The line group = group[1 .. pos-1] & group[pos+1 .. $] shows some of the ''sequence'' handling facilities. A ''sequence'' may contain a set 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.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Euphoria (programming language)
(section)
Add topic