mutual recursion

9 views
Skip to first unread message

Ralf Hemmecke

unread,
Jun 10, 2014, 7:09:31 AM6/10/14
to fricas-devel
How do I programm such mutual recursion in SPAD?

BTW, in fact I want a global store (here represented by

h: XHashTable(String, ConstructorData) := empty()

which will be filled whenever some data is computed. Otherwise
ConstructorDataBase should simply serve as cache.

Other ways how to implement that idea.

Maybe, instead of passing ConstructorData to my functions, I must pass
ConstructorDataBase and name of the constructor.

Ralf

(1) -> )co foo.spad
Compiling FriCAS source code from file
/home/hemmecke/backup/git/fricas/src/doc/foo.spad using old
system compiler.
CONDB abbreviates package ConstructorDataBase
------------------------------------------------------------------------
initializing NRLIB CONDB for ConstructorDataBase
compiling into NRLIB CONDB
****** comp fails at level 1 with expression: ******
(|ConstructorData|)
****** level 1 ******
$x:= ConstructorData
$m:= (Type)
$f:=
((((|data| #) (|#| #) (= #) (|any?| #) ...)))

>> Apparent user error:
unspecified error


If I reorder the constructors (first ConstructorData, then
ConstructorDataBas), then I get this:

(1) -> )co foo.spad
Compiling FriCAS source code from file
/home/hemmecke/backup/git/fricas/src/doc/foo.spad using old
system compiler.
CONDATA abbreviates domain ConstructorData
------------------------------------------------------------------------
initializing NRLIB CONDATA for ConstructorData
compiling into NRLIB CONDATA
processing macro definition Rep ==> String
compiling exported computeConstructorData : String -> $
CONDATA;computeConstructorData;S$;1 is replaced by str
Time: 0.01 SEC.

compiling exported getConstructorData : String -> $
****** comp fails at level 1 with expression: ******
error in function getConstructorData

(((|Sel| |ConstructorDataBase| |constructorData|) |s|))
****** level 1 ******
$x:= ((Sel ConstructorDataBase constructorData) s)
$m:= $
$f:=
((((|s| # #) (|#| #) (< #) (<= #) ...)))

>> Apparent user error:
ConstructorDataBase
is an unknown mode


foo.spad

Waldek Hebisch

unread,
Jun 11, 2014, 10:15:24 PM6/11/14
to fricas...@googlegroups.com
Ralf Hemmecke wrote:
> How do I programm such mutual recursion in SPAD?
>
> BTW, in fact I want a global store (here represented by
>
> h: XHashTable(String, ConstructorData) := empty()
>
> which will be filled whenever some data is computed. Otherwise
> ConstructorDataBase should simply serve as cache.

1) You need to correct 'getConstructorData':

getConstructorData(s: String): % ==
constructorData(s)$ConstructorDataBase pretend %

(Spad compiler do not see that % is the same as ConstructorData
so we need 'pretend' here).

2)
)boot $bootStrapMode := true
)compile foo.spad
)boot $bootStrapMode := false
)compile foo.spad

--
Waldek Hebisch
heb...@math.uni.wroc.pl

Ralf Hemmecke

unread,
Jun 12, 2014, 2:32:45 AM6/12/14
to fricas...@googlegroups.com
Hi Waldek,

Thanks for your answer.

On 06/12/2014 04:15 AM, Waldek Hebisch wrote:
> Ralf Hemmecke wrote:
>> How do I programm such mutual recursion in SPAD?
>>
>> BTW, in fact I want a global store (here represented by
>>
>> h: XHashTable(String, ConstructorData) := empty()
>>
>> which will be filled whenever some data is computed. Otherwise
>> ConstructorDataBase should simply serve as cache.
>
> 1) You need to correct 'getConstructorData':
>
> getConstructorData(s: String): % ==
> constructorData(s)$ConstructorDataBase pretend %
>
> (Spad compiler do not see that % is the same as ConstructorData
> so we need 'pretend' here).

Forever? Aldor can already compile this just fine (see attachment).

> 2)
> )boot $bootStrapMode := true
> )compile foo.spad
> )boot $bootStrapMode := false
> )compile foo.spad

Well. That's a solution for bootstrapping. I really wouldn't want to
tell this to as spad programmer.

Ralf
foo.as
Reply all
Reply to author
Forward
0 new messages