login  home  contents  what's new  discussion  bug reports help  links  subscribe  changes  refresh  edit

# Edit detail for SandBoxConditionalFunctions revision 1 of 1

 1 Editor: Bill Page Time: 2008/11/18 19:27:06 GMT-8 Note: Francois Maltey

changed:
-
**Conditional for inner functions in a package.**

On 02 Jan 2007 16:44:11 +0100 Francois Maltey wrote:

A *.spad file can contain conditionals such as::

if R is Integer then
aFunction x == a definition for integer
else
aFunction x == an other definition

Or conditionals involving 'has'.

But the function 'aFunction' must be an exported function.
If 'aFunction' is a local function in the package the test
is always false.

So some packages export a lot of local functions, for example
\begin{axiom}
)sh EF
\end{axiom}

all the ixxx functions might be inner functions because
they are defined after a conditional.

-- the following should be local, but are conditional

Where is the problem ? What can aldor do ?
Export too much functions complicate the use of axiom.

You can test this very short package for expression
-------------------------------------------------------------------
)abbrev package TRYCOND TryConditions

TryConditions (R, F): Exports == Implementation where
R : Join (OrderedSet, GcdDomain)
F : Join (FunctionSpace R, TranscendentalFunctionCategory)

Exports ==> with
result    : F -> F
expResult : F -> F

iResult : F -> F
iResult x == cos x
expResult x == cos x
if R is Integer then
iResult x == sin x
expResult x == sin x
result x == iResult x

test

\begin{axiom}
-- Expect sin : right
result (sin x)
-- Expect cos : result sin
result (sin %i)
-- Expect sin : right
expResult (sin x)
-- Expect cos : right
expResult (sin %i)
\end{axiom}



Conditional for inner functions in a package.

On 02 Jan 2007 16:44:11 +0100 Francois Maltey wrote:

A *.spad file can contain conditionals such as:

 if R is Integer then
aFunction x == a definition for integer
else
aFunction x == an other definition


Or conditionals involving has.

But the function aFunction must be an exported function. If aFunction is a local function in the package the test is always false.

So some packages export a lot of local functions, for example elemntry.spad.

fricas
)sh EF
ElementaryFunction(R: Join(Comparable,IntegralDomain),F: Join(FunctionSpace(R),RadicalCategory)) is a package constructor
Abbreviation for ElementaryFunction is EF
This constructor is not exposed in this frame.
------------------------------- Operations --------------------------------
acos : F -> F                         acosh : F -> F
acot : F -> F                         acoth : F -> F
acsc : F -> F                         acsch : F -> F
asec : F -> F                         asech : F -> F
asin : F -> F                         asinh : F -> F
atan : F -> F                         atanh : F -> F
belong? : BasicOperator -> Boolean    cos : F -> F
cosh : F -> F                         cot : F -> F
coth : F -> F                         csc : F -> F
csch : F -> F                         exp : F -> F
iiacos : F -> F                       iiacosh : F -> F
iiacot : F -> F                       iiacoth : F -> F
iiacsc : F -> F                       iiacsch : F -> F
iiasec : F -> F                       iiasech : F -> F
iiasin : F -> F                       iiasinh : F -> F
iiatan : F -> F                       iiatanh : F -> F
iicos : F -> F                        iicosh : F -> F
iicot : F -> F                        iicoth : F -> F
iicsc : F -> F                        iicsch : F -> F
iiexp : F -> F                        iilog : F -> F
iisec : F -> F                        iisech : F -> F
iisin : F -> F                        iisinh : F -> F
iisqrt2 : () -> F                     iisqrt3 : () -> F
iitan : F -> F                        iitanh : F -> F
localReal? : F -> Boolean             log : F -> F
pi : () -> F                          sec : F -> F
sech : F -> F                         sin : F -> F
sinh : F -> F                         tan : F -> F
tanh : F -> F
operator : BasicOperator -> BasicOperator
specialTrigs : (F, List(Record(func: F,pole: Boolean))) -> Union(F,"failed")

all the ixxx functions might be inner functions because they are defined after a conditional.

the following should be local, but are conditional

Where is the problem ? What can aldor do ? Export too much functions complicate the use of axiom.

You can test this very short package for expression -------------------------------------------------------------------

)abbrev package TRYCOND TryConditions
TryConditions (R, F): Exports == Implementation where
R : Join (OrderedSet, GcdDomain)
F : Join (FunctionSpace R, TranscendentalFunctionCategory)
Exports ==> with
result    : F -> F
expResult : F -> F
iResult : F -> F
iResult x == cos x
expResult x == cos x
if R is Integer then
iResult x == sin x
expResult x == sin x
result x == iResult x
   Compiling FriCAS source code from file
using old system compiler.
TRYCOND abbreviates package TryConditions
------------------------------------------------------------------------
initializing NRLIB TRYCOND for TryConditions
compiling into NRLIB TRYCOND
****** Domain: R already in scope
****** Domain: F already in scope
compiling local iResult : F -> F
Time: 0.04 SEC.
compiling exported expResult : F -> F
Time: 0 SEC.
compiling local iResult : F -> F
Time: 0 SEC.
compiling exported expResult : F -> F
Time: 0 SEC.
compiling exported result : F -> F
Time: 0 SEC.
(time taken in buildFunctor:  0)
;;;     ***       |TryConditions| REDEFINED
;;;     ***       |TryConditions| REDEFINED
Time: 0 SEC.
Cumulative Statistics for Constructor TryConditions
Time: 0.04 seconds
finalizing NRLIB TRYCOND
Processing TryConditions for Browser database:
--->-->TryConditions(constructor): Not documented!!!!
--->-->TryConditions((result (F F))): Not documented!!!!
--->-->TryConditions((expResult (F F))): Not documented!!!!
--->-->TryConditions(): Missing Description
; compiling file "/var/aw/var/LatexWiki/TRYCOND.NRLIB/TRYCOND.lsp" (written 04 APR 2022 07:10:35 PM):
; /var/aw/var/LatexWiki/TRYCOND.NRLIB/TRYCOND.fasl written
; compilation finished in 0:00:00.018
------------------------------------------------------------------------
TryConditions is now explicitly exposed in frame initial
TryConditions will be automatically loaded when needed from
/var/aw/var/LatexWiki/TRYCOND.NRLIB/TRYCOND

test

fricas
-- Expect sin : right
result (sin x)
 (1)
Type: Expression(Integer)
fricas
-- Expect cos : result sin
result (sin %i)
There are 1 exposed and 1 unexposed library operations named result
having 1 argument(s) but none was determined to be applicable.
Use HyperDoc Browse, or issue
)display op result
or "\$" to specify which version of the function you need.