Euphoria – Library Routines

library routines

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 euphoria\include directory to use them.

To indicate what kind of object may be passed in and returned, the following prefixes are used −

S.NoPrefix & Description
1xa general object (atom or sequence)
2sa sequence
3aan atom
4ian integer
5fnan integer used as a file number
6sta 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.

integertest if an object is an integer
atomtest if an object is an atom
sequencetest if an object is a sequence
objecttest if an object is an object (always true)

Sequence Manipulation

lengthreturn the length of a sequence
repeatrepeat an object n times to form a sequence of length n
reversereverse a sequence
appendadd a new element to the end of a sequence
prependadd a new element to the beginning of a sequence

Searching and Sorting

comparecompare two objects
equaltest if two objects are identical
findfind an object in a sequence – start searching from element number 1
find_fromfind an object in a sequence – start searching from any element number
matchfind a sequence as a slice of another sequence – start searching from element number 1
match_fromfind a sequence as a slice of another sequence – start searching from any element number
sortsort the elements of a sequence into ascending order
custom_sortsort the elements of a sequence based on a compare function that you supply

Pattern Matching

lowerconvert an atom or sequence to lower case
upperconvert an atom or sequence to upper case
wildcard_matchmatch a pattern containing ? and * wildcards
wildcard_filematch a file name against a wildcard specification

Math

These routines can be applied to individual atoms or to sequences of values.

sqrtcalculate the square root of an object
randgenerate random numbers
sincalculate the sine of an angle
arcsincalculate the angle with a given sine
coscalculate the cosine of an angle
arccoscalculate the angle with a given cosine
tancalculate the tangent of an angle
arctancalculate the arc tangent of a number
logcalculate the natural logarithm
floorround down to the nearest integer
remaindercalculate the remainder when a number is divided by another
powercalculate a number raised to a power
PIthe 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_bitsperform logical AND on corresponding bits
or_bitsperform logical OR on corresponding bits
xor_bitsperform logical XOR on corresponding bits
not_bitsperform 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
openopen a file or device
closeclose a file or device
flushflush out buffered data to a file or device
lock_filelock a file or device
unlock_fileunlock a file or device
printprint a Euphoria object on one line, with braces and commas {,,} to show the structure
pretty_printprint a Euphoria object in a nice readable form, using multiple lines and appropriate indentation
? xshorthand for print(1, x)
sprintreturn a printed Euphoria object as a string sequence
printfformatted print to a file or device
sprintfformatted print returned as a string sequence
putsoutput a string sequence to a file or device
getcread the next character from a file or device
getsread the next line from a file or device
get_bytesread the next n bytes from a file or device
prompt_stringprompt the user to enter a string
get_keycheck for key pressed by the user, don’t wait
wait_keywait for user to press a key
getread the representation of any Euphoria object from a file
prompt_numberprompt the user to enter a number
valueread the representation of any Euphoria object from a string
seekmove to any byte position within an open file
wherereport the current byte position in an open file
current_dirreturn the name of the current directory
chdirchange to a new current directory
dirreturn complete info on all files in a directory
walk_dirrecursively walk through all files in a directory
allow_breakallow control-c/control-Break to terminate your program or not
check_breakcheck 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_mousereturn mouse “events” (clicks, movements)
mouse_eventsselect mouse events to watch for
mouse_pointerdisplay or hide the mouse pointer

Operating System

timenumber of seconds since a fixed point in the past
tick_rateset the number of clock ticks per second (DOS32)
datecurrent year, month, day, hour, minute, second etc.
command_linecommand-line used to run this program
getenvget value of an environment variable
systemexecute an operating system command line
system_execexecute a program and get its exit code
abortterminate execution
sleepsuspend execution for a period of time
platformfind out which operating system are we running on

Special Machine-Dependent Routines

machine_funcspecialized internal operations with a return value
machine_procspecialized internal operations with no return value

Debugging

tracedynamically turns tracing on or off
profiledynamically turns profiling on or off

Graphics & Sound

The following routines let you display information on the screen. In DOS, the PC screen can be placed into one of many graphics modes.

The following routines work in all text and pixel-graphics modes.

clear_screenclear the screen
positionset cursor line and column
get_positionreturn cursor line and column
graphics_modeselect a new pixel-graphics or text mode (DOS32)
video_configreturn parameters of current mode
scrollscroll text up or down
wrapcontrol line wrap at right edge of screen
text_colorset foreground text color
bk_colorset background color
palettechange color for one color number (DOS32)
all_palettechange color for all color numbers (DOS32)
get_all_paletteget the palette values for all colors (DOS32)
read_bitmapread a bitmap (.bmp) file and return a palette and a 2-d sequence of pixels
save_bitmapcreate a bitmap (.bmp) file, given a palette and a 2-d sequence of pixels
get_active_pagereturn the page currently being written to (DOS32)
set_active_pagechange the page currently being written to (DOS32)
get_display_pagereturn the page currently being displayed (DOS32)
set_display_pagechange the page currently being displayed (DOS32)
soundmake a sound on the PC speaker (DOS32)

The following routines work in text in modes only

cursorselect cursor shape
text_rowsset number of lines on text screen
get_screen_charget one character from the screen
put_screen_charput one or more characters on the screen
save_text_imagesave a rectangular region from a text screen
display_text_imagedisplay an image on the text screen

The following routines work in pixel-graphics modes only (DOS32)

pixelset color of a pixel or set of pixels
get_pixelread color of a pixel or set of pixels
draw_lineconnect a series of graphics points with a line
polygondraw an n-sided figure
ellipsedraw an ellipse or circle
save_screensave the screen to a bitmap (.bmp) file
save_imagesave a rectangular region from a pixel-graphics screen
display_imagedisplay an image on the pixel-graphics screen

Multitasking

task_clock_startrestart the scheduler’s clock
task_clock_stopstop the scheduler’s clock
task_createcreate a new task
task_listget a list of all tasks
task_scheduleschedule a task for execution
task_selfreturn the task id of the current task
task_statusthe current status (active, suspended, terminated) of a task
task_suspendSuspend a task.
task_yieldYield control, so the scheduler can pick a new task to run.

This Post Has One Comment

Leave a Reply