HP Forums
Debugging With an Orange Bang - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Debugging With an Orange Bang (/thread-8599.html)



Debugging With an Orange Bang - toml_12953 - 06-29-2017 02:58 AM

I have a program that checks OK but when I go to run it, all I get is an orange circle with a bang (exclamation point) in it. I can't even run the debugger without getting the bang. How am I supposed to debug that? A more informative error message would be appreciated.

Code:
#cas
Testpass():=
BEGIN

circl();
dett();

    x:=1; y:=2;   

    c:=makemat(0,2);
    p:=makemat(0,3,2);
    temp:="";
    
    p(1,x) := 7;
    p(1,y) := 7;
    
    p(2,x) := 0;
    p(2,y) := 8;
    
    p(3,x) := 0;
    p(3,y) := 0;  

    print();
    temp := "points: ";
    temp := temp + "("+ p(1,x)+ ", "+ p(1,y)+ "), ";
    temp := temp + "("+ p(2,x)+ ", "+ p(2,y)+ "), ";
    print (temp+"("+ p(3,x)+ ", "+ p(3,y)+ ") ");
    
    r := circl( c, p );
    if r > 0 then
        print ("Circle: ("+ c(x)+ ", "+ c(y)+ "), "+ r); 
    else
        print ("Not a circle!");
    end;

END;
//
//  Calculate center and radius of 
//  circle given three points
//
circl( c, p )
begin
    local x:=1, y:=2;
    local i;
    local r, m11, m12, m13, m14;
    local a:=makemat(0,3,3);

    for i := 1 to 3 do           // find minor 11
        a(i,1) := p(i,x);
        a(i,2) := p(i,y);
        a(i,3) := 1;
    end;
    m11 := dett( a, 3 );

    for i := 1 to 3 do           // find minor 12 
        a(i,1) := p(i,x)^2 + p(i,y)^2;
        a(i,2) := p(i,y);
        a(i,3) := 1;
    end;
    m12 := dett( a, 3 );

    for i := 1 to 3 do           // find minor 13
        a(i,1) := p(i,x)^2 + p(i,y)^2;
        a(i,2) := p(i,x);
        a(i,3) := 1;
    end;
    m13 := dett( a, 3 );

    for i := 1 to 3 do           // find minor 14
        a(i,1) := p(i,x)^2 + p(i,y)^2;
        a(i,2) := p(i,x);
        a(i,3) := p(i,y);
    end;
    m14 := dett( a, 3 );

    if m11 = 0 then
        r := 0;                  // not a circle
    else
        c(x) =<  0.5 * m12 / m11; // center of circle
        c(y) =< -0.5 * m13 / m11;
        r    := sqrt( c(x)^2 + c(y)^2 + m14/m11 );
    end;

    return r;                    // the radius

end;

//
//  Calculate determinate using recursive 
//  expansion by minors.
//
dett( a, n )
begin
    local i, j, j1, j2;
    local d := 0;
    local m := makemat(0,3,3);

    // assert n > 1

    if n = 2 then
        d := a(1,1)*a(2,2) - a(2,1)*a(1,2);
    else 
        d := 0;
        for j1 := 1 to n do
            // create minor
            for i := 2 to n do
                j2 := 1;
                for j := 1 to n do
                    if j <> j1 then
                      m(i-1,j2) := a(i,j);
                      j2 := j2 + 1;
                    end;
                end;
            end;
            // calculate determinant
            d := d + ( -1.0 )^(1 + j1 ) * a(1,j1) * dett( m, n-1 );
        end;
    end;
    
    return d;
end;
#end



RE: Debugging With an Orange Bang - webmasterpdx - 06-29-2017 12:01 PM

If you run it with the debugger, the cursor should be placed on the offending instruction (after you get the bang).


RE: Debugging With an Orange Bang - cyrille de brébisson - 06-30-2017 05:15 AM

Hello,

Your program is a CAS program and unfortunately, the debuger does not really work with the CAS...

now, as it turns out, your program, as far as I can tell, does not really need the CAS, so you should be able to remove the #cas at the top and easily transform said program in a home program. At that point, the debugger WILL work and you will be able to find the issue.

Cyrille


RE: Debugging With an Orange Bang - toml_12953 - 06-30-2017 10:24 AM

(06-30-2017 05:15 AM)cyrille de brĂ©bisson Wrote:  Hello,

Your program is a CAS program and unfortunately, the debuger does not really work with the CAS...

