On Tue, Aug 30, 2022 at 10:14:21PM -0700, 'Nasser M. Abbasi' via FriCAS - 
computer algebra system wrote:
> I am learning Fricas with the hope I can write Fricas script for CAS 
> integration tests directly.
> 
> I am having hard time figuring how to check the type of variable. I looked 
> at Fricas book but it shows no examples.
> 
> (11) -> n:Integer   
>                                                                    Type: 
> Void
> (12) -> n:=10
>    (12)  10
>                                                                 Type: 
> Integer
> (13) -> typeOf(n)
>    (13)  Integer
> 
> Now I want to check, using if then else, that "n" has type "Integer". How 
> to this? For example, this gives error

But why do you want to do this?  When you declare that variable
is of type Integer, then it has this type, no need to check.

I could say more about 'typeOf', but there is good chance that
what you really want to do is something else.  Intstead I give
you an example:

(13) -> 1::Expression(Integer)

   (13)  1
                                                    Type: Expression(Integer)
(14) -> typeOf(1::Expression(Integer))

   (14)  Expression(Integer)
                                                                   Type: Type
(15) -> retract(1::Expression(Integer))@Integer

   (15)  1
                                                                Type: Integer

Note 1: In simple uses 'typeOf' is redundant becase interpreter already
prints types.

Note 2: Something that logically is an integer may be embedded in
larger type.  'retractIfCan' allows you to check if expression has
integral value.  If you are sure that value is integral, then
'retract' is simpler.

-- 
                              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/20220831162306.GA28545%40fricas.math.uni.wroc.pl.

Reply via email to