On Sun, Sep 27, 2020 at 08:33:01PM +0200, Ralf Hemmecke wrote:
> I would like to make enabeling FormatMathJax in the jFriCAS frontend
> simpler. It should work like this:
> 
> setFormat!(FormatMathJax)
> )set output formatted on
> 
> In fact, the attached package would do exactly that, BUT
> I cannot call it like above.
> 
> (11) -> setFormat!(FormatMathJax)
>    There are 1 exposed and 0 unexposed library operations named
>       setFormat! having 1 argument(s) but none was determined to be
>       applicable. Use HyperDoc Browse, or issue
>                            )display op setFormat!
>       to learn more about the available operations. Perhaps
>       package-calling the operation or using coercions on the arguments
>       will allow you to apply the operation.
> 
>    Cannot find a definition or applicable library operation named
>       setFormat! with argument type(s)
>                                     Type
> 
>       Perhaps you should use "@" to indicate the required return type,
>       or "$" to specify which version of the function you need.
> 
> (11) -> setFormat!(FormatMathJax pretend FormatterCategory)
>                                                         Type: Void
> 
> (12) -> 1/sqrt(5)
> 
>           +-+
>          \|5
>    (12)  ----
>            5
> --FORMAT:BEG:FormatMathJax
> \[
> \frac{\sqrt{5}}{5}
> \]
> --FORMAT:END:FormatMathJax
> 
> Of course, it is not very user-friendly to require a pretend. And it
> makes this simple switch quite long.
> 
> Obviously, the interpreter does not recognise the type of FormatMathJax
> as the category FormatterCategory, but only as Type.

Yes, that is limitation of current interpreter.  It is hard to
remove this limitation without substantial rewrite...

> 
> So I programmed fmtjfricastype.spad.
> 
> Instead of
> 
>     setFormat!: FormatterCategory -> Void
> 
> I now use
> 
>     setFormat!: Type -> Void
> 
> with that
> 
>   setFormat!(FormatMathJax)
> 
> works perfectly in a FriCAS session.
> 
> However, I find it a bit sad that in setFormat! I have to accept ALL
> types. Can I at least check that the input is indeed of category
> FormatterCategory even though I use
> 
>     setFormat!: Type -> Void
> 
> otherwise it looks pretty type-unsafe.

Well, you can write 'setFormat!' like:

      setFormat!(t : Type) : Void ==
          if t has FormatterCategory then
              setFormat!(t pretend FormatterCategory)$TV
          else
              error "t is not of FormatterCategory"

where TV is version of package accepting FormatterCategory.
With smart enough compiler the above would work without
'pretend', but I am affraid that ATM 'pretend' is needed.

> 
> Which way should I follow?

Well, usual solution chosen by others was to have something like

setFormatMathJax()

Since 'setFormatMathJax' is handled by Spad compiler it should
work without 'pretend'...

> 
> Second question.
> At the same time as setFormat! is called, it should switch on this
> format, i.e. do the equivalent of
> 
>   )set output formatted on
> 
> How can I program this from within a .spad file.

There is 'systemCommand' in 'system.spad'.

-- 
                              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 on the web visit 
https://groups.google.com/d/msgid/fricas-devel/20200927193756.GA33280%40math.uni.wroc.pl.

Reply via email to