On Mon, Apr 16, 2012 at 07:42:14PM +0200, Ralf Hemmecke wrote:
> Sorry, I read your mail too late. The code you demonstrate here should
> also work. What is so bad with it except tht it is a bit lengthy?
Bad is _only_ that it must not work!
Its length does not matter, and I do not consider it as large.
I wrote about length only to show that my Spad-like example is small and
clear, so that people can read and consider it.
> You cannot expect that code that looks elegant in one language looks
> equally elegant in another one.
Again: this Spad-like code is small and elegant all right.
The matter is that it _must not work_!
Waldek and other people wrote that (if only I understand them correctly)
an user Spad program cannot add new category instances
to any Axiom library domain.
For example, one cannot increase Integer with an instance of my Show
category. And in my code below Integer is re-defined, extended.
Similarly, the set of instances related for Product(S,T) and List(T)
are re-defined, extended.
Hence the below code must not work in Spad. Must it?
People, please, consider the below code and tell: what is wrong in it
(besides absence of the )abbrev line) ?
(I never tried to compile it, because was sure that it would not).
If it does not work in Spad, then what is the appropriate replacement?
Regards,
------
Sergei
[email protected]
> ------------------------------------------------------------------------
>> category Show() : Category == SetCategory with show : % -> String
>>
>> --------------
>> domain Integer() : Export == Implementation where
>> -- add Show to the domain of Integer
>> Export == Join(Integer export, Show)
>>
>> Implementation == Integer add
>> show n == string n
>>
>> --------------
>> domain Product(S : SetCategory, T : SetCategory) :
>> Export == Implementation where
>> Export == Product(S,T) export
>> if S has Show and T has Show then Show
>> -- add Show to the domain of Product
>>
>> Implementation == Product(S, T) add
>> if S has Show and T has Show then Show
>> -- add Show to the domain of Product
>>
>> Implementation == Product(S, T) add
>>
>> if S has Show and T has Show then
>> show(p : %) : String ==
>> concat[ "(", show (first p), ",", show (second p), ")" ]
>>
>> --------------
>> domain List(T : Type) : Export == Implementation where
>>
>> Export == Product export
>> if T has Show then Show -- add to the List(T) domain
>>
>> Implementation == List(T) add
>>
>> if T has Show then
>> show(xs : %) : String == -- print xs to string
>> empty? xs => "[]"
>> x := first xs
>> xs := rest xs
>> str := concat("[", show x)
>> while not empty?(xs) repeat
>> x := first xs
>> xs := rest xs
>> str := concat[str, ",", show x]
>> concat(str, "]")
>> ------------------------------------------------------------------------
If Spad accepted this, then the Example of usage may be:
show ([ [construct(1,2), construct(3,4)],
[construct(5,6), construct(7,8)] ]
:: List List Product(INT, INT))
->
"[[(1,2),(3,4)],[(5,6),(7,8)]]"
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/fricas-devel?hl=en.