On Sat, Jun 30, 2018 at 11:30 AM, Waldek Hebisch
<[email protected]> wrote:
> Bill Page wrote:
>> >
>> > Well, advantage is consistency with rules.
>> >
>>
>> Could you site specifically what rule is being violated?
>
> The one that Ricardo was asking about: that 'if' always works,
> but for one armed 'if' you get Void as a type.
>
>> ...
>> In fact the Spad compiler does not always do what I had hoped. For
>> example compiling the following function using Spad:
>>
>>   f(x:Integer):PositiveInteger == if x<1 then 1
>>
>> --
>>
>> (1) -> f(0)
>>
>>    (1)  1
>>                                                         Type: PositiveInteger
>> (2) -> f(1)
>>    Internal Error
>>    Interpreter code generation failed for expression(|f| 1)
>
> The message looks fishy.  Do you really used _Spad_ function here?

Yes, here is the exact code that I compiled:

-- file: one-armed.spad
)abbrev domain TEST Test
Test(): with
    test1: ()->Integer
    test2: ()->Void
    f:Integer -> PositiveInteger
    g:Integer -> PositiveInteger
    h:Integer -> PositiveInteger
  == add
    z:Integer := 1
    test1() ==
      A := if z<2 then 1
      return A
    test2() ==
      B := if 2<1 then 1
      return B

    f(x:Integer):PositiveInteger == if x<1 then 1
    g(x:Integer):PositiveInteger == coerce((if x<1 then 1 else
void()$Void)::Union(Void,PositiveInteger))
    h(x:Integer):PositiveInteger == g(x)+1
--

This is the result:

(1) -> )co one-armed
   Compiling FriCAS source code from file /home/wspage/one-armed.spad
      using old system compiler.
   TEST abbreviates domain Test
...
  Test is now explicitly exposed in frame frame1
   Test will be automatically loaded when needed from
      /home/wspage/TEST.NRLIB/TEST

(1) -> f(0)

   (1)  1
                                                        Type: PositiveInteger
(2) -> f(1)
   Internal Error
   Interpreter code generation failed for expression(|f| 1)

(2) -> g(0)

   (2)  1
                                                        Type: PositiveInteger
(3) -> g(1)

   >> Error detected within library code:
   "()" of mode Union(Void,PositiveInteger) cannot be coerced to mode
PositiveInteger

(3) -> h(0)

   (3)  2
                                                        Type: PositiveInteger
(4) -> h(1)

   >> Error detected within library code:
   "()" of mode Union(Void,PositiveInteger) cannot be coerced to mode
PositiveInteger

(4) ->

> The message looks like coming from interpreter and given
> Spad function of correct type interpreter should just blindly
> call it.
>

Yes, I thought so too.

-- 
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to