Strictly speaking the following commands to the interpreter
plus (f,g) == x+->f(x)+g(x)
and
double n == n + n
do not define functions but rather "modes". A mode can stand for many
possible functions.
On the other hand
plus(f:INT->INT,g:INT->INT):INT->INT == (x:INT):INT +-> f(x)+g(x)
does define a function.
Your interpreter example works for me if types are fully specified.
wspage@suse:~/Desktop> fricas
Checking for foreign routines
AXIOM="/usr/local/lib/fricas/target/x86_64-suse-linux"
spad-lib="/usr/local/lib/fricas/target/x86_64-suse-linux/lib/libspad.so"
foreign routines found
openServer result 0
FriCAS Computer Algebra System
Version: FriCAS 2014-03-24
Timestamp: Sat Apr 19 15:14:04 EDT 2014
-----------------------------------------------------------------------------
Issue )copyright to view copyright notices.
Issue )summary for a summary of useful system commands.
Issue )quit to leave FriCAS and return to shell.
-----------------------------------------------------------------------------
(1) -> plus(f:INT->INT,g:INT->INT):INT->INT == (x:INT):INT +-> f(x)+g(x)
Function declaration plus : ((Integer -> Integer),(Integer ->
Integer)) -> (Integer -> Integer) has been added to workspace.
Type: Void
(2) -> double(n:INT):INT == n + n
Function declaration double : Integer -> Integer has been added to
workspace.
Type: Void
(3) -> h:INT->INT := plus(double,double)
Compiling function double with type Integer -> Integer
Compiling function plus with type ((Integer -> Integer),(Integer ->
Integer)) -> (Integer -> Integer)
(3)
theMap
#<FUNCTION (LAMBDA (#:G666 |envArg|) :IN |*2;plus;1;frame1|) {10044C264B}>
,
655
Type: (Integer -> Integer)
(4) -> h 4
(4) 16
Type: PositiveInteger
(5) ->
---
But I notice that printing of the function h is not so pretty.
Apparently something similar happens when calling your SPAD functions
since the following works:
(1) -> )co plus
Compiling FriCAS source code from file
/home/wspage/Desktop/plus.spad using old system compiler.
PLSPKG abbreviates package PlusPackage
------------------------------------------------------------------------
initializing NRLIB PLSPKG for PlusPackage
compiling into NRLIB PLSPKG
compiling exported plus2 : (A -> B,A -> B) -> A -> B
;;; *** |PLSPKG;plus2;3M;1| REDEFINED
Time: 0.00 SEC.
(time taken in buildFunctor: 0)
;;; *** |PlusPackage| REDEFINED
;;; *** |PlusPackage| REDEFINED
Time: 0 SEC.
Cumulative Statistics for Constructor PlusPackage
Time: 0.00 seconds
finalizing NRLIB PLSPKG
Processing PlusPackage for Browser database:
--->/home/wspage/Desktop/plus.spad-->PlusPackage(constructor): Not
documented!!!!
--->/home/wspage/Desktop/plus.spad-->PlusPackage((plus2 ((Mapping B A)
(Mapping B A) (Mapping B A)))): Not documented!!!!
--->/home/wspage/Desktop/plus.spad-->PlusPackage(): Missing Description
; compiling file "/home/wspage/Desktop/PLSPKG.NRLIB/PLSPKG.lsp"
(written 23 APR 2014 09:51:50 AM):
; /home/wspage/Desktop/PLSPKG.NRLIB/PLSPKG.fasl written
; compilation finished in 0:00:00.013
------------------------------------------------------------------------
PlusPackage is now explicitly exposed in frame frame1
PlusPackage will be automatically loaded when needed from
/home/wspage/Desktop/PLSPKG.NRLIB/PLSPKG
TEST1 abbreviates package TestPlusPackage
------------------------------------------------------------------------
initializing NRLIB TEST1 for TestPlusPackage
compiling into NRLIB TEST1
compiling exported double2 : A -> A
;;; *** |TEST1;double2;2A;1| REDEFINED
Time: 0 SEC.
(time taken in buildFunctor: 0)
;;; *** |TestPlusPackage| REDEFINED
;;; *** |TestPlusPackage| REDEFINED
Time: 0.00 SEC.
Cumulative Statistics for Constructor TestPlusPackage
Time: 0.00 seconds
finalizing NRLIB TEST1
Processing TestPlusPackage for Browser database:
--->/home/wspage/Desktop/plus.spad-->TestPlusPackage(constructor): Not
documented!!!!
--->/home/wspage/Desktop/plus.spad-->TestPlusPackage((plus2 ((Mapping
B A) (Mapping B A) (Mapping B A)))): Not documented!!!!
--->/home/wspage/Desktop/plus.spad-->TestPlusPackage(constructor): Not
documented!!!!
--->/home/wspage/Desktop/plus.spad-->TestPlusPackage((double2 (A A))):
Not documented!!!!
--->/home/wspage/Desktop/plus.spad-->TestPlusPackage(): Missing Description
; compiling file "/home/wspage/Desktop/TEST1.NRLIB/TEST1.lsp" (written
23 APR 2014 09:51:50 AM):
; /home/wspage/Desktop/TEST1.NRLIB/TEST1.fasl written
; compilation finished in 0:00:00.005
------------------------------------------------------------------------
TestPlusPackage is now explicitly exposed in frame frame1
TestPlusPackage will be automatically loaded when needed from
/home/wspage/Desktop/TEST1.NRLIB/TEST1
(1) -> h := plus2(double2,double2)$PLSPKG(INT,INT)
(1) theMap(PLSPKG;plus2;3M;1!0,655)
Type: (Integer -> Integer)
(2) -> h 4
(2) 16
Type: PositiveInteger
(3) ->
On 23 April 2014 09:16, jiazhaoconga <[email protected]> wrote:
> I have some problems when I try to have high order generic functions in
> Fricas:
>
> For example, 'plus' is a high order generic functions that takes two functions
> (f,g) and returns an (anonymous) function (with parameter x) that returns the
> sum of f(x) and g(x) :
>
> 1. Do it in REPL:
> plus (f,g) == x+->f(x)+g(x)
>
> Test it:
> double n == n + n
> h := plus(double,double)
> h 4
>
> but get:
>
> FriCAS will attempt to step through and interpret the code.
>
> Anonymous user functions created with +-> that are processed in
> interpret-code mode must have result target information
> available. This information is not present so FriCAS cannot
> proceed any further. This may be remedied by declaring the
> function.
>
> 2. Do it in Spad:
> -- file plus.spad starts here
> )abbrev package PLSPKG PlusPackage
>
> PlusPackage(A:SetCategory, B:AbelianSemiGroup) : Exports == Impl where
> Exports == with
> plus2 : ((A->B),(A->B))->(A->B)
> Impl == add
> plus2(f,g) == x+->f(x)+g(x)
>
> )abbrev package TEST1 TestPlusPackage
>
> TestPlusPackage(A:AbelianSemiGroup) : Exports == Impl where
> Exports == with
> double2 : A->A
> Impl == add
> double2 x == x+x
> -- file plus.spad ends here
>
> and in REPL:
> )compile plus
> h == plus2(double2,double2)
> h 4
>
> but get:
>
> There are 1 exposed and 0 unexposed library operations named plus2
> having 2 argument(s) but none was determined to be applicable.
>
> What/Where is going wrong?
>
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.