now, as it turns out, your program, as far as I can tell, does not really need the CAS, so you should be able to remove the #cas at the top and easily transform said program in a home program. At that point, the debugger WILL work and you will be able to find the issue.

Cyrille

You mean I can use =< to modify an array by reference in a non-CAS program? I tried that but get a syntax error at that line. I'll keep experimenting.


RE: Debugging With an Orange Bang - toml_12953 - 06-30-2017 11:50 AM

(06-29-2017 12:01 PM)webmasterpdx Wrote:  If you run it with the debugger, the cursor should be placed on the offending instruction (after you get the bang).

Thank for the reply. The cursor is put at the beginning of the first line "#cas"

That doesn't seem very helpful to me.


RE: Debugging With an Orange Bang - Didier Lachieze - 06-30-2017 11:56 AM

I've slightly modified your program and I've got a working version:
  • I've moved the first function out of the #cas #end sequence
  • I've moved the circl and dett declaration out of Testpass
  • I've added the declaration of the local variables within Testpass
In summary I've replaced:
Code:
#cas
Testpass():=
BEGIN

circl();
dett();
....
END;
by:
Code:
circl();
dett();

EXPORT Testpass()
BEGIN
LOCAL x,y,c,p,temp,r;
....
END;
#cas

The full code:
Code:
circl();
dett();

EXPORT Testpass()
BEGIN
LOCAL x,y,c,p,temp,r;

    x:=1; y:=2;   

    c:=makemat(0,2);
    p:=makemat(0,3,2);
    temp:="";
    
    p(1,x) := 7;
    p(1,y) := 7;
    
    p(2,x) := 0;
    p(2,y) := 8;
    
    p(3,x) := 0;
    p(3,y) := 0;  

    print();
    temp := "points: ";
    temp := temp + "("+ p(1,x)+ ", "+ p(1,y)+ "), ";
    temp := temp + "("+ p(2,x)+ ", "+ p(2,y)+ "), ";
    print (temp+"("+ p(3,x)+ ", "+ p(3,y)+ ") ");
    
    r := circl( c, p );
    if r > 0 then
        print ("Circle: ("+ c(x)+ ", "+ c(y)+ "), "+ r); 
    else
        print ("Not a circle!");
    end;

END;

#cas
//
//  Calculate center and radius of 
//  circle given three points
//
circl( c, p )
begin
    local x:=1, y:=2;
    local i;
    local r, m11, m12, m13, m14;
    local a:=makemat(0,3,3);

    for i := 1 to 3 do           // find minor 11
        a(i,1) := p(i,x);
        a(i,2) := p(i,y);
        a(i,3) := 1;
    end;
    m11 := dett( a, 3 );

    for i := 1 to 3 do           // find minor 12 
        a(i,1) := p(i,x)^2 + p(i,y)^2;
        a(i,2) := p(i,y);
        a(i,3) := 1;
    end;
    m12 := dett( a, 3 );

    for i := 1 to 3 do           // find minor 13
        a(i,1) := p(i,x)^2 + p(i,y)^2;
        a(i,2) := p(i,x);
        a(i,3) := 1;
    end;
    m13 := dett( a, 3 );

    for i := 1 to 3 do           // find minor 14
        a(i,1) := p(i,x)^2 + p(i,y)^2;
        a(i,2) := p(i,x);
        a(i,3) := p(i,y);
    end;
    m14 := dett( a, 3 );

    if m11 = 0 then
        r := 0;                  // not a circle
    else
        c(x) =<  0.5 * m12 / m11; // center of circle
        c(y) =< -0.5 * m13 / m11;
        r    := sqrt( c(x)^2 + c(y)^2 + m14/m11 );
    end;

    return r;                    // the radius

end;

//
//  Calculate determinate using recursive 
//  expansion by minors.
//
dett( a, n )
begin
    local i, j, j1, j2;
    local d := 0;
    local m := makemat(0,3,3);

    // assert n > 1

    if n = 2 then
        d := a(1,1)*a(2,2) - a(2,1)*a(1,2);
    else 
        d := 0;
        for j1 := 1 to n do
            // create minor
            for i := 2 to n do
                j2 := 1;
                for j := 1 to n do
                    if j <> j1 then
                      m(i-1,j2) := a(i,j);
                      j2 := j2 + 1;
                    end;
                end;
            end;
            // calculate determinant
            d := d + ( -1.0 )^(1 + j1 ) * a(1,j1) * dett( m, n-1 );
        end;
    end;
    
    return d;
