📜  Euphoria-图书馆例程

📅  最后修改于: 2020-11-04 07:56:29             🧑  作者: Mango


 

提供了大量的库例程。有些内置在解释器中,例如ex.exe,exw.exe或exu 。其他文件则用Euphoria编写,您必须在euphoria \ include目录中包含一个.e文件才能使用它们。

为了指示可以传递和返回哪种对象,使用了以下前缀-

S.No Prefix & Description
1 x

a general object (atom or sequence)

2 s

a sequence

3 a

an atom

4 i

an integer

5 fn

an integer used as a file number

6 st

a string sequence, or single-character atom

预定义类型

除了使用这些类型声明变量之外,您还可以像普通函数一样调用它们,以测试值是否为特定类型。

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)

序列操纵

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

搜索和排序

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

模式匹配

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

数学

这些例程可以应用于单个原子或值序列。

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…)

按位逻辑运算

这些例程将数字视为二进制位的集合,并对数字的二进制表示形式中的相应位执行逻辑运算。

没有用于向左或向右移位位的例程,但是您可以通过乘以或除以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

文件和设备I / O

要在文件或设备上进行输入或输出,必须首先打开文件或设备,然后使用下面的例程对其进行读写,然后关闭文件或设备。 open()将为您提供一个文件号,以用作其他I / O例程的第一个参数。某些文件/设备会自动为您打开(作为文本文件)-

  • 0-标准输入
  • 1-标准输出
  • 2-标准错误
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

鼠标支持(DOS32和Linux)

在Windows XP上,如果希望DOS鼠标在(非全屏)窗口中工作,则必须在DOS窗口的“属性”中禁用“快速编辑”模式。

get_mouse return mouse “events” (clicks, movements)
mouse_events select mouse events to watch for
mouse_pointer display or hide the mouse pointer

操作系统

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

特殊的机器相关例程

machine_func specialized internal operations with a return value
machine_proc specialized internal operations with no return value

调试

trace dynamically turns tracing on or off
profile dynamically turns profiling on or off

图形和声音

以下例程可让您在屏幕上显示信息。在DOS中,可以将PC屏幕置于许多图形模式之一。

以下例程适用于所有文本和像素图形模式。

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)

以下例程仅在模式下以文本形式工作

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

以下例程仅在像素图形模式下工作(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

多任务

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.