Dino has quite a lot of predeclared identifiers. The section Declarations and Scope Rules contains them in alphanumeric order. Here they are described according to the declaration category which they belongs to.
Dino has some predeclared variables which contain useful information or can be used to control the behaviour of the Dino interpreter.
To access arguments to the program and the environment, the following variables can be used:
argv
. The variable value is an immutable vector
whose elements are strings (immutable vectors of characters)
representing arguments to the program (see implementation).env
. The variable value is immutable table whose
elements are strings (immutable vectors of characters)
representing values of environment variables whose names are
the keys of the table.As Dino is a live programming language, it and its interpreter are in
the process of permanent development. To access the Dino interpreter's
version number and consequently the language version, the final variable
version
can be used. The variable value is the Dino version as a
floating point number. For example, if the current Dino version is
0.54, the variable value will be 0.54.
To access some information about threads in Dino program, the following variables can be used.
main_thread
. The variable value is the main
thread. When the program starts, there is only one thread
which is called the main thread.curr_thread
. The variable value is the thread in
which you reference the variable.When it is necessary to create an exception which is a object of a
class declared inside class except
or when it is necessary to
refer to a class inside class except
, the following variables
can be used. Instead of typing catch
(except().signal().sigint)
, you could type catch
(signals.sigint)
.
excepts
. The variable value is an object of the
class except
.errors
. The variable value is an object of the
class excepts.error
.signals
. The variable value is an object of the
class errors.signal
.invops
. The variable value is an object of the
class errors.invop
.invindexes
. The variable value is an object of
the class errors.invindex
.invkeys
. The variable value is an object of the
class errors.invkey
.invcalls
. The variable value is an object of the
class errors.invcall
.syserrors
. The variable value is an object of the
class invcalls.syserror
.systemcalls
. The variable value is an object of
the class invcalls.systemcall
.invparsers
. The variable value is an object of
the class invcalls.invparser
.invregexps
. The variable value is an object of
the class invcalls.invregexp
.invexterns
. The variable value is an object of
the class invcalls.invextern
.invaccesses
. The variable value is an object of
the class errors.invaccess
.To output something into standard streams or to input something from the standard input stream, the following variables can be used:
stdin
. The variable value is an object of the
class file
which corresponds to the standard input
stream.stdout
. The variable value is an object of the
class file
which corresponds to the standard output
stream.stderr
. The variable value is an object of the
class file
which corresponds to the standard error
stream.Values of the following variables are used by some predeclared functions:
split_regex
. The variable value is a string which
represents regular expression which is used by the predeclared
function split
when the second parameter is not given.
The initial value of the variable is string "[ \t]+"
.time_format
. The variable value is a string which
is the output format of time used by the function
strtime
when it is called without parameters. The
initial value of the variable is the string "%a %b %d
%H:%M:%S %Z %Y"
.The most of the predeclared classes describe exceptions which may be generated in Dino program.
Dino has predeclared final class file
. Work with files in
Dino program are made through objects of the class. All declarations
inside of class are private. The objects of the class can be created
only by predeclared functions open
or popen
. If you
create an object of the class by calling the class, exception
callop
will be generated.
All Dino exceptions are represented by objects of the predeclared
class except
or of a class in the class except
. The
class except
has no parameters, therefore all arguments in
calling the class will be ignored. There is one predeclared class
error
inside class except
. All classes
corresponding to user-defined exceptions are suggested to be declared
in class except
not in the class error
because all
other exceptions (e.g. generated by the Dino interpreter itself or by
predeclared functions) are objects of the class error
or
predeclared classes inside the class error
. The class
error
and all classes inside the class has one parameter
msg
which contains a readable message about the exception.
The following classes are declared in the class error
:
signal
. Classes inside this class describe
exceptions from receiving a signal from other OS processes. They
are
sigint
. This class describes the exception
generated by the user's interrupt from the keyboard.sigill
. This class describes the exception
generated by illegal execution of an instruction .sigabrt
. This class describes the exception
generated by the signal abort.sigfpe
. This class describes floating point
exception.sigterm
. This class describes the exception
generated by the termination signal.sigsegv
. This class describes the exception
generated by an invalid memory reference.invenv
. This class describes corruption of the Dino
program environment (see predeclared variable env
).invop
. Classes inside this class describe
exceptions when operands of operations have an incorrect type or
value.
optype
. This class describes that the operand
of an operation is not of the required type (possibly after
implicit conversions).opvalue
. This class is reserved for the error
of that an operand of an operation has invalid value. Now
this exception is not generated.invindex
. Classes inside this class describe
exceptions in referring for a vector element.
indextype
. This class describes that the
index is not of integer type (possibly after implicit
integer conversion).indexvalue
. This class describes that the
index is negative or equal to or more than the vector
length.indexop
. This class describes that the first
operand in referring to a vector element is not a vector.invkey
. Classes inside this class describe
exceptions in referring to a table element.
keyvalue
. This class describes that there is
no such element in the table with the given key when we
need the value of the element. The exception does not
occur when a table element reference stands in the left
hand side of an assignment-statement.keyop
. This class describes that the first
operand in referring to a table element is not a table.invcall
. Classes inside this class describe
exceptions in calling functions (mainly predeclared ones).
callop
. This class describes that we try to
call something which is not a function, class, or
thread-function. The exception is also generated when you
try to create a class file
instance by calling the
class.partype
. This class describes that a
parameter value of a predeclared function is not of
required type.invfmt
. This class describes that a format of
a format output function is wrong (see function
putf
.invresult
. This class describes that the
result value of function call is not of required type,
e.g. comparison function used in a call to function
sort
returns a non integer value.invinput
. This class describes that the file
input is not of required format. Usually the exception is
generated by function scan
etc.eof
. This class describes that end of file is
encountered. Usually the exception is generated by
functions reading files (get
, scan
etc).parnumber
. This class describes that the
number of actual parameters is not valid when we call a
predeclared function.syserror
. Classes inside this class describe
exceptions in predeclared functions which call OS system
functions. Some exceptions are never generated but may
be generated in the future on some OSes.
eaccess
. This describes the system error
"Permission denied".eagain
. This describes the system error
"Resource temporarily unavailable".ebadf
. This describes the system error
"Bad file descriptor".ebusy
. This describes the system error
"Resource busy".echild
. This describes the system error
"No child processes".edeadlk
. This describes the system error
"Resource deadlock avoided".edom
. This describes the system error
"Domain error".eexist
. This describes the system error
"File exists".efault
. This describes the system error
"Bad address".efbig
. This describes the system error
"File too large".eintr
. This describes the system error
"Interrupted function call".einval
. This describes the system error
"Invalid argument".eio
. This describes the system error
"Input/output error".eisdir
. This describes the system error
"Is a directory".emfile
. This describes the system error
"Too many open files".emlink
. This describes the system error
"Too many links".enametoolong
. This describes the system
error "Filename too long".enfile
. This describes the system error
"Too many open files in system".enodev
. This describes the system error "No
such device".enoent
. This describes the system error "No
such file or directory".enoexec
. This describes the system error
"Exec format error".enolck
. This describes the system error "No
locks available".enomem
. This describes the system error
"Not enough space".enospc
. This describes the system error "No
space left on device".enosys
. This describes the system error
"Function not implemented".enotdir
. This describes the system error
"Not a directory".enotempty
. This describes the system error
"Directory not empty".enotty
. This describes the system error
"Inappropriate I/O control operation".enxio
. This describes the system error "No
such device or address".eperm
. This describes the system error
"Operation not permitted".epipe
. This describes the system error
"Broken pipe".erange
. This describes the system error
"Result too large".erofs
. This describes the system error
"Read-only file system".espipe
. This describes the system error
"Invalid seek".esrch
. This describes the system error "No
such process".exdev
. This describes the system error
"Improper link".systemcall
. Classes inside this class
describe exceptions in calling the predeclared function
system
.
noshell
. This class describes the exception
that the function system
can not find the OS
command interpreter (the shell).systemfail
. This class describes all
remaining exceptions in calling the OS function
system
.invparser
. Classes inside this class describe
exceptions specific for calling functions of the predeclared
class parser
implementing the Earley parser.
invgrammar
. This class describes
the exception that the Earley parser got a bad grammar,
e.g. without rules, with loops in rules, with
nonterminals unachievable from the axiom, with nonterminals
not deriving any terminal string etc.invtoken
. This class describes the
exception that the parser got an input token with unknown
(undeclared) code.pmemory
. This class describes the exception
that there is not enough memory for internal parser
data.invregexp
. Classes inside this class describe
exceptions specific for calling predeclared functions
implementing regular expression pattern matching.
ebrack
. This class describes the exception
that a regular expression has an unmatched bracket.erange
. This class describes the exception
that there is an invalid use of range in regular
expression.ectype
. This class describes the exception
that there is an unknown character class name in regular
expression.eparen
. This class describes the exception
that a regular expression has an unmatched parenthesis.esubreg
. This class describes the exception
that there is an invalid back reference to a
subexpression in a regular expression.eend
. This class describes the exception
that there is a non specific error in regular expression.eescape
. This class describes the exception
that there is a trailing backslash.badpat
. This class describes the exception
that there is invalid use of pattern operators in a
regular expression.esize
. This class describes exception that
the compiled regular expression is too big.espace
. This class describes the exception
that there is no memory for a regular expression function
to work.invextern
. Classes inside this class describe
exceptions in calling external functions or in accessing
an external variable.
noextern
. This class describes the
exception that the given external can not be find.libclose
. This class describes the
exception that there is an error in closing a shared
library.noexternsupp
. This class describes an
exception in the usage of externals when they are not
implemented under this OS.invenvar
. This class describes corruption in
the type of variables split_regex
and
time_format
(e.g. their values are not strings).internal
. This class describes all other
(nonspecified) exceptions in calling predeclared functions.Dino has the three following classes which are used by the Earley parser embedded into the Dino interpreter.
Dino has predeclared final class parser
which implements
the Earley parser. The Earley parser is a very powerful tool to implement
serious language compilers, processors, or translators. The
implementation of the Earley parser used in Dino has the following
features:
parser
:
ambiguous_p
. This public variable stores
information about the last parsing. A nonzero variable value
means that during the last parsing on a given input the parser
found that the grammar is ambiguous. The parser can find this
even if you asked for only one parser tree (see function
set_one_parse
).
set_grammar (descr, strict_p)
. This function
tunes the parser to given grammar. The grammar is given by
string descr
. Nonzero value of parameter
strict_p
(after implicit integer conversion) means
more strict checking the grammar. In this case, all
nonterminals will be checked on their ability to derive a
terminal string instead of only checking the axiom for this.
The function can generate exceptions partype
(if the
parameters have wrong types) or invgrammar
if the
description is a bad grammar. The function can also generate
exception pmemory
if there is no memory for internal
parser data.
The description is similiar to the YACC one. It has
the following syntax:
file : file terms [';']
| file rule
| terms [';']
| rule
terms : terms IDENTIFIER ['=' NUMBER]
| TERM
rule : IDENTIFIER ':' rhs [';']
rhs : rhs '|' sequence [translation]
| sequence [translation]
sequence :
| sequence IDENTIFIER
| sequence C_CHARACTER_CONSTANT
translation : '#'
| '#' NUMBER
| '#' '-'
| '#' IDENTIFIER [NUMBER] '(' numbers ')'
numbers :
| numbers NUMBER
| numbers '-'
So the description consists of terminal declaration and
rule sections.
The terminal declaration section describes the name of
terminals and their codes. The terminal code is optional. If
it is omitted, the terminal code will the next free code
starting with 256. You can declare a terminal several times
(the single condition is that its code should be the same).
A character constant present in the rules is a terminal
described by default. Its code is always the ASCII code of the
character constant.
Rules syntax is the same as YACC rule syntax. The
single difference is an optional translation construction
starting with #
right after each alternative. The
translation part could be a single number which means that the
translation of the alternative will be the translation of the
symbol with the given number (symbol number in the alternative
start is with 0). Or the translation can be empty or
`-
' which designates the value of the variable
nil_anode
. Or the translation can be an abstract node
with the given name, optional cost, and with fields whose
values are the translations of the alternative symbols with
numbers given in parentheses after the abstract node name. You
can use `-
' in an abstract node to show that the empty
node should be used in this place. If the cost is absent it is
believed to be 1. The cost of the terminal, error node, and
empty node is always zero.
There is a reserved terminal error
which marks the
start point of error recovery. The translation of the terminal
is the value of the variable error_anode
.
set_debug (level)
. This function sets up the
level of debugging information output to stderr
. The
higher the level, the more information is output. The default
value is 0 (no output). The debugging information includes
statistics, the result translation tree, the grammar, parser
sets, parser sets with all situations, situations with
contexts. The function returns the previously set up debug
level. Setting up a negative debug level results in output of
the translation for program dot of the graphic
visualization package graphviz. The parameter should
be an integer after implicit integer conversion. The function
will generate exception partype
if it is not true.set_one_parse (flag)
. This function sets up a
flag whose nonzero value means building only one translation
tree (without any alternative nodes). For an unambiguous
grammar the flag does not affect the result. The function
returns the previously set up flag value. The default value of
the flag is 1. The parameter should be an integer after
implicit integer conversion. The function will generate
exception partype
if it is not true.set_lookahead (flag)
. This function sets up a
flag of of usage of look ahead in the parser work. The usage
of lookahead gives the best results with the point of view of
space and speed. The default value is 1 (the lookahead usage).
The function returns the previously set up flag. No usage of
the lookahead is useful sometimes to get more understandable
debug output of the parser work (see function
set_debug
). The parameter should be an integer after
implicit integer conversion. The function will generate the
exception partype
if it is not true.set_cost (flag)
. This function sets up building
the only translation tree (trees if we set up one_parse_flag to
0) with minimal cost. For an unambiguous grammar the flag does
not affect the result. The default value is 0. The function
returns the previously set up flag value. The default value of
the flag is 0. The parameter should be an integer after
implicit integer conversion. The function will generate
exception partype
if it is not true.set_recovery (flag)
. This function sets up a flag
whose nonzero value means making error recovery if a syntax
error occurred. Otherwise, a syntax error results in finishing
parsing (although the syntax error function passed to
parse
is called once). The function returns the
previously set up flag value. The default value of the flag is
1. The parameter should be an integer after implicit integer
conversion. The function will generate exception
partype
if it is not true.set_recovery_match (n_toks)
. This function sets
up an internal parser parameter meaning how much subsequent
tokens should be successfully shifted to finish error recovery.
The default value is 3. The function returns the previously
set up value. The parameter should be an integer after
implicit integer conversion. The function will generate
exception partype
if it is not true.
parse (tokens, error_func)
. This function is the
major function of the class. It makes translation according to
the previously set up grammar of input given by the parameter
tokens
whose value should be an array of objects of
predeclared class token
. If the parser recognizes a
syntax error it calls the function given through parameter
error_func
with six parameters:
tokens
) on which
the syntax error occured.tokens
)
ignored due to error recovery.tokens
)
which is not ignored after error recovery.set_recovery
, the third and fifth parameters
will be negative and forth and sixth parameter will be
nil.
The function returns an object of the predeclared class
anode
which is the root of the abtsract tree
representing the translation of the parser input. The function
returns nil only if syntax error was occurred and
error recovery was switched off. The function can generate
exception partype
if the parameter types are wrong or
exception invtoken_decl
if any of the input tokens
have a wrong code. The function also can generate exception
pmemory
if there is no memory for internal parser
data.The call of the class parser
itself can generate exception
pmemory
if there is no memory for internal parser
data.
Dino has a predeclared class token
. Objects of this class
should be the input of the Earley parser (see function parse
in class parser
). The result abstract tree representing the
translation will have input tokens as leaves. The class
token
has one public variable code
whose value
should be the code of the corresponding terminal described in the
grammar. You could extend the class description e.g. by adding
variables whose values could be attributes of the token (e.g. source
line number, name of an identifier, or value for a number).
Dino has a predeclared class anode
whose objects are nodes of
the abtract tree representing the translation (see function
parse
of class parser
). Objects of this class are
generated by the Earley parser. The class has two public variables
name
whose value is string representing name of the abstract
node as it given in the grammar and transl
whose value is
array with abstract node fields as the array elements. There are a
few node types which have special meaning:
$term
. The
value of the public variable transl
for this node is
an object of class token
representing the
corresponding input token which was an element of the array
passed as a parameter of function parse
of function
parser
.$error
. This
node exists in one exemplar (see description of variable
error_anode
) and represents the translation of
reserved grammar symbol error
. The value is public
variable transl
will be nil in this case.$nil
.
This node also exists in one exemplar (see description of
variable nil_anode
) and represents the translation of
a grammar symbol for which we did not describe a translation.
For example, in a grammar rule an abstract node refers for the
translation of a nonterminal for which we do not produce a
translation. The value is public variable of such class object
will be nil in this case.$alt
.
It represents all possible alternatives in the translation of
the grammar nonterminal. The value of the public variable
transl
will be an array with elements whose values are
objects of class anode
which represent all possible
translations. Such nodes can be generated by the parser only
if the grammar is ambiguous and we did not ask it to produce
only one translation.There is only one instance of anode
which represents empty
(nil) nodes. The same is true for the error nodes. The final
variables nil_anode
and error_anode
correspondingly
refer to these nodes.
Let us write a program which transforms an expression into postfix
polish form. Please, read the program comments to understand what the
code does. The program should output string "abcda*+*+"
which is the postfix polish form of input string
"a+b*(c+d*a)"
.
// The following is the expression grammar:
var grammar = "E : E '+' T # plus (0 2)\n\
| T # 0\n\
| error # 0\n\
T : T '*' F # mult (0 2)\n\
| F # 0\n\
F : 'a' # 0\n\
| 'b' # 0\n\
| 'c' # 0\n\
| 'd' # 0\n\
| '(' E ')' # 1";
// Create parser and set up grammar.
var p = parser ();
p.set_grammar (grammar, 1);
// Add attribute repr to token:
ext token { var repr; }
// The following code forms input tokens from string:
var str = "a+b*(c+d*a)";
var i, inp = [#str : nil];
for (i = 0; i < #str; i++) {
inp [i] = token (str[i] + 0);
inp [i].repr = str[i];
}
// The following function output messages about syntax errors
// syntax error recovery:
func error (err_start, err_tok,
start_ignored_num, start_ignored_tok_attr,
start_recovered_num, start_recovered_tok) {
put ("syntax error on token #", err_start,
" (" @ err_tok.code @ ")");
putln (" -- ignore ", start_recovered_num - start_ignored_num,
" tokens starting with token #", start_ignored_num);
}
var root = p.parse (inp, error); // parse
// Output translation in polish inverse form
func pr (r) {
var i, n = r.name;
if (n == "$term")
put (r.transl.repr);
else if (n == "mult" || n == "plus") {
for (i = 0; i < #r.transl; i++)
pr (r.transl [i]);
put (n == "mult" ? "*" : "+");
}
else if (n != "$error") {
putln ("internal error");
exit (1);
}
}
pr (root);
putln ();
The predeclared functions expect a given number of actual parameters
(may be a variable number of parameters). If the actual parameter
number is an unexpected one, exception parnumber
is
generated. The predeclared functions believe that the actual
parameters (may be after implicit conversions) are of the required
type. If this is not true, exception partype
is generated.
To show how many parameters the function requires, we will write the
names of the parameters and use brackets [
and ]
for
the optional parameters in the description of the functions.
Examples: The following description
strtime ([format [, time]])
describes that the function can accept zero, one, or two
parameters. If only one parameter is given, then this is
parameter format
.
If something is not said about the returned result, the function returns the default value nil.
The following functions make implicit arithmetic conversion of the parameters. After the conversions the parameters are expected to be of integer or floating point type. The result is always a floating point number.
sqrt (x)
. The function returns the square root of
x
. The function generates the exception edom
if x
is negative.exp (x)
. The function returns e
(the
base of the natural logarithm) raised to the power of
x
.log (x)
. The function returns the natural
logarithm of x
. The function generates the exception
edom
if x
is negative or may generate
syserrors.erange
if the value is zero.log10 (x)
. The function returns the decimal
logarithm of x
. The function generates the exception
edom
if x
is negative or may generate
syserrors.erange
if the value is zero.pow (x, y)
. The function returns x
raised to the power of y
. The function generates
exception edom
if x is negative and y is not of
integral value.sin (x)
. The function returns the sine of
x
.cos (x)
. The function returns the cosine of
x
.atan2 (x, y)
. The function returns the arc
tangent of the two variables x
and y
. It is
similar to calculating the arc tangent of y / x
,
except that the signs of both arguments are used to determine
the quadrant of the result.Dino has the predeclared functions which are used for pattern matching. The pattern is described by regular expressions (regex). The pattern has syntax of extended POSIX (1003.2) regular expressions, i.e. the pattern has the following syntax:
Regex = Branch {"|" Branch}
A regex matches anything that matches one of the branches.
Branch = {Piece}
A branch matches a match for the first piece, followed by a
match for the second piece, etc. If the pieces are omitted, the
branch matches the null string.
Piece = Atom ["*" | "+" | "?" | Bound]
Bound = "{" Min ["," [Max]] "}" | "{" "," Max "}"
Min = <unsigned integer between 0 and 255 inclusive>
Max = <unsigned integer between 0 and 255 inclusive>
An atom followed by *
matches a sequence of 0 or
more matches of the atom. An atom followed by +
matches a
sequence of 1 or more matches of the atom. An atom followed by
?
matches a sequence of 0 or 1 matches of the atom.
There is a more general construction (a bound) for describing
repetitions of an atom. An atom followed by a bound containing only
one integer min
matches a sequence of exactly min
matches of the atom. An atom followed by a bound containing one
integer min
and a comma matches a sequence of min
or
more matches of the atom. An atom followed by a bound containing a
comma and one integer Max
matches at most Max
repetitions of the atom. An atom followed by a bound containing two
integers min
and max
matches a sequence of
min
through max
(inclusive) matches of the atom.
Atom = "(" Regex ")"
| "(" ")"
| "."
| "^"
| "$"
| BracketedList
| "\^"
| "\["
| "\$"
| "\("
| "\)"
| "\*"
| "\+"
| "\?"
| "\{"
| "\."
| <any pair the first character is \ and the second is any
except for ^.[$()|*+? >
| <any character except for ^.[$()|*+? >
A regular expression enclosed in ()
can be an atom. In this
case it matches a match for the regular expression in the
parentheses). The atom ()
matches the null string. The atom
.
matches any single character. Atoms ^
and
$
match correspondingly the null string at the beginning of a
line and the null string at the end of a line.
An atom which is \
followed by one of the characters
^.[$()|*+?{\
matches that character taken as an ordinary
character. Atom which is \
followed by any other character
matches the second character taken as an ordinary character, as if the
\
had not been present. So you should use \\
for
matching with a single \
. An atom which is any other single
character matches that character. It is illegal to end a regular
expression with \
. There is an exception which is not
described by the atom syntax. An {
followed by a character
other than a digit or comma is an ordinary character, not the
beginning of a bound and matches the character {
.
BracketedList = "[" List "]"
List = FirstChar ["-" Char] {Char ["-" Char]}
FirstChar = <any character except for ^ - and ]>
| CollatingElement
Char = FirstChar
| "^"
CollatingElement = "[:" Class ":]"
Class = "alnum"
| "alpha"
| "blank"
| "ctrl"
| "digit"
| "graph"
| "lower"
| "print"
| "punct"
| "space"
| "upper"
| "xdigit"
An atom can be a bracket expression which is a list of
characters enclosed in []
. Usually it is used to match any
single character from the list. If the list begins with ^
,
it matches any single character (but see below) not in the list. If
two characters in the list are separated by -
, this is
shorthand for the full range of characters between those two
(inclusive) in the collating sequence of ASCII codes,
e.g. [0-9]
matches any decimal digit. It is illegal for two
ranges to share an endpoint, e.g. a-c-e
.
There are exceptions which are not described by the atom syntax which
is used to include a literal ]
in the list by making it the first
character (following a possible ^
). To include a literal
-
, make it the first or the last character, or the second
endpoint of a range. As you can see from the syntax, all special
characters (except for [
) described in an atom lose their
special significance within a bracket expression.
A collating element is a name of a character class enclosed in
[:
and :]
. It denotes the list of all characters
belonging to that class. Standard character class names are:
alnum digit punct
alpha graph space
blank lower upper
cntrl print xdigit
These names stand for the character classes defined in the ANSI C
include file ctype.h
. There is an exception not described by
the syntax: a character class can not be used as an endpoint of a
range.
There is an extension of regular expressions used by DINO and of ones defined in Posix 1003.2: no particular limit is imposed on the length of the regular expression.
There are the following Dino pattern matching functions:
match (regex, string)
. The function searches for
the matching regular expression regex
in
string
. The both parameters should be strings after
their implicit string conversion. The matching is made
according to the standard POSIX 1003.2: The regular expression
matches the substring starting earliest in the string. If the
regular expression could match more than one substring starting
at that point, it matches the longest. Subexpressions also
match the longest possible substrings, subject to the
constraint that the whole match be as long as possible, with
subexpressions starting earlier in the regular expression
taking priority over ones starting later. In other words,
higher-level subexpressions take priority over their component
subexpressions. Match lengths are measured in characters, not
collating elements. A null string is considered longer than no
match at all. If there is no matching, the function returns
the value nil. Otherwise, the function returns a new
mutable vector of integers. The length of the vector is 2
* (N + 1)
where N
is the number of atoms which
are regular expressions in parentheses. The first two elements
are the index of the first character of the substring
corresponding to the whole regular expression and the index of
the last character matched plus one. The subsequent two
elements are the index of the first character of the substring
corresponding to the first atom in the regular expression (the
atoms are ordered by their open parentheses) and the index of
the last character plus one, and so on. If there is no
matching with a regular expression in parentheses, the
corresponding vector elements will have negative values.
Example: The program
println (match ("()(a)((a)(a))", "baaab"));
outputs
[1, 4, 1, 1, 1, 2, 2, 4, 2, 3, 3, 4]
gmatch (regex, string[, flag])
. The function
searches for different occurrences of regular expression
regex
in string
. Both parameters should
be strings after their implicit string conversion. The third
parameter is optional. If it is present, it should be integer
after implicit integer conversion. If its value is nonzero,
the substrings matched by regexp can be overlapped. Otherwise,
the substrings are never overlapped. If the parameter is
absent, the function behaves as its value were zero. The
function returns a new mutable vector of integers. The length
of the vector is 2 * N
where N
is number of
the found occurrences. Pairs of the vector elements correspond
to the occurrences. The first element of the pairs is index of
the first character of substring corresponding to all regular
expression in the corresponding occurrences and the second
element is index of the last character plus one. If there is
no one occurrence, the function returns nil.
Example: The program
println (gmatch ("aa", "aaaaa"));
println (gmatch ("aa", "aaaaa", 1));
outputs
[0, 2, 2, 4]
[0, 2, 1, 3, 2, 4, 3, 5]
sub (regex, string, subst)
. The function searches
for substrings matching the regular expression regex
in string
. All parameters should be string after
implicit string conversion. If there is no matching, the
function returns the value nil. Otherwise, the
function returns a new mutable vector of characters in which
the first substring matched has been changed to the string
subst
. Within the replacement string subst
,
the sequence \n
, where n
is a digit from 1 to
9, may be used to indicate the text that matched the
n
'th atom of the regex in parentheses. The sequence
\0
represents the entire matched text, as does the
character &
.gsub (regex, string, subst)
. The function is
analogous to the function sub
except for the function
searches for all non-overlapping substrings matched with the
regular expression and returns a new mutable vector of
characters in which all matched substrings have been changed to
the string subst
.split (string [, regex])
. The function splits
string
into non-overlapped substrings separated by
strings matching the regular expression. All parameters should
be strings after implicit string conversion. If the second
parameter is omitted the value of the predeclared variable
split_regex
is used instead of the second parameter
value. In this case the function may generate the exception
invenvar
(corrupted value of a predeclared variable).
The function returns a new mutable vector with elements which
are the separated substrings. If the regular expression is the
null string, the function returns a new mutable vector with
elements which are strings each containing one character of
string.
Examples: The program
println (split ("aaa bbb ccc ddd"));
outputs
["aaa", "bbb", "ccc", "ddd"]
The program
println (split ("abcdef", ""));
outputs
["a", "b", "c", "d", "e", "f"]
ebrack
. Regular expression has unmatched bracket.invregexps.erange
. Invalid use of range in regular
expression.ectype
. Unknown character class name in regular
expression.eparen
. Regular expression has unmatched
parenthesis.esubreg
. Invalid back reference to a
subexpression in regular expression.eend
. Non specific error in regular expression.eescape
. Invalid escape sequence in regular
expression.ebadpat
. Invalid use of pattern operators in
regular expression.esize
. Compiled regular expression is too big.espace
. No memory for the regular expression
function to work.Dino has some predeclared functions to work on files and directories.
The following predeclared functions can be used for accessing file or
directory information. The functions may generate an exception
declared in the class syserror
(e.g. eaccess
,
enametoolong
, enfile
and so on) besides the standard
partype
, and parnumber
. The functions expect one
parameter which should be a file instance (see the predeclared class
file
) or the path name of a file represented by a string (the
functions make implicit string conversion of the parameter). The
single exception to this is isatty
which expects a file
instance.
ftype (fileinstance_or_filename)
. The function
returns one the following characters:
'f'
. A regular file.'d'
. A directory.'L'
. A symbolic link.'c'
. A character device.'b'
. A block device.'p'
. A fifo.'S'
. A socket.fun (fileinstance_or_filename)
. The function
returns new string representing name of owner of the file
(directory). Under some OSes the function may return the new
string "Unknown"
if there is no notion "owner" in the
OS file system.fgn (fileinstance_or_filename)
. Analogous to the
previous function except for it returns a new string
representing name of the group of the file (directory). Under
some OSes the function may return the new string
"Unknown"
if there is no notion "group" in the OS file
system.fsize (fileinstance_or_filename)
. The function
returns an integer value which is the length of the file in
bytes.fatime (fileinstance_or_filename)
. The function
returns integer value which is time of the last access to the
file (directory). The time is measured in seconds since the
fixed time (usually since January 1, 1970). See also time
functions.fmtime (fileinstance_or_filename)
. Analogous to
the previous functions but returns the time of the last
modification.fctime (fileinstance_or_filename)
. Analogous to
the previous functions but it returns the time of the last
change. Here `change' usually means changing the file
attributes (owner, modes and so on), while `modification' means
usually changing the file itself.fumode (fileinstance_or_filename)
. The function
returns a new string representing the rights of the owner of
the file (directory). The string may contain the following
characters (in the following order if the string contains more
than one character):
's'
. Sticky bit of the file (directory).'r'
. Right to read.'w'
. Right to write.'x'
. Right to execute.fgmode (fileinstance_or_filename)
. Analogous to
the previous function except for the fact that it returns
information about the file (directory) group user rights and
that the function never returns a string containing the
character 's'
.fomode (fileinstance_or_filename)
. Analogous to
the previous function except for the act that it returns
information about the rights of all other users.isatty (fileinstance)
. The function returns 1 if
the file instance given as a parameter is an open file
connected to a terminal and 0 otherwise.fumode
). The functions always
return the value nil.
chumod (path, mode)
. The function sets up rights
for the file (directory) owner according to the given mode.chgmod (path, mode)
. Analogous to the previous
function except for the fact that it sets up rights for the
file (directory) group users and that the function ignores the
character 's'
.chomod (path, mode)
. Analogous to the previous
function except for the fact that it sets up rights for all
other users.The following functions work with directories. The functions may
generate an exception declared in class syserror
(e.g. eaccess
, enametoolong
, enotdir
and so
on) besides the standard partype
, parnumber
.
readdir (dirpath)
. The function makes implicit
string conversion of the parameter value which should be a
string (directory path). The function returns a new mutable
vector with elements which are strings representing names of
all files and sub-directories (including "."
and
".."
for the current and parent directory
respectively) in given directory.mkdir (dirpath)
. The function creates a directory
with the given name represented by a string (the parameter
value after implicit string conversion). The directory has
read/write/execute rights for all. You can change it with the
aid of the functions ch*mod
.rmdir (dirpath)
. The function removes the
directory given by a string which is parameter value after
implicit string conversion.getcwd ()
. The function returns a new string
representing the full path of the current directory.chdir (dirpath)
. The function makes the directory
given by dirpath
(which should be a string after
implicit string conversion) the current directory.The following functions (besides input/output functions) work with OS
files. The functions may generate an exception declared in the class
syserror
(e.g. eaccess
, enametoolong
,
eisdir
and so on) besides the standard partype
,
and parnumber
. The function rename
can be used for
renaming a directory, not only a file.
rename (old_path, new_path)
. The function renames
the file (directory) given by its path name. The old and new
names are given by parameter values which should be strings
after implicit string conversion.remove (file_path)
. The function removes the OS
file given by its path name. The file path name should be a
string after implicit string conversion.open (file_path, mode)
. The function opens the
file for work in the given mode, creates a new class
file
instance, associates the opened file with the
instance, and returns the instance. The parameter values
should be strings after implicit string conversions. The first
parameter value is a string representing the file path. The
second parameter value is string representing the mode for work
with the file (for all possible modes see the ANSI C function
fopen
documentation). All work with an opened file is
made through the file instance.close (fileinstance)
. The function closes a file
opened by the function open
. The file is given by the
class file
instance. The function also removes all
association of the instance with the file.flush (fileinstance)
. The function flushes any
output that has been buffered for the opened file given by
the class file
instance.popen (command, mode)
. The function starts the
shell command given by the first parameter value (which should
be a string after implicit string conversion), creates a pipe,
creates a new class file
instance, associates the pipe
with the instance, and returns the instance. Writing to such a
pipe (through the class file instance) writes to the standard
input of the command. Conversely, reading from the pipe reads
the command's standard output. After implicit string
conversion the second parameter value should be the string "r"
(for reading from the pipe) or "w" (for writing to the pipe).
The pipe should be closed by the function pclose
.pclose (fileinstance)
. The function waits for the
command connected to a pipe to terminate. The pipe is given by
the class file
instance returned by the function
popen
. The function also removes the association of
the instance with the pipe.tell (fileinstance)
. The function returns the
current value of the file position indicator for the file
(opened by function open
) given by the class
file
instance.seek (fileinstance, offset, whence)
. The function
sets up the current file position indicator for the file
(opened by function open
) given by the class
file
instance. The position is given by
offset
which should be an integer after implicit
arithmetic conversion and whence
which should be a
string after implicit string conversion. The first character
of the string should be 's'
, 'c'
, or
'e'
(these characters mean that the offset is relative
to the start of the file, the current position indicator, or
the end-of-file, respectively).The following functions are used to output something into opened
files. All the functions always return the value nil. The
functions may generate an exception declared in the class syserror
(e.g. eio
, enospc
and so on) besides the standard
partype
, and parnumber
.
put (...)
. All parameters should be strings after
implicit string conversion. The function outputs all strings
into the standard output stream.putln (...)
. The function is analogous to the
function put
except for the fact that it additionally
outputs a new line character after output of all the strings.fput (fileinstance, ...)
. The function is
analogous to the function put
except for the fact that
it outputs the string into an opened file associated with a
class file
instance which is the first parameter
value.fputln (fileinstance, ...)
. The function is
analogous to function fput
except for the fact that it
additionally outputs a new line character after output of all
the strings.
putf (format, ...)
. The first parameter should be
strings after implicit string conversion. The function outputs
the rest of parameters according to the format. The number of
the rest parameters should be exactly equal to the conversions
(including parameterized widths and precisions) in the format.
Otherwise, exception parnumber
will be generated. The
types of the parameter should correspond to the corresponding
conversion specifier (or to be integer for parameterized widths
and precisions). If it is not true, exception partype
will be generated. The format is subset of one of standard C
function printf
and has the following syntax:
format : <any character except %>
| '%' flags [width] [precision]
conversion_specifier
flags :
| flag
flag : '#' | '0' | '-' | ' ' | '+'
width : '*' | <decimal number starting with non-zero>
precision : '.' ['*' | <decimal number>]
conversion_specifier : 'd' | 'o' | 'x' | 'X'
| 'e' | 'E' | 'f' | 'g'
| 'G' | 'c' | 's' | '%'
If the format syntax is wrong, exception invfmt
is
generated.
Flag '#' means that the value should be converted into an
alternative form. It can be present only for conversion
specifiers 'o', 'x', 'X', 'e', 'E', 'f', 'g', and 'G'. If the
flag is used for conversion specifier 'o', the output will be
prefixed by '0'. For 'x' and 'X' the output will be prefixed
by '0x' and '0X' correspondingly. For conversions 'e', 'E',
'f', 'g', and 'G' the output will always contain a decimal
point. For conversions 'g' and 'G' it also means that trailing
zeros are not removed from the output as they would be without
the flag. The following code using flag '#' in format
putf ("->%#o %#x %#.0e %#.0f %#g\n", 8, 10, 2., 3., 4.);
will output
->010 0xa 2.e+00 3. 4.00000
Flag '0' means that the output value will be zero padded on the
left. If both flags '0' and '-' appear, the flag '0' is
ignored. It is also ignored for conversions 'd', 'o', 'x', and
'X' if a precision is given. The flag is prohibited for
conversions 'c' and 's'. The following code using flag '0' in
format
putf ("->%04d %04x %09.2e %05.2f %05.2g\n", 8, 10, 2., 3., 4.);
will output
->0008 000a 02.00e+00 03.00 00004
Flag '-' means that the output will be left adjusted on the
field boundary. (The default is right justification). Flag '-'
overrides flag '0' if the both are given. The following code
using flag '-' in format
putf ("->%-04d %-04x %-09.2e %-05.2f %-05.2g\n",
8, 10, 2., 3., 4.);
will output
->8 a 2.00e+00 3.00 4
Flag ' ' means that the output of a signed number will start
with a blank for positives number. The flag can be used only
for conversions 'd', 'e', 'E', 'f', 'g', and 'G'. If both
flags ' ' and '+' appear, the flag ' ' is ignored. The
following code using flag ' ' in format
putf ("->% d % .2e % .2f % .2g\n", 8, 2., 3., 4.);
will output
-> 8 2.00e+00 3.00 4
Flag '+' means that the output of a signed number will start
with a plus for positives number. The flag can be used only
for conversions 'd', 'e', 'E', 'f', 'g', and 'G'. Flag '+'
overrides flag ' ' if both are given. The following code using
flag '+' in format
putf ("->%+d %+.2e %+.2f %+.2g\n", 8, 2., 3., 4.);
will output
->+8 +2.00e+00 +3.00 +4
The width defines a minimum width of the output value. If the
output is smaller, it is padded with spaces (or zeros -- see
flag '0') on the left (if flag '-' is used) or right. The
output is never truncated. The width should be no more than
maximal integer value, otherwise exception invfmt
is
generated. The width can be given as a parameter of integer
type if '*' is used. If the value of width given by the
parameter is negative, flag '-' is believed to be given and the
width is believed to be equal to zero. The following code
using width in format
putf ("->%5d %05d %-5d %*d %*d<-\n", 8, 9, 10, 5, 8, -5, 10);
will output
-> 8 00009 10 8 10 <-
The precision is prohibited for conversions 'c'. If the number
after the period is absent, its value will be zero. The
precision can be given as a parameter of integer type if '*' is
used after the period. If the value of precision given by the
parameter is negative, its value is believed to be zero too.
For conversions 'd', 'o', 'x', and 'X' the precision means
minimum number of output digits. For conversions 'e', 'E', and
'f' it means the number of digits to appear after the decimal
point. For 'g' and 'G' it means the maximum number of
significant digits. For 's' it means the maximum number of
characters to be output from a string. The following code
using precision in format
putf ("->%.d %.0d %.5d %.0f %.0e %.2g<-\n",
8, 8, 9, 2.3, 3.53);
putf ("->%.2s %.0d %.*d %.*d<-\n", "long", 0, 5, 8, -5, 8);
will output
->8 8 00009 2 2e+00 3.5<-
->lo 00008 8<-
Conversion 'd' should be used to output integer. The default
precision is 1. When 0 is output with an explicit precision 0,
the output is empty.
Conversions 'o', 'x', and 'X' should be used to output an
integer value as unsigned in octal and hexadecimal form. The
lower case letters abcdef
are used for 'x' and the
upper case letters ABCDEF
are used for 'X'. The
precision gives the minimum number of digits that must
appear. If the output value requires fewer digits, it is padded
on the left with zeros. The default precision is 1. When 0 is
output with an explicit precision 0, the output is empty.
Conversion 'f' should be used to output floating point values.
The output value has a form [-]ddd.ddd
where the
number of digits after the decimal point is given by the
precision specification. The default precision value is 6. If
the precision is explicitly zero, no decimal-point character
appears.
Conversions 'e' and 'E' should be used to output floating point
values with an exponent in form [-]d.ddd[e|E][+|-]dd
.
There is always one digit before the decimal-point. The number
of digits after the decimal point is defined by the precision.
The default precision value is 6. If the precision is zero, no
decimal-point appears. Conversion 'E' uses the letter
E
(rather than e
) to introduce the exponent.
The exponent always contains at least two digits. If the
exponent value is zero, the exponent is output as 00
.
Conversions 'g' and 'G' should be used to output floating point
values in style 'f' or 'e' (or 'E' for conversion 'G'). The
precision defines the number of significant digits. The
default value of the precision is 6. If the precision is zero,
it is treated as 1. Conversion 'e' is used if the exponent
from the conversion is less than -4 or not less than the
precision. Trailing zeros are removed from the fractional part
of the output. If all fractional part is zero, the decimal
point is removed too.
Conversion 'c' should be used to output a character value.
Conversion 's' should be used to output strings.
Conversion '%' should be used to output %
.
The following code using different conversions in format
putf ("->%% %c %s %d %o %x %X<-\n",
'c', "string", 7, 8, 20, 20);
putf ("->%f<-\n", 1.5);
putf ("->%e %E %g %G %g %G<-\n",
2.8, 2.8, 3.7, 3.7, 455555555.555, 5.9e-5);
will output
->% c string 7 10 14 14<-
->1.500000<-
->2.800000e+00 2.800000E+00 3.7 3.7 4.55556e+08 5.9E-05<-
fput (fileinstance, format, ...)
. The function is
analogous to the function putf
except for the fact that
it outputs the string into an opened file associated with a
class file
instance which is the first parameter
value.print (...)
. The function outputs all parameter
values into standard output stream. The function never makes
implicit conversions of the parameter values. The parameter
values are output as they could be represented in Dino itself
(e.g. character 'c'
is output as 'c'
, vector
['a', 'b', 'c']
is output as "abc"
, vector
[10, 20]
as [10, 20]
and so on). As you know
some values (functions, classes, block instances, class
instances, threads) are not represented fully in DINO. Such
values are represented schematically. For example, the output
func f {}.g(unique_number)
would mean function
f
in the call of function (or class) g
with
the given unique number and function g is in the instance of
the implicit block covering the whole program. For the
function g
, output would look simply like func
g
because there is only one instance of the implicit block
covering the whole program. Output for an instance of the
class c
in the function f
looks like
instance {}.f(unique_number).c(unique_number)
. Output
for a block instance of the function f
looks like
stack {}.f(unique_number)
. Output for a thread whose
thread-function t
is declared in the function
f
would look like thread unique_number
{}.f(unique_number).t(unique_number)
.println (...)
. The function is analogous to the
function print
except for the fact that it
additionally outputs new line character after output of all
parameters.fprint (fileinstance, ...)
. The function is
analogous to the function print
except for the fact
that it outputs the parameters into an opened file associated
with a class file
instance which is the value of first
parameter.fprintln (fileinstance, ...)
. The function is
analogous to function fprint
except for the fact that
it additionally outputs a new line character after the output
of all the parameters.The following functions are used to input something from opened files.
All the functions always return the value nil. The functions
may generate an exception declared in the class syserror
(e.g. eio
, enospc
and so on) or eof
besides
the standard partype
, and parnumber
.
get ()
. The function reads one character from
standard input stream and returns it. The function generates
the exception eof
if the function tries to read the
end of file.getln ()
. The function reads one line from
standard input stream and returns it as a new string. The end
of line is the newline character or end of file. The returned
string does not contain the newline character. The function
generates the exception eof
only when the file
position indicator before the function call stands exactly on
the end of file.getf ([ln_flag])
. The function reads the whole
standard input stream and returns it as a new string. The
function generates the exception eof
only when the
file position indicator before the function call stands exactly
on the end of file. The function has an optional parameter
which should be integer after implicit integer conversion. If
the parameter value is nonzero, the function returns a vector
of strings. Otherwise it behaves as usually. Each string is a
line in the input stream. The strings do not contain the
newline character.fget (fileinstance)
. The function is analogous to
function get
except for the fact that it reads from an
opened file associated with the class file
instance
which is the parameter's value.fgetln (fileinstance)
. The function is analogous
to the function getln
except for the fact that it
reads from an opened file associated with a class file
instance which is the parameter value.fgetf (fileinstance [, ln_flag])
. The function is
analogous to the function getf
except for the fact
that it reads from an opened file associated with a class
file
instance which is the parameter's value.scan ()
. The functions reads a character,
integer, floating point number, string, vector, or table and
returns it as the result. The input values should be
represented in the file as the ones in the Dino language
(except for the fact that there should be no identifiers in the
input values and there should be no operators in the values,
although the signs +
and -
are possible in an
integer or floating point represenation). The table or vector
should contains only values of types mentioned above. The
values in the file can be separated by white characters. If
there is an error (e.g. unbalanced brackets in a vector value)
in the read value representation the function generates the
exception invinput
. The functions generates the
exception eof
if only white characters are still
unread in the file.scanln ()
. The function is analogous to the
function scan
except for the fact that it skips all
characters until the end of line or the end of file after
reading the value. Skipping is made even if the exception
invinput
is generated.fscan (fileinstance)
. The function is analogous
to the function scan
except for the fact that it reads
from an opened file associated with a class file
instance which is the parameter's value.fscanln (fileinstance)
. The function is analogous
to the function scanln
except for that it reads from
an opened file associated with a class file
instance
which is the parameter value.The following functions can be used to get information about real time.
time ()
. The function returns the time in seconds
since the fixed time (usually since January 1, 1970).strtime ([format [, time]])
. The function returns
a string representing the time
(integer representing
time in seconds since the fixed time) according to the
format
(string). If the format is not given, the
value of variable time_format
is used. In this case
if the value of time_format
is corrupted (it is not a
string), the function generates exception invenvar
.
If the time is not given, the current time is used. The format
is the same as in C library function strftime
. Here
is an extraction from the OS function documentation. The
following format specifiers can be used in the format:
%a
- the abbreviated weekday name according to
the current locale.%A
- the full weekday name according to the
current locale.%%b
- the abbreviated month name according to
the current locale.%%B
- the full month name according to the
current locale.%%c
- the preferred date and time
representation for the current locale.%%d
- the day of the month as a decimal number
(range 01 to 31).%%H
- the hour as a decimal number using a
24-hour clock (range 00 to 23).%%I
- the hour as a decimal number using a
12-hour clock (range 01 to 12).%%j
- the day of the year as a decimal number
(range 001 to 366).%%m
- the month as a decimal number (range 01
to 12).%%M
- the minute as a decimal number.%%p
- either `am' or `pm' according to the given time
value, or the corresponding strings for the current locale.%%S
- the second as a decimal number.%%U
- the week number of the current year as a
decimal number, starting with the first Sunday as the first
day of the first week.%%W
- the week number of the current year as a
decimal number, starting with the first Monday as the first
day of the first week.%%w
- the day of the week as a decimal, Sunday
being 0.%%x
- the preferred date representation for
the current locale without the time.%%X
- the preferred time representation for
the current locale without the date.%%y
- the year as a decimal number without a
century (range 00 to 99).%%Y
- the year as a decimal number including
the century.%%Z
- the time zone or the name or an
abbreviation.%%%
- a literal `%' character.There are Dino predeclared functions which are used to get information about the current OS process (the Dino interpreter which executes the program). Each OS process has unique identifier and usually OS processes are called by a concrete user and group and are executed on behalf of the concrete user and group (so called effective identifiers). The following functions return such information. On some OSes the function may return string "Unknown" as a name if there are notions of user and group identifiers.
getpid ()
. The function returns an integer value
which is the process ID of the current OS process.getun ()
. The function returns a new string which
is the user name for the current OS process.geteun ()
. The function returns a new string
which is the effective user name for the current OS process.getgn ()
. The function returns a new string which
is the group name for the current OS process.getegn ()
. The function returns a new string
which is the effective group name for the current OS process.getgroups ()
. The function returns a new vector
of strings (possibly the empty vector) representing
supplementary group names for the current OS process.There are the following miscellaneous functions:
max (v1, v2, ...)
. The function searches for and
returns the maximal value in all of its parameters. The
parameters should be of integer or floating point type after
implicit arithmetic conversion. So the function can return an
integer or floating point number depending on the type of the
maximal value after the conversion.min (v1, v2, ...)
. The function is analogous to
the previous function, but searches for and returns the minimal
value.tolower (str)
. The function expects that the
parameter str
(after implicit string conversion) is a
string. The function returns new string str
in which
upper case letters are changed to the corresponding lower case
letters.toupper (str)
. The function expects that
the parameter str
(after implicit string conversion) is
a string. The function returns the new string str
in which
lower case letters are changed to the corresponding upper case
letters.trans (str, what, subst)
. The function
transliterates charactes in a string. The function expects
that the parameters str
(after implicit string
conversion), what
, and subst
are strings.
The function returns the new string str
in which its
characters which are present in what
are changed to
the corresponding characters in <\tt>subst<\tt>. The last two
strings should have the same length. The second string may
contain more than one occurence of a character. In this case
the last correspondence is taken.eltype (vect)
. The function expects that the
parameter value is a vector. The function returns nil
if the vector is heterogenous, otherwise the function returns
the type of the vector elements (type of nil if the
vector is empty).keys (tab)
. The function expects that the
parameter value is a table. The function returns a new mutable
vector containing all the keys in the table. The order of keys
in the vector is undefined.context (par)
. The function returns the context
(see section Declarations and Scope Rules) represented
by a block instance or an object for the given parameter value
which should be a function, a class, a thread, a block
instance, or an object.inside (par1, par2[, flag])
. The goal for
function usage is to check that something is declared inside
something other. If the third parameter value after implicit
integer conversion is given and nonzero, it is checked with
taking contexts into account. The second parameter value
should be a function or a class. The first parameter value
should be a function, a class, an object, or a block instance.
In the first three cases, they define corresponding a function,
class, or block. If the function, class, or block defined by
the first parameter is declared inside the function or class
given by the second parameter, the function inside
returns 1. The function inside
also returns 1 if the
function or class defined by the first parameter is the same as
the function or class given by the second parameter. Otherwise
the function inside
returns 0. The following example
illustrates the difference between checking with taking
contexts into account and without it.
class c () {
class subc () {
}
}
inside (c ().subc (), c ().subc);
inside (c ().subc (), c ().subc, 1);
The first call of inside
returns 1, while the second
one returns 0.subv (vect, index[, length])
. The function is
used to extract a slice of vector elements. The first
parameter value should be a vector after implicit string
conversion. The second and third parameter values should be
integers after implicit integer conversion. The function
extracts only an element or the part of the slice existing in
the vector (so you can use any values of the index and the
length). If index is negative, it is considered to be equal to
zero. If the length is negative, the slice will finish on the
vector end. The function returns a new vector which is the
slice. The result vector is immutable only when the original
vector is immutable.del (vect, index[, length]) or del (tab, key)
.
The first form of the function is used to remove the vector
element or a slice of vector elements from the mutable vector
vect
. The second and the third parameter values
should be integers after implicit integer conversion. The
function removes only an element or the part of the slice
existing in the vector (so you can use any values of the index
and the length). If index is negative, it is considered to be
equal to zero. If the length is negative, the slice will
finish on the vector end. The second form of the function is
used to remove the element (if it exists) with the given key
from the mutable table. The function generates the exception
immutable
if we are trying to remove from an immutable
vector or table. The function returns the modified vector.ins (vect, el[, index])
. The function inserts the
element given by the second parameter into the vector given by
the first parameter on the place given by the third parameter.
If the third parameter is not given it is believed to be zero.
The third parameter should be an integer after implicit integer
conversion. If the third parameter is negative or equal to or
greater than the vector length, the element is inserted at the
end of the vector. The function generates the exception
immutable
if we are trying to insert into an immutable
vector. The function returns the modified vector.insv (vect, vect[, index])
. The function is
analogous to the function ins
but it is used for
insertion of all vector elements into the vector given as the
first parameter. So the second parameter value should be a
vector. The function returns the modified vector.rev (vect)
. The function returns reversion of the
given vector.cmpv (vect, vect)
. The function makes implicit
string conversion of the parameter values. After that, the
parameter values should be vectors whose first corresponding
equal elements should have the same type (character, integer,
or floating point type). The first corresponding unequal
elements should have the same type too (the remaining elements
can have different type). As usual, if this is not true,
exception partype
is generated. The function returns
1 if the first unequal element value of the first vector is
greater than the corresponding element in the second vector, -1
if less, and 0 if the all corresponding vector elements are
equal. If the first vector is a prefix of the second vector,
the function returns -1. If the second vector is a prefix of
the first vector, the function returns 1, so it is in fact
generalized lexicographical order.sort (vect[, compare_function])
. The function
returns a new sorted vector. The original vector given as the
first parameter value should be a homogeneous vector whose
elements are of character, integer, or floating point type. If
the second parameter is not given, standard arithmetic order
(see comparison operators) is used. To use special ordering,
use the second parameter which should be a function which
compares two elements of the vector and returns a negative
integer if the first parameter value (element) is less than the
second one, a positive integer if the first parameter value is
greater than the second one, and zero if they are equal.exit (code)
. The function finishes the work of
the interpreter with the given code which should be an integer
value after implicit integer conversion.gc ()
. The function forces garbage collection and
heap compaction. Usually the Dino interpreter itself invokes
garbage collection when there is no more free memory.system (command)
. The function executes the
command given by a string (the parameter value) in the OS
command interpreter. Besides standard exceptions
parnumber
and partype
the function may
generate exceptions noshell
and systemfail
.srand ([seed])
. The function sets the parameter
value (after implicit integer conversion) as the seed for a new
sequence of pseudo-random integers to be returned by
rand
. These sequences are repeatable by calling
srand
with the same seed value. If the parameter is
not given, the seed will be the result of calling function
time
.rand ()
. The function returns a pseudo-random
integer value. If the function srand
was not called
before, 1 will be used as the seed value.sput (...), sputln (...), sputf (format, ...)
The
functions are analogous to functions put, putln, print, and
println but they return the result string instead of output of
the formed string into the standard output stream.sprint (...), sprintln (...)
. The functions are
analogous to functions print and println but they return the
result string instead of output of the formed string into the
standard output stream.