end;
#end

(06-30-2017 10:24 AM)toml_12953 Wrote:  You mean I can use =< to modify an array by reference in a non-CAS program? I tried that but get a syntax error at that line. I'll keep experimenting.

Now I'm wondering why you use =< here as it works as well with := instead of =< in the lines:

Code:
        c(x) =<  0.5 * m12 / m11; // center of circle
        c(y) =< -0.5 * m13 / m11;



RE: Debugging With an Orange Bang - toml_12953 - 06-30-2017 12:26 PM

(06-30-2017 11:56 AM)Didier Lachieze Wrote:  Now I'm wondering why you use =< here as it works as well with := instead of =< in the lines:

Code:
        c(x) =<  0.5 * m12 / m11; // center of circle
        c(y) =< -0.5 * m13 / m11;

In order for that to work, c has to either be global or be passed by reference. Otherwise modifying the values in c in the function circl won't modify the values in the main program. At least that's what I've found in regular programs. Maybe in CAS programs it's different? If so, I'll be making most of my programs CAS from now on. Thanks for your time and expertise on this!


RE: Debugging With an Orange Bang - toml_12953 - 06-30-2017 12:33 PM

(06-30-2017 11:56 AM)Didier Lachieze Wrote:  I've slightly modified your program and I've got a working version:

I tried the following but c never gets modified in the main program:

Code:
circl();
dett();

x:=1; y:=2;

EXPORT Testpass()
begin

    local c,p,temp:="",r;

    c:=makemat(0,2);
    p:=makemat(0,3,2);
    
    p(1,x) := 7;
    p(1,y) := 7;
    
    p(2,x) := 0;
    p(2,y) := 8;
    
    p(3,x) := 0;
    p(3,y) := 0;  

    print();
    temp := "points: ";
    temp := temp + "("+ p(1,x)+ ", "+ p(1,y)+ "), ";
    temp := temp + "("+ p(2,x)+ ", "+ p(2,y)+ "), ";
    print (temp+"("+ p(3,x)+ ", "+ p(3,y)+ ") ");
    
    r := circl( c, p );
    if r > 0 then
        print ("Circle: ("+ c(x)+ ", "+ c(y)+ "), "+ r); 
    else
        print ("Not a circle!");
    end;

end;

#cas
//
//  Calculate center and radius of 
//  circle given three points
//
circl( c, p )
begin

    local i;
    local r, m11, m12, m13, m14;
    local a:=makemat(0,3,3);

    for i := 1 to 3 do           // find minor 11
        a(i,1) := p(i,x);
        a(i,2) := p(i,y);
        a(i,3) := 1;
    end;
    m11 := dett( a, 3 );

    for i := 1 to 3 do           // find minor 12 
        a(i,1) := p(i,x)^2 + p(i,y)^2;
        a(i,2) := p(i,y);
        a(i,3) := 1;
    end;
    m12 := dett( a, 3 );

    for i := 1 to 3 do           // find minor 13
        a(i,1) := p(i,x)^2 + p(i,y)^2;
        a(i,2) := p(i,x);
        a(i,3) := 1;
    end;
    m13 := dett( a, 3 );

    for i := 1 to 3 do           // find minor 14
        a(i,1) := p(i,x)^2 + p(i,y)^2;
        a(i,2) := p(i,x);
        a(i,3) := p(i,y);
    end;
    m14 := dett( a, 3 );

    if m11 = 0 then
        r := 0;                  // not a circle
    else
        c(x) =<  0.5 * m12 / m11; // center of circle
        c(y) =< -0.5 * m13 / m11;
        r    := sqrt( c(x)^2 + c(y)^2 + m14/m11 );
    end;

    return r;                    // the radius

end;

//
//  Calculate determinate using recursive 
//  expansion by minors.
//
dett( a, n )
begin
    local i, j, j1, j2;
    local d := 0;
    local m := makemat(0,3,3);

    // assert n > 1

    if n = 2 then
        d := a(1,1)*a(2,2) - a(2,1)*a(1,2);
    else 
        d := 0;
        for j1 := 1 to n do
            // create minor
            for i := 2 to n do
                j2 := 1;
                for j := 1 to n do
                    if j <> j1 then
                      m(i-1,j2) := a(i,j);
                      j2 := j2 + 1;
                    end;
                end;
            end;
            // calculate determinant
            d := d + ( -1.0 )^(1 + j1 ) * a(1,j1) * dett( m, n-1 );
        end;
    end;
    
    return d;
