FAQ

Frequently Asked Questions

Here are most of the questions that new comers to the language tend to ask at some time.

Programming Euphoria FAQ

General Questions

Is there a source code level debugger with breakpoints, single-stepping, etc.?

Yes. See Debugging and Profiling in the Manual.

Is there a tool to help find bugs or perform static analysis?

-TEST (all) Parses the code only and issues any warnings or errors to STDOUT. On error the exit code will be 1, otherwise 0. If an error was found, the normal "Press Enter" prompt will not be presented when using the -TEST parameter which enables many editor/IDE programs to test the syntax of your Euphoria source in real time.

How can I create a stand-alone binary from a Euphoria script?

See Distributing a Program in the Manual.

Are there coding standards or a style guide for Euphoria programs?

See Euphoria CodingConvention.

My program is too slow. How do I speed it up?

See Performance Tips in the Manual.

Core Language

How do you set a global variable in a function?

Assign a value to it.

What are the rules for local and global variables in Euphoria?

See Scope.

How do I share global variables across modules?

Use the "global" variable definition.

What are the "best practices" for using import in a module?

Answer me.

How can I pass optional or keyword parameters from one function to another?

Answer me.

How do I write a function with output parameters (call by reference)?

Euphoria doesn't support call by reference. If you want your function to modify a variable, assign the return value of the function to that variable.

How do you make a higher order function in Euphoria?

Answer me.

How do I copy an object in Euphoria?

a=b

How can I find the methods or attributes of an object?

Euphoria isn't object oriented.

How can my code discover the name of an object?

Euphoria isn't an object oriented language.

Is there an equivalent of C's "?:" ternary operator?

see std/utils.e iif() function

Is it possible to write obfuscated one-liners in Euphoria?

Why do you ask?

Numbers, strings, math

How do I generate random numbers in Euphoria?

See Random Numbers in the Manual.

How do I specify hexadecimal and octal integers?

