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.

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” (clicks, movements)
mouse_eventsโˆ’select mouse events to watch for
mouse_pointerโˆ’display or hide the mouse pointer

Operating System

timeโˆ’number of seconds since a fixed point in the past
tick_rateโˆ’set the number of clock ticks per second (DOS32)
dateโˆ’current year, month, day, hour, minute, second etc.
command_lineโˆ’command-line used to run this program
getenvโˆ’get value of an environment variable
systemโˆ’execute an operating system command line
system_execโˆ’execute a program and get its exit code
abortโˆ’terminate execution
sleepโˆ’suspend execution for a period of time
platformโˆ’find out which operating system are we running on

Special Machine-Dependent Routines

machine_funcโˆ’specialized internal operations with a return value
machine_procโˆ’specialized internal operations with no return value

Debugging

traceโˆ’dynamically turns tracing on or off
profileโˆ’dynamically 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_screenโˆ’clear the screen
positionโˆ’set cursor line and column
get_positionโˆ’return cursor line and column
graphics_modeโˆ’select a new pixel-graphics or text mode (DOS32)
video_configโˆ’return parameters of current mode
scrollโˆ’scroll text up or down
wrapโˆ’control line wrap at right edge of screen
text_colorโˆ’set foreground text color
bk_colorโˆ’set background color
paletteโˆ’change color for one color number (DOS32)
all_paletteโˆ’change color for all color numbers (DOS32)
get_all_paletteโˆ’get the palette values for all colors (DOS32)
read_bitmapโˆ’read a bitmap (.bmp) file and return a palette and a 2-d sequence of pixels
save_bitmapโˆ’create a bitmap (.bmp) file, given a palette and a 2-d sequence of pixels
get_active_pageโˆ’return the page currently being written to (DOS32)
set_active_pageโˆ’change the page currently being written to (DOS32)
get_display_pageโˆ’return the page currently being displayed (DOS32)
set_display_pageโˆ’change the page currently being displayed (DOS32)
soundโˆ’make a sound on the PC speaker (DOS32)

The following routines work in text in modes only

cursorโˆ’select cursor shape
text_rowsโˆ’set number of lines on text screen
get_screen_charโˆ’get one character from the screen
put_screen_charโˆ’put one or more characters on the screen
save_text_imageโˆ’save a rectangular region from a text screen
display_text_imageโˆ’display an image on the text screen

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

pixelโˆ’set color of a pixel or set of pixels
get_pixelโˆ’read color of a pixel or set of pixels
draw_lineโˆ’connect a series of graphics points with a line
polygonโˆ’draw an n-sided figure
ellipseโˆ’draw an ellipse or circle
save_screenโˆ’save the screen to a bitmap (.bmp) file
save_imageโˆ’save a rectangular region from a pixel-graphics screen
display_imageโˆ’display an image on the pixel-graphics screen

Multitasking

task_clock_startโˆ’restart the scheduler’s clock
task_clock_stopโˆ’stop the scheduler’s clock
task_createโˆ’create a new task
task_listโˆ’get a list of all tasks
task_scheduleโˆ’schedule a task for execution
task_selfโˆ’return the task id of the current task
task_statusโˆ’the current status (active, suspended, terminated) of a task
task_suspendโˆ’Suspend a task.
task_yieldโˆ’Yield control, so the scheduler can pick a new task to run.

This Post Has One Comment

Leave a Reply