|
|
|
The FunLog++ standard library provides functions for known number objects, text objects, list objects as well as for semiknown or unknown objects. Objects with dimensional units (for length, area, volume, mass, time) and absolute date objects can be also calculated by the standard library.
This document is still and will be under development (at least until
December 1998). Minor changes will occur without further notice. Last modification:
9 Jan 1998
is_unknown(A) | no information |
is_semiknown(A) | ambiguous or imprecise information |
is_known(A) | unambiguous and precise information |
is_empty(A) | no solution, e.g. due to failing or contradicting premises |
In FunLog++ tests usually may succeed or fail. The test result (in contrast
to Prolog) is an object. It is comfortable to include in each class a function
which succeeds if its parameter is of the respective class. But if the
parameter belongs to a different class we get an undefined_exception.
Therefore there is a postfix operator A? (see below) which
returns failure if the respective function A
returned an undefined_exception. So, e.g. to test if some
object X is unknown you will have to write is_unknown(X)?.
length; mass; duration; temperature; current, light; substance
is_number(A) | if A is a number then success otherwise undefined_exception. |
is_text(A) | if A is a text then success otherwise undefined_exception. |
is_list(A) | if A is a list then success otherwise undefined_exception. |
is_measure(A) | if A is a measure then success otherwise undefined_exception. |
is_date(A) | if A is a date then success otherwise undefined_exception. |
is_length(A) | if A is a length measure (in meters) then success otherwise undefined_exception. |
is_mass(A) | if A is a mass measure (in kilograms) then success otherwise undefined_exception. |
is_duration(A) | if A is a duration measure (in seconds) then success otherwise undefined_exception. |
is_temerature(A) | if A is a temperature measure (in Kelvins) then success otherwise undefined_exception. |
is_current(A) | if A is a current measure (in amperes) then success otherwise undefined_exception |
is_light(A) | if A is a light measure (in candels) then success otherwise undefined_exception |
is_substance(A) | if A is a substance measure (in moles) then success otherwise undefined_exception |
is_composed(A) | if A is a composed measure then success otherwise undefined_exception |
A :: B | If A is the unaccepted_exception then B otherwise A. |
A ! B | If =failure(A) then unaccepted_exception otherwise B. |
A ;; B | Disjunction of A and B (using backtracking, as in Prolog). |
A ,, B | Conjunction of A and B (using backtracking, as in Prolog). |
A \/ B | Disjunction of A and B (useful for semiknown objects A and/or B). |
A /\ B | Conjunction of A and B (useful for semiknown objects A and/or B). |
A ; B | If is_failure(A) then B otherwise A. |
A , B | If is_failure(A) then failure. If is_success(A) then B otherwise undefined_exception. |
A ? B | if is_undefined_exception(A) then B otherwise A |
A ? | if is_undefined_exception(A) then failure otherwise A |
A ?? B | if is_unknown(A) then B otherwise A |
A ?? | if is_unknown(A) then failure otherwise A |
success | This is the value returned for succeeding relations, e.g. 3<5. |
failure | This is the value returned for failing relations, e.g. 5<3. |
In order to select the wanted function depending on parameter objects types two new operators A!B and A::B were introduced. A!B is used to check the premises A (e.g. a type check) before an evaluation of message B. If the premise A fails then this function does not accepted the message and the next function of the program has to be tried. In so far the location of a function within a FunLog++ program may be of importance.
A,,B and A;;B work like A,B and A;B do in Prolog.
There is another pair of conjunction and disjunction, A /\ B and A \/ B.
With backtracking or semiknown conjunction or disjunction both operand
A
and B might backtrack or be ambiguous. But if we want that
disjunction A;;B should fail if A failed
(independent of B) then we can use A;B
instead. If we known that in a conjunction A,,B the left
operand A cannot backtrack then we can tell this to the
interpreter by using A,B instead (see above).
+ A | equivalent to A. Here + is a prefix operator. |
- A | equivalent to NULL-A where NULL is the null-element of the type of A. Example: -5 km = 0 km - 5 km. |
A + B | equivalent to A-(-B). Here + is an infix operator. |
A - B | the difference between A and B where A and B must be of the same object type. |
A * B | if B is the null-element then the null-element of the
type of A*B otherwise A/(1/B).
Example: 28 s * 0 m = 0 m*s. |
A / B | if B is not the null-element then the ratio of A and
B,
otherwise undefined_exception.
If A or B are measure-type-objects then the resulting type is selected accordingly, Example: 6 m2 / 3 m yields 2m. |
A // B | equivalent to (A/B)//1, where A and
B
must be of the same object-type and
where X//1 is the integer part of some number X. |
A % | equivalent to A/100 where A must be a number. % may be written as a postfix operator. |
sqrt(A) | equivalent to some number X so that A = X*X, where A must be a number. Here sqrt is a mere function without any syntactic prefix, infix, or postfix enhancement. So round brackets have to be used. |
ln(A) | equivalent to some number X so that A = exp(X) where A must be a number. |
exp(A) | the constant e (2.7183 approximately) raised to the power A where A must be a number. |
display(X) | This function converts any object X into a text representation for X. |
A & B | Concatenates the elements of A and B where A and B are both texts or both lists. |
A # B | This is equivalent to display(A) & display(B). |
[A,B,C] | This is the denotation of a list with elements A, B, and C. In general a list can be denoted in square brackets by the sequence of its elements separated by commas. |
[A,B,C,D|E] | A list of at least n elements where the rest in unknown may be denoted
in square brackets by the sequence
of the first n elements separated by commata (,) and followed by a vertical bar (|) and a unbound variable for the unknown rest of the list. |
sorted(L) | For this function it is required that order relation A<B is defined between all elements of L. Then sorted(L) returns a sorted list with the elements of L beginning with the smallest first. If some tested relation A<B is not defined than the undefined_exception is returned. |
From the composed units area (m2) and volume(m3) are supported by denotation functions (e.g. 5 m3) and the display/1 function. The other composed measures as there are frequency (1/s), velocity (m/s), acceleration (m/s2), force ('N'=kg*m/s2), density (kg/m3), specific gravity ('N'/m2), pressure ('Pa'='N'/m2), work=energy ('J'='N'*m), power ('W'='N'*m/s), turning moment ('N'*m), impulse (kg*m/s) have to be specified in terms of the basic SI units.
N m | a length type object where N is the number of meters. |
N km | equivalent to (N*1000) m. |
N cm | equivalent to (N/100) m. |
N mm | equivalent to (N/10) cm. |
N um | equivalent to (N/1000) mm. |
N nm | equivalent to (N/1000) um. |
N 'Mpc' | equivalent to (N*1000) kpc. |
N kpc | equivalent to (N*1000) pc. |
N pc | equivalent to (N*206264.8) 'AE'. (parsec) |
N ly | equivalent to (N*9460500000000) km. (light year) |
N 'AE' | equivalent to (N*149597870) km. (astronomic unit) |
N m2 | equivalent to N m * 1m. |
N km2 | equivalent to N km * 1km. |
N cm2 | equivalent to (N/10000) m2. |
N mm2 | equivalent to (N/100) cm2. |
N m3 | equivalent to N m2 * 1m. |
N pc3 | equivalent to N pc * 1pc * 1pc. |
N km3 | equivalent to N km2 * 1km. |
N l | equivalent to (N/1000) m3. |
N ml | equivalent to (N/1000) l. |
N ul | equivalent to (N/1000) ml. |
N nl | equivalent to (N/1000) ul. |
N pl | equivalent to (N/1000) nl. |
N fl | equivalent to (N/1000) pl. |
N cm3 | equivalent to N ml. |
N mm3 | equivalent to N ul. |
N kg | a mass type object where N is the number of kilograms. |
N t | equivalent to (N*1000)kg. |
N gram | equivalent to (N/1000)kg. |
N mg | equivalent to (N/1000)g. |
N ug | equivalent to (N/1000)mg. |
N ng | equivalent to (N/1000)ug. |
N pg | equivalent to (N/1000)ng. |
N s | a time type object where N is the number of seconds. |
N ms | equivalent to (N/1000) s. |
N us | equivalent to (N/1000) ms. |
N ns | equivalent to (N/1000) us. |
N ps | equivalent to (N/1000)ns. |
N fs | equivalent to (N/1000)ps. |
N secs (or 1 sec) | equivalent to N s. |
N mins (or 1 min) | equivalent to N*60 secs. |
N hours (or 1 hour) | equivalent to N*60 mins. |
N days (or 1 day) | equivalent to N*24 hours. |
N months (or 1 month) | a time type object where N is the number of months. |
N years (or 1 year) | equivalent to N*12 years. |
N 'A' | a current type object where N is the number of amperes. |
N mA | equivalent to (N/1000) 'A'. |
N uA | equivalent to (N/1000) mA. |
N nA | equivalent to (N/1000) uA. |
N pA | equivalent to (N/1000) nA. |
N mol | a amount-of-substance type object where N is the number of mols. |
N mmol | equivalent to (N/1000) mol. |
N umol | equivalent to (N/1000) mmol. |
N nmol | equivalent to (N/1000) umol. |
N pmol | equivalent to (N/1000) nmol. |
N 'K' | a temperature type object where N is the number of Kelvins. |
N cd | a strength-of-light type object where N is the number of candels. |
N 'Hz' | equivalent to N / 1 sec. |
N kHz | equivalent to (N*1000)'Hz'. |
N 'MHz' | equivalent to (N*1000) kHz. |
N 'GHz' | equivalent to (N*1000)'MHz'. |
N 'N' | equivalent to N m * 1 kg / 1 s2. |
N 'Pa' | equivalent to N 'N' / 1 m2. |
N kPa | equivalent to (N*1000)'Pa'. |
N 'J' | equivalent to N 'N' * 1m. |
N 'W' | equivalent to N 'J' / 1 sec. |
N kW | equivalent to (N*1000)'W'. |
N 'MW' | equivalent to (N*1000) kW. |
N 'GW' | equivalent to (N*1000)'MW'. |
N mW | equivalent to (N/1000)'W'. |
N 'C' | equivalent to N 'A' * 1 sec. |
N 'V' | equivalent to N 'W' / 1 'A'. |
N mV | equivalent to (N/1000)'V'. |
N uV | equivalent to (N/1000)mV. |
N kV | equivalent to (N*1000)'V'. |
N 'F' | equivalent to N 'C' / 1 'V'. |
N mF | equivalent to (N/1000)'F'. |
N uF | equivalent to (N/1000)mF. |
N nF | equivalent to (N/1000)uF. |
N pF | equivalent to (N/1000)nF. |
N 'Ohm' | equivalent to N 'V' / 1 'A'. |
N kOhm | equivalent to (N/1000)kOhm. |
N 'MOhm' | equivalent to (N/1000)'MOhm'. |
N 'T' | equivalent to N 'V' * 1 sec / 1 m2. |
N 'Gy' | equivalent to N 'J' / 1 kg. |
on(Year,Month,Day,Hour,Min,Sec) | This function calculates the object for the specified date
where all parameters are given as numbers. |
now | The date object from when the starting FunLog++ message was sent. |
today | The date object from the beginning of the day when the starting FunLog++ message was sent. |
A < B | This relation is satisfied if date A is before date B. |
A - B | If A and B are dates then this function calculates the time between
A
and B.
Example: today - on(1996,9,18,0,0,0). |
A + B (or A - B) | If A is a date and B is a time (duration) then this function calculates
the date B later than A (or B before A). Example: on(1996,9,18,14,55,0) - 2 years. |
A = B | A and B are tried to be unified according
to object type of A and B.
If unification succeeds then the A=B returns succeess. Otherwise the term A=B returns failure. |
A \= B | A and B are tested if unification would
fail or succeed. A\=B succeds if A and
B
can not be unified.
With A\=B variables in A or B are not bound. Comment: An alternative implementation would be: A<B ; B<A. We are still discussing this question. |
A < B | A < B is not a mere comparison.
If ordering is possible then variables in A and/or B may be bound to (often semiknown) subobjects. In the FunLog++ standard library order relation < is defined for known and semiknown numbers, texts, dates and measures as well as unknown objects. |
A <= B | equivalent to A<B \/ A=B. |
A > B | equivalent to B<A. |
A >= B | equivalent to A>B \/ A=B. |
Two ground objects A and B are identical if A = B succeeds. Two unknown (variable) objects are identical if they are one and the same, e.g. if the message A=V, display(A)=display(B) succeeds for any value of V. Two parameterless objects are identical if they belong to the same class. Two arbitrary objects are identical if they belong to the same class and if all parameters are pairwise identical.
A == B | A == B succeeds if A and B are identical. |
clone(A) | returns a copy of A with a new identity (i.e. with new variables). |
identity(A) | returns the identity of A (i.e. the list of variables contained in A). If A is ground then ident(A) returns the empty list. |
ground(A) ::= identity(A) = [ ].
A semiknown possibilistic object specifies a subset of at least two elements of some domain. Examples of possibilistic objects are unions, which may be implemented with semiknown generator function A\/B. Another semiknown possibilistic object is an interval A--B which states that all object X are possible where A<X and X<B. Another kind of a possibilistic object is a grammar which defines a subset of (syntactically correct) sequences, e.g. texts, (not yet implemented).
A semiknown probabilistic object specifies a probability density function over some domain. Examples are probability distributions for qualitative domains where the probability may be attached element by element, e.g. gastroenteritis @ 60% \/ appendicitis @ 40%. For quantitative domains Gauss normal distribution is available, e.g. gauss returns a semiknown number with mean 0 and variance 1. To obtain a distribution with mean A and variance B we have to write A+(sqrt(B)*gauss). In the future distribution with upto four moments (mean, variance, skewness, and kurtosis) are planned to be implemented.
A\/B | This function was already defined in section control functions
(see above).
It returns the (semiknown) union of A and B. A\/B represents either a possibilistic subset consisting of known or possibilistic parameters A and B or it represents a qualitative probability distribution where A\/B is completely composed from single-element-distributions (see below in this table). |
A/\B | This function was also already defined in section control functions.
It returns the intersection of A and B. |
A--B | This function returns a possibilistic object allowing all elements
X
where A<X and X<B. |
A-+B | This is equivalent to (A-B)--(A+B). |
A=--B | This is equivalent to the term (A \/ A--B) with left bound included. |
A--=B | This is equivalent to the term (A--B \/ B) with right bound included. |
A=-=B | This is equivalent to the term (A \/ A--B \/ B) with both bounds included. |
<A | This is equivalent to (-infinity)--A. |
<=A | This is equivalent to the term (<A \/ A). |
>A | This is equivalent to A--infinity. |
>=A | This is equivalent to the term (>A \/ A). |
A@B | This function returns a single-element probabilistic distribution
where object A is associated with a probability of B which is a number between 0 and 1. The complementary probability of 1-B remains unassociated so far. More-element distributions are obtained by unions of single-element probabilistic distributions. But then the sum of all probabilities must not exceed 1. |
moments | This parameterless function returns a semiknown probabilistic number
with mean 0, variance 1, skewness 0 and kurtosis 3. |
moments([M,V,S,K]) | This function returns a semiknown probabilistic number
with mean M, variance V, skewness S and kurtosis K. |
throw(KIND,ORIGIN) | This function returns an exception with kind KIND and origin ORIGIN. ORIGIN is a object to describe a source code position (class and method) within a FunLog++ program. |
catch(KIND,TERM,VALUE) | If evaluation of term TERM results an exception of
kind KIND
then the result is VALUE otherwise the result is TERM. |
A ? | This function is equivalent to catch("Undefined Function",A,failure). |
number(A) ::= { number(SELF,X) ::= X=A. min(SELF,PAR2) ::= number(PAR2,B)? | A<=B, A \/ A>B, B. max(SELF,PAR2) ::= number(PAR2,B)? | A<=B, B \/ A>B, A. }.As method number/2 is only defined for the number object a message like number("Boston",V) would return an undefined_exception. Therefore we need the ?/1 function to convert the undefined_exception into a failure object.
There are some exceptions which are predefined in the FunLog++ runtime
system. The TopMessage is the message which started FunLog++ interpreter
execution (e.g. root("lipid.fun"):result.). The TopMessage
usually comes from within a command line, from within an icon or from an
external program.
|
|
function undefined
<Context> <Message> |
There is no suitable function defined in the given context for the given message. Please try to modify the message or insert an appropriate function definition. |
top message undefined
<Message> |
In the top message which is (mostly) of type root(A):B one of its submessages in A or B are not suitably defined in the FunLog++ system. |
top message failed
<Message> |
The top message failed. In contrast to other contexts, top messages must not fail in FunLog++. |
receiver undefined
<Context> <Message> |
In a message like Receiver:Term the receiver message is nowhere defined in the current context. |
receiver failed
<Context> <Message> |
In a message like Receiver:Term the receiver message returned a failure object. In contrast to other contexts a receiver message must not fail in FunLog++. |
receiver unknown
<Context> <Message> |
In a message like Receiver:Term the receiver message returned an unknown object. In contrast to other contexts a receiver message must not be unknown in FunLog++. |
compiletime error
<Location> <ErrorKind> |
There was a compilertime error which was ignored. Now during runtime it was tried to execute the erroneous function. Please correct your FunLog++ program according to the compiletime error message. |
runtime error
<ErrorKind> |
There is an error in the FunLog++ runtime system. Please tell this error to the FunLog++ system developers. |
If an exception occurs and it is not handled within the FunLog++ program
by =/1 or catch/3 then it will be passed
to the runtime system which causes an appropriate error message.
Static loading: Function load(Library) loads a compiled library into the FunLog++ heap space where Library is the file name of the library's source file. The file extension then has to be ".FUN" or must be omitted (where then ".FUN" is assumed). Function ::/1 gives access to the libraries public root level functions.
load(Library) | This functions enables access to the root class object of the specified FunLog++ source file Library by another function (::/1). |
::/1 | This pseudo-function sends the message which is specified in the parameter to the library common root object. |
connect(Database) ::= load("database.fun"), ::sql:connect(Database).In this example we assuem that in the root object of source file "database.fun" there is a public function sql/0. Then the message ::sql:connect(A) send connect/1 to the resulting object of this function.
Dynamic loading: Function root(SubProgram) dynamically creates and loads a program object where SubProgram is the file name of the subprograms FunLog++ source file. The file extension then has to be ".FUN" or must be omitted (where then ".FUN" is assumed).
root(Program) | This functions returns the root class object of the specified FunLog++ source file Program. |
convert_coordinates_to_vrml_text(X,Y,Text) ::= VRML_program = root("vrml_tools.fun"), Text = VRML_program:draw_diagram(X,Y).In this example we assume that there is a different FunLog++ source file, called "vrml_tools.fun". In the root class of "vrml_tools.fun" there should be defined a function draw_diagram(X,Y) which calculates the wanted VRML text.
sqltable(DataSource,TableId) | This function returns a table object to represent a link to a database table TableId from a given source DataSource. |
record(Key) | This function returns a location object to represent a link to a database record Key from the table which is the receiver object. |
textfile(FileId) | This function returns the location object of the text file specified by FileId. Here FileId is a text like "//COMPUTER/PATH/FILE.EXTENSION". Use put/2 and get/2 (see next chapter) for reading and writing text files. |
get_birthdate_of_patient(Key,Date)::= Table = sqltable("jdbc:odbc:lis","patients"), Location = Table:record(Key), get(Location,"BirthDate",Date).In the given example "jdbc:odbc:lis" is the datasource which is given as a database URL. Database URLs are strings with the following structure: <protocolname>:<subprotocol>:<subname> (see JDBC documentation). The table is a FunLog++ specific object which serves as a link descriptor to the wanted SQL database table "patients". The Key is some unique identifier for the requested patient, say "JM550824-1". If the Key is not unique for some reason than the result of record(Key) is semiknown. Finally "BirthDate" is the field identifier of the patient's birthdate.
get(Location,Selector,Value) | This function unifies the content of Location with Value. |
put(Location,Selector,Value) | This function returns a write access directive which, when executed, stores the text Value as new content of Location. If there was another content stored before in Location then this will be replaced by the new one. |
result(Key,Text1,Text2) ::= Location1 = birthdate_location(Key), Location2 = html_output_location, [ put(Location1,"BirthDate",Text1), put(Location2,"",Text2) ].
birthdate_location(Key) ::= sqltable("jdbc:odbc:lis","patients"):record(Key).
html_output_location ::= textfile("//promdsvr/temp/output.html").The selector for the content of text files usually is "". Regard the list of put directives at the end of the function result/3. Assume that function result/3 defined above occurs in some FunLog++ program source file mykb.fun then the command
fun root("mykb.fun"):result(1234,"28.Feb 1997","<HTML> ... </HTML>").will write into SQL database jdbc:odbc:lis record 1234 field "BirthDate" the text "28.Feb 1997" and it will write the text "<HTML> ... </HTML>" into file /temp/output.html on computer //promdsvr.
|
|