For hexadecimal, use the '#' symbol (#FE, #A000, etc.). It is not possible to input octal values, but it is possible to output them. See printf().

How do I convert a string to a number?

Use the value() function.

How do I convert a number to a string?

Use the sprint() orsprintf() function.

How do I modify a string in place?

Just do it. name = "Abe Lincoln" name = "Abraham Lincoln" now it's modified. Was that so hard?

How do I use strings to call functions/methods?

see routine_id in the docs.

Is there an equivalent to Perl's chomp() for removing trailing newlines from strings?

See trim(), trim_head(), and trim_tail().

Is there a scanf() or sscanf() equivalent?

see value()

Variables, constants, and arguments

What is the scope of a local variable? a constant?

See Scope.

When does a local variable become accessible?

Answer me.

How are arguments passed?

All arguments are passed by value.

What does '#' prepended to an argument mean?

A better question would be which programming language allows prepending a '#' to an argument. If you answer Racket you get an A.

Does the value of a constant ever change?

No. The value of a constant is fixed when it's defined for the life of the program.

Does Euphoria support keyword arguments?

No. There are ways to simulate keyword arguments, however, using functions in the std library.

Syntax

How can I code post-test loops?

See loop until in the Manual.

An example of the loop..until construct:

i = 0 
loop do 
    printf(1, "i = %d\n", {i} )  
    i += 1      
until i > 4 

What are the non-alphanumerical symbols in Euphoria code?

What does $ mean?

The symbol '$' in Euphoria version 2.5 and later means "length(of_sequence)."

sequence s, i  
s = "My Sequence"  
i = s[$] -- i = "e"  
i = s[4..$] -- i = "Sequence"  
i = s[$-5] -- i = "q" 

Miscellaneous

How do random number seeds work?

Answer me.

How can I count the frequency of words in a file?

Answer me.

How can I sort strings in alphabetical order?

See sort().

How can I expand tabs to spaces?

See find_replace() and match_replace().

Does Euphoria have function pointers?

see routine_id

Does Euphoria have exception handling?

No.

How can I move or copy a file?

See copy_file() and move_file().

Sequences

What's a negative index?

Negative index is a mis-named feature of Python and some other languages. If the index is n, and n = -1, then this means, to python, in English, "the last". In Euphoria, this would be x[length(x)], or in a more convenient shorthand x[$]. In Python, -2 would mean "next to last". In Euphoria x[length(x)-1] or x[$-1].

How do I iterate over a sequence in reverse order?

Use a for..loop, like so

sequence s  
for t=length(s) to 1 by -1 do  
    -- do something with s[t]  
end for 

How do you remove duplicates from a sequence?

See remove_dups().

How do you make an array in Euphoria?

Sequences are arrays. You create them by first declaring a variable as sequence, then assigning elements to the sequence. For example

sequence s  
s = { 1, 2, 3 } -- s is a 3-element sequence  
s = repeat(0,20) -- s is a 20-element sequence of zeroes  
s = repeat(repeat(1,10),20) -- s is a 20-element sequence of 10-element sequences 

How do you refer to individual elements in an array?

You get the value from a sequence with bracketed values. For instance,

?s[5][3] -- prints the third element of the fifth sequence (a multi-dimensional sequence) 

How do I create a multidimensional list?

Answer me.

How do I apply a method to a sequence of objects?

Answer me.

Dictionaries

How can I get a dictionary to display its keys in a consistent order?

Answer me.

I want to do a complicated sort: can you do a Schwartzian Transform in Euphoria?

The term "Schwartzian transform" is the perl name for a sorting algorithm which can be written in almost any turing-complete programming language, including Euphoria. Euphoria is likely to be faster than perl.

How can I sort one list by values from another list?

Answer me.

Input and Output

How can I process a file and update its contents?

See File Reading/Writing.

One way to do this is:

  1. Use read_lines() to read in the contents of a file.
  2. Manipulate the sequence of lines as desired
  3. Use write_lines() to write the sequence back to a file.

Should I feel uneasy if I don't close a file?

You should always close any files you no longer need open. However, Euphoria will automatically close any still-open files when your program terminates.

How do I get a recursive list of all the files under a directory and its subdirectories?

Answer me.

How can I control output buffering?

flush.

Extensions

How can I use Euphoria interactively?

You don't.

Is there a debugger for Euphoria?

Answer me.

How can I use a library written in C from Euphoria?

You can access shared libraries from a Euphoria program.

You can use code from a shared library uing open_dll(libname). This returns an atom which you'll have to reuse to access individual variables or functions.

You can access a function in a previously opened shared library by calling define_c_function(entry_point,func_name,type_arglist,return_type). This return an id that you can use with call_func().

define_c_proc() and define_c_var() work in the same way, but require less arguments for obvious reasons. You can define a function as a procedure if you'll never care about the returned value. You can access executable machine code using the above. Use "" as an entry point, and the address as name.

You can call(address) so that code at address gets executed. The code must be a routine that returns using the near ret instructions (opcode #C3). All used registers must be restored upon return. You'll have to set up the memory area which you'll call() into by coding some machine code into a sequence, allocate() a memory block of the right size and poke()ing the sequence first.

You must be aware that the code will run in 32 bit protected mode at privilege 3, and that call() requires two task switches, penalizing performance unless the asm code has a lot of work to perform. (1)

Can I use Tcl/Tk interface in Euphoria?

Answer me.

Can I use gtk+ interfaces in Euphoria?

Yes - https://sites.google.com/site/euphoriagtk/ for Linux, Windows, and OS X. EuGTK can load and run XML interface code built by Glade, so you can simply drag-and-drop to build your program's user interface.

Can I use xforms interfaces in Euphoria?

Answer me.

How can I do date arithmetic?

See the DateTime standard library. In particular, add
() and [[http://openeuphoria.org/docs/std_datetime.html#_1109_subtract|subtract
().

Can I integrate Euphoria and Python?

Answer me. Better yet, explain why you would want to do this.

XML parsers

There are several in the archives.

Is there a Euphoria library for wxWidgets?

Yes. See Matthew Lewis' wxEuphoria library.

Other Features

How can I count the number of lines in a file?

Here's one way:

include std/io.e 
 
sequence fname = "GtkEngine.e" 
 
object lines = read_lines(fname) 
printf(1,"There are %d lines in file %s\n",{length(lines),fname}) 

How can I sum the elements in an array?

Here's one way:

include std/math.e 
sequence a = {1,2,3,4,5,6,7,8}  
? sum(a) 

Is there a CGI module for Euphoria?

There is no standard CGI module that gets distributed with the Euphoria base package. However, there is code available for doing CGI with Euphoria (obviously, because this entire website is being served by a Euphoria CGI program). You can also get specific information for running Euphoria as CGI here and at the official Euphoria web site.

Object-Orientedness

Does Euphoria support object oriented programming?

Vanilla Euphoria does not "support" OO programming, though there are OO libraries in the archive, and Matthew Lewis has created a Euphoria interpreter with built-in object-oriented features.

Converting from version 3 to version 4

Why does my program take longer to load?

Symbol scope and resolution has changed in v4. Most v3 code will work correctly with respect to include files and global symbols, but if you use a global symbol without including the file in which it was defined (or another file that includes the correct file) then euphoria will take a little longer to resolve that reference. It is advised that if you use any variable or routine from some file or library, that each using file include the file or library that defines the symbols being used.

General Euphoria FAQ

Euphoria Libraries FAQ

Extending/Embedding Euphoria FAQ

GUI Programming FAQ

Search



Quick Links

User menu

Not signed in.

Misc Menu