hello Waldek, hello folks,

Le mer. 20 mars 2024 à 22:28, Waldek Hebisch <de...@fricas.org> a écrit :
>
> On Wed, Mar 20, 2024 at 07:41:11PM +0100, Grégory Vanuxem wrote:
> > Hello,
> >
> > Do you happen to know why the declaration of string(Integer) is in
> > StringCategory and its definition in the String domain?
> > (STRINGIMAGE$Lisp)
>
> 'string' constructs a String and as all functions of similar sort
> is defined in corresponding domain.  As usual, 'string' is declared
> in corresponding category, that is StringCategory

Yes, of course. I was just wondering why String(__Integer_) was
declared there instead of a generic declaration like:
string : % -> String

That way, like Symbol, it can be defined in the Integer domain and
thus avoid unexpected effects during interpreter coercion mechanisms.
I encountered this with other integer related domains like another
prime field domain, another integer mod domain... etc.

In fact, instead of declaring string : % -> String in those domains I
declare it at a 'Category' level and that solved this. To be more
precise, I do not ask for its implementation, having a way to obtain
an ASCII string representation of every Spad object would be handy I
find. Even string(Type) like string(Integer) => "Integer". I guess
this exists somewhere in Spad but I have not found where. A good
candidate to use it could be the 'error' function. There seems to be
no implicit rules to use this function and from memory I have seen an
error like "Not invertible". Franckly, imagine you have a lot of code
with integers, matrices etc. and you see this error. Euh... Not a
field? rectangular matrix? Singular maybe? And so on. Personally I
like to know the function who throws the error and more information
could be handy. For example string(%) could be of use. I only know the
'latex' function declared in SetCategory that resembles but it is a
typesetting function, not a simple string function.

,>
> > That way if someone adds a domain, say, Foo, that has an Integer to
> > Foo coercion and exports a 'string' operation the interpreter will
> > choose the Foo one. It's a bit of a shame, isn't it?
>
> Well, that is how Spad overloading works: if you have two ways
> they should give the same result or you need to be more specific
> (hide Foo, add explicit '$Integer' etc.).  If Foo can be coerced
> to Integer, then maybe 'string' in Foo is not needed at all.

Yes, but from my point of view string(Integer) should not be
overloaded, it is up to the Integer domain author/programmer to handle
this coercion Integer -> String. There is 'convert@String' though, but
it uses 'string':
convert(x : %) : String      == string(x pretend Integer)$String

>
> Also, note that interpreter coercions are tuned to existing set
> of domains.  When you add new domains (or new operations to existing
> domains) with current rules interpreter can make undesirable
> choice.  That is a shame, when adding exposed operations we need
> to take into account what interpreter will do, or modify
> interpreter to change its rules.

I totally agree.

> Ideally there should be a
> user level way to add or remove interpreter inference rules.

Ideally, yes.

- Greg


>
> --
>                               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 fricas-devel+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/fricas-devel/ZftU-WcPThCruCpy%40fricas.org.

-- 
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 fricas-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/CAHnU2dbuU7Pmssyc9yyJZcbWKnLsDEVdtxe7i0%3DYssOA3f4%3DDw%40mail.gmail.com.

Reply via email to