end;
#end

Run shows:
points: (7, 7), (0, 8), (0, 0)
Not a circle!
[/code]

When I debug it, it seems like circl never gets called. Step skips right over the call to circl.


RE: Debugging With an Orange Bang - Didier Lachieze - 06-30-2017 01:14 PM

(06-30-2017 12:26 PM)toml_12953 Wrote:  
(06-30-2017 11:56 AM)Didier Lachieze Wrote:  Now I'm wondering why you use =< here as it works as well with := instead of =< in the lines:

Code:
        c(x) =<  0.5 * m12 / m11; // center of circle
        c(y) =< -0.5 * m13 / m11;

In order for that to work, c has to either be global or be passed by reference. Otherwise modifying the values in c in the function circl won't modify the values in the main program. At least that's what I've found in regular programs. Maybe in CAS programs it's different? If so, I'll be making most of my programs CAS from now on. Thanks for your time and expertise on this!

Ok, I understand now what you're trying to do. But when you call circl with: circl(c,p) the parameters are not passed by reference as described for the xcas functions: "It is not possible to pass arguments by reference, only by value." I don't think it is different on the Prime.

So circl get a copy of c and whatever you do on it with := or =< , this will not change the value of c in the main program. At least this is how I understand it.

You can have c declared as a global variable but in this case it should not be a parameter of circl and then whatever change is done in circl will be visible to the main program but there is no need to use =< for that.


RE: Debugging With an Orange Bang - toml_12953 - 06-30-2017 01:38 PM

(06-30-2017 01:14 PM)Didier Lachieze Wrote:  
(06-30-2017 12:26 PM)toml_12953 Wrote:  In order for that to work, c has to either be global or be passed by reference. Otherwise modifying the values in c in the function circl won't modify the values in the main program. At least that's what I've found in regular programs. Maybe in CAS programs it's different? If so, I'll be making most of my programs CAS from now on. Thanks for your time and expertise on this!

Ok, I understand now what you're trying to do. But when you call circl with: circl(c,p) the parameters are not passed by reference as described for the xcas functions: "It is not possible to pass arguments by reference, only by value." I don't think it is different on the Prime.

So circl get a copy of c and whatever you do on it with := or =< , this will not change the value of c in the main program. At least this is how I understand it.

You can have c declared as a global variable but in this case it should not be a parameter of circl and then whatever change is done in circl will be visible to the main program but there is no need to use =< for that.

My original program worked and did use c as a global array but I was hoping to eliminate that with =<.
So what is the point of =< as opposed to := ? I thought =< was supposed to modify by reference. If it doesn't, I really don't see the utility of it.


RE: Debugging With an Orange Bang - roadrunner - 06-30-2017 05:22 PM

Couldn't you just make c a local variable? Like this:

Code:
LOCAL DoSomeStuff();
LOCAL c;

EXPORT TryThis()
BEGIN
 c:={0,0}; // initialize c
 DoSomeStuff(); // do what ever you want with c

// do some more stuff with c
 print();
 print(c);
 return c;
END;

DoSomeStuff()
BEGIN
 c:={2,2};
 return 1;
END;

-road


RE: Debugging With an Orange Bang - toml_12953 - 06-30-2017 05:56 PM

(06-30-2017 05:22 PM)roadrunner Wrote:  Couldn't you just make c a local variable? Like this:

Code:
LOCAL DoSomeStuff();
LOCAL c;

-road

Huh. I thought a variable outside the EXPORT begin-end block had to be global. Your suggestion makes them semi-global - Global to all routines in this program but not seen by other programs. I have so much to learn! That's why I have so much fun with these machines. I learn so much. Thanks for your input!


RE: Debugging With an Orange Bang - Tim Wessman - 06-30-2017 09:12 PM

You don't need to put the LOCAL there either (it is optional ouside of a function scope). Any variable declared outside the scope will be one of these "local to the file" variables that don't appear outside the system except for full qualification.


RE: Debugging With an Orange Bang - webmasterpdx - 07-01-2017 10:55 PM

If the debugger is on the #CAS instruction when you get the fault, then it could be that you are missing a matching END; statement, or you have to be in CAS mode to run it. I think if you want to run it in home mode, you need to use EXPORT instead of #cas.....