mutual recursion

已查看 9 次
跳至第一个未读帖子

Ralf Hemmecke

未读,
2014年6月10日 07:09:312014/6/10
收件人 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

未读,
2014年6月11日 22:15:242014/6/11
收件人 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

未读,
2014年6月12日 02:32:452014/6/12
收件人 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
回复全部
回复作者
转发
0 个新帖子