Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Euphoria (programming language)
(section)
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.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)