Wasting Time with PanX (Happy Pi Day!)


#1

If you have a few minutes for a slightly amusing thing, try running this code, but today only:

setdialogtrigger ""
let lvpi=3 //the approximate value of pi
let n=2
let x=1 //for counting the iterations

loop

    lvpi=lvpi+4/(n*(n+1)*(n+2))-4/((n+2)*(n+3)*(n+4))
    shortcall "otherstuff"

until 1000

otherstuff:    
    n=n+4
    x=x+1

    if str(lvpi)[1,12]="3.1415926535"
        Alertsheet x +" iterations. Happy pi day!"+cr()+cr()+"pi ≈ 3.1415926535","Buttons","Yippeee!"
        stop
    endif

    let lvbut=switch(x,100,"Not Bad for 100 stabs.",200,"Pretty Good!",300,"Nilakantha would be so proud!",400,"Aren't computers great?",500,"Am I boring you?",600,"Hang on "+array(info("user"),1," "),700,"Getting very warm!","Go for it!")

if x mod 100=0
    alertsheet "Pi ≈ "+pattern(lvpi,"#.##########")+cr()+cr()+"Error:  "+pattern(3.1415926535-lvpi,"#.##########"),"buttons",lvbut+",Cancel"
    if info("dialogtrigger")="Cancel"
        nsnotify "You Cancelled!"
        stop
    endif
endif

rtn

#2

:pie::pie: Not a waste of time - I will be using the switch( function more frequently in the future. :pie::pie:


#3

Note that the setdialogtrigger "" at the top isn’t necessary.

Also, FYI, Panorama includes the pi() function, or you can even just type in π, so it’s not necessary to type in the digits of pi into the program. For example you could just say:

pattern(π-lvpi,"#.##########")

P.S. Silly fact – everyone in this thread so far has Tom in their name (it’s my middle name).


#4

I think maybe my feelings are hurt. I can’t believe you thought I don’t know about pi(. Although I did just admit recently to not knowing about some other longstanding functions. But pi( cannot return a series of humorous messages and I am certainly hoping that that feature gets on the list of future improvements.
On a more serious note, I think that from time to time I have had the value of info(“dialogtrigger”) persist longer than I expected. The help page does not say when it returns to “”. While I was testing the pi program, I thought I encountered a persistent value for info(“dialogtrigger”). But I have never taken the time to determine more carefully what happened in those cases and so I have never raised the issue on the forum. For example, I am unclear if a subroutine calls an alert and a Cancel button is pushed, and then control is passed to the calling routine, does the value of info(“dialogtrigger”), i.e., Cancel, persist while the calling routine is running. If we test once for the value of info(“dialogtrigger”), does that return it to “”? What event should I expect will return the value of info(“dialogtrigger”) to “”?


#5

The value for info(“dialogtrigger”) persists until the next instance when it is used. It is good practice to use setdialogtrigger “” beforehand in the code so you know what is a legitimate result and not a leftover from some previous action.


#6

Ditto for info(“Trigger”)


#7

I wasn’t suggesting that pi( could replace the entire fun program you submitted! Just the places where you typed “3.1415926535” :slightly_smiling_face:


#8

I think a slightly better way to state this would be to say, it persists until another dialog or alert is opened.

it is good practice to use setdialogtrigger “” beforehand

Well, I wouldn’t say that is bad practice, but it’s not something I have ever done. Whenever I use this function, it is always immediately after I open the alert, like this, so there is no question as to whether this is a leftover result.

alert "this or that"
if info("dialogtrigger")="this"
    ...
elseif info("dialogtrigger")="that"
    ...
endif

If for some reason I need to use the dialogtrigger value later, I’ll always copy it into a variable, then use the variable later instead of the info(“dialogtrigger”) function.

alert "this or that"
let thisOrThatButton = info("dialogtrigger")
...
...
alert "that or the other thing"
...
if thisOrThatButton = "this"
    ....
endif

I use the same technique for the info(“trigger”) function. So I never worry about leftover results, even though I never use setdialogtrigger "" or settrigger "".

In this particular “pi” example, the only time info(“dialogtrigger”) is ever used is immediately after an alert statement. This follows my suggested practice, so there is no way for a leftover result to happen. Hence my statement that the setdialogtrigger "" wasn’t needed. It doesn’t hurt anything, but it can never affect the operation of the program either.


#9

Thanks for this clarification on info(“dialogtrigger”). Perhaps I misinterpreted what happened in past cases since I also would ordinarily test for info(“dialogtrigger”) immediately after a dialog or alert.