On Mon, Sep 01, 2025 at 12:48:22AM +0200, 'Ralf Hemmecke' via FriCAS - computer
algebra system wrote:
> I thought the following would be possible in SPAD.
>
> -----------------------------
> )abbrev package FOO Foo
> Foo(n: Integer): Exports == Implementation where
> Exports ==> Ring
> Implementation ==>
> n > 2 => Fraction Integer
> Integer
> -----------------------------
>
> However, it gives
>
> %%% (148) -> )co ../foo
> Compiling FriCAS source code from file
> /home/hemmecke/backup/git/qeta/tmp/../foo.spad using system
> compiler.
> FOO abbreviates package Foo
> ****** comp fails at level 1 with expression: ******
> ((DEF (|Foo| |n|) ((|Ring|) (|Integer|))
> (IF (> |n| 2)
> (|Fraction| (|Integer|))
> (|Integer|))))
> ****** level 1 ******
> x:= (DEF (Foo n) ((Ring) (Integer)) (IF (> n 2) (Fraction (Integer))
> (Integer)))
> m:= $EmptyMode
> f:=
> ((((|$DomainsInScope| # #))))
>
> >> Apparent user error:
> bad == form
> (DEF (Foo n) ((Ring) ) (IF (> n 2) (Fraction (Integer)) (Integer)))
>
> Cannot I implement a domain that uses a certain representation depending on
> an argument.
>
> Actually, Expression is doing that, but it does it with only one "add"
> keyword.
<snip>
> Is this a weakness of the SPAD-compiler?
Try the following:
)abbrev package FOO Foo
Foo(n: Integer): Exports == Implementation where
Exports ==> Ring
Implementation ==> (n > 2 => Fraction(Integer); Integer) add
foo () : Integer == 1
I do not know if it works, but at least for me it compiles.
Note that there is one and only one 'add' here.
Yes, it is a weakness in SPAD compiler. Theoretically without 'add'
your definition should work, but you get what you get.
--
Waldek Hebisch
--
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 view this discussion visit
https://groups.google.com/d/msgid/fricas-devel/aLTaNjAqODh2-yg_%40fricas.org.