Type to String

13 views
Skip to first unread message

Ralf Hemmecke

unread,
Sep 27, 2020, 8:09:17 AM9/27/20
to fricas-devel
I would like to get the name of a type as a string.
In a FriCAS session I can simply do

(15) -> unparse(Integer :: InputForm)

Function Selection for unparse
Arguments: INFORM

[1] signature: INFORM -> STRING
implemented: slot (String)$ from INFORM


(15) "Integer()"
Type: String

Unfortunately, that doesn't work in the compiler.

Is there a simple way to get the name or do I have to use some trick?

Ralf

Ralf Hemmecke

unread,
Sep 27, 2020, 11:37:03 AM9/27/20
to fricas...@googlegroups.com
Hi Waldek,

I have now found this:

https://github.com/fricas/fricas/blob/master/src/algebra/polycat.spad#L1223

op_of_PS : Symbol := CAR(devaluate(PS)$Lisp)$Lisp

It's rather lispy, but can it count as a "supported" way to get the name
of a constructor?

Actually, the question arises whether introspection should be allowed at
all. If yes, then all supported forms should make it into a package.

Ralf

Waldek Hebisch

unread,
Sep 27, 2020, 2:22:26 PM9/27/20
to fricas...@googlegroups.com
On Sun, Sep 27, 2020 at 05:37:00PM +0200, Ralf Hemmecke wrote:
> Hi Waldek,
>
> I have now found this:
>
> https://github.com/fricas/fricas/blob/master/src/algebra/polycat.spad#L1223
>
> op_of_PS : Symbol := CAR(devaluate(PS)$Lisp)$Lisp
>
> It's rather lispy, but can it count as a "supported" way to get the name
> of a constructor?

It is not likely to change soon, but I would prefer to keep such
code limited to small number of crucial places.

>
> Actually, the question arises whether introspection should be allowed at
> all. If yes, then all supported forms should make it into a package.

IMO introspection is clearly needed, otherwise some natural
conditions on types are not possible (which in particular led to
hack above in 'polycat.spad'). Tricky part is to give exact
rules. In particular, currently types are of type 'Category',
but almost all that can be done with categories is buit into
compiler. Interpreter can only use categories created by
compiler and there is bunch of functions in runtime support.
ATM it is not clear if we should turn 'Category' into an actual
type. Logicaly things like type name or arguments are operations
on types, that is operation in elements of type 'Category'
so should be among exports of Category'... But trurly first
class categories lead to serious problems, so probably it is
better to just build needed support into compiler and
interpreter.

> On 9/27/20 2:09 PM, Ralf Hemmecke wrote:
> > I would like to get the name of a type as a string.
> > In a FriCAS session I can simply do
> >
> > (15) -> unparse(Integer :: InputForm)
> >
> > Function Selection for unparse
> > Arguments: INFORM
> >
> > [1] signature: INFORM -> STRING
> > implemented: slot (String)$ from INFORM
> >
> >
> > (15) "Integer()"
> > Type: String
> >
> > Unfortunately, that doesn't work in the compiler.
> >
> > Is there a simple way to get the name or do I have to use some trick?
> >


Well, ATM there is Boot function 'typeToForm' which can coerce type
to InputForm or OutputForm. There is also 'outputDomainConstructor'
which is more naive, but should work before algebra bootstrap
('typeToForm' recures to algebra so is usable only after
bootstrap).



--
Waldek Hebisch
Reply all
Reply to author
Forward
0 new messages