Creating a custom function from a custom statement

I have created a custom statement and put it in my default library (~/Library/Application Support/PanoramaX/Libraries/MyLibrary). One calls the statement with the code StatementName input,output. The calling procedure supplies the input and the statement returns the output. So how do I convert this to a function, in the form output=StatementName(input)? Are there step by step instructions somewhere on how to do this? I have made several attempts but end up with an error that just leaves me confused.

Tom, I’ve sent you a couple of documents which explain in great detail how to set up custom statements and how to create custom functions from them.

For the benefit of other forum members who may be interested, these are two text files which are written in a form designed for inclusion in the Panorama X Help wizard. Here’s how to use them:

  1. Open one of them, select all and copy.
  2. Open the Panorama X Help wizard, pick a topic at random and open the corrections window.
  3. Select all in the corrections window and delete the contents (no harm will come from this).
  4. Paste in the text on the clipboard and it will look like this:

  1. Click on the Preview tab and it will look like this:

  1. Read it.

The two source files, one for custom statements the other for custom functions, can be downloaded from here:

Hi Michael,

This is exactly what I needed. I got my first custom function working. I had trouble using a corrections window to view the text file. The preview would not display after I pasted in the text, but I just used the document in a word processing document.

I guess this also answers the question I asked earlier, why do we need both statements and functions that do the same thing.

Anyway, thank you so much for this.

Tom

To use the preview, you need to have a copy of MultiMarkdown installed.

Yep - I’d forgotten that.

FYI you can get MultiMarkdown free here:

https://fletcherpenney.net/multimarkdown/

I have encountered some problem that I have not been able to solve in creating a custom function. I have created custom statements and corresponding functions and saved them in my default custom statement library. Then I have added another database with a new custom Statement into the Library and that works. But if I try to create the corresponding custom function, that has failed every time. I get an error during startup of Panorama saying ‘Field or variable “libfunctions” does not exist.’ I am forced to restart PanX and log in to my account again.
Any suggestions on how to solve this problem? I would be glad to post more details if someone thinks that will be helpful.
00%20PM

Following this. I also saw some similar issue when my cousin was trying to create a custom function back in the morning. I even checked it on FinancePolice.com. but not satisfied.

Expecting some good information from the people here. XoXo

Unfortunately, that error message isn’t very informative as to how Panorama got to that point.

I assume you have an .InitializeFunctions statement in your library database? What does that code look like, and how did you change it just before this happened?

I don’t quite get this. I would think to recover you would need to quit, then move the library database out of the folder so that it doesn’t get invoked on launch, then relaunch. I don’t know why you would have to log in to your account again at that point.

However, I can definitely see why you wouldn’t be logged in at the point that this error dialog appeared. The error stopped Panorama’s initialization process, so it didn’t finish running the code that initializes your account.

If Panorama is stopped by an error when initializing, you really can’t continue running it. However, if you look at the SCANLIBRARY code above where the error occurs, you can see that when it calls your .InitializeFunction it has error handling code in place so that it should recover from any type of error in your code. I’m not happy that this isn’t happening. I just did a test and the error recovery worked even if there was a syntax error in the procedure being called. So I am at a loss as to why the error recovery isn’t working for you.

Do you have notifications enabled on your system? If there is an error in your .InitializeFunctions code, Panorama is supposed to throw up a notification. If notifications aren’t enabled it should just continue silently, but it would be good to know if that notification is appearing and what it says.

Bottom line, there is nothing normal about what you are seeing. This isn’t a standard error that I can just say “oh yes, here’s the fix.” Since you haven’t given us any information at all about what you actually did to try to set up a custom function, I can’t really diagnose any further at this point.

I created a file named TestCustomFunction.
I created a statement named MYCIRCLEAREA with two parameters, diameter and area. It calculates the area based on the diameter. The statement works.
Then I wanted to make a corresponding function. To do that I did two things:

I create a procedure in the same database named mycircleareaf with this code:

 let lvarea=0
 MYCIRCLEAREA parameter(1),lvarea
 functionvalue lvarea

I created a procedure .InitializeFunctions with this code:

registercustomfunction "mycirclearea(",1,{call ("TestCustomFunction","mycircleareaf",•1)}

I dragged this file to my ~/Libraries/Application Suppport/PanoramaX/Libraries folder. I restarted PanX.

This has failed consistently in the same way. To recover, I have to quit, drag the file out of the Libraries folder, and then log in on the next start. Notifications are enabled in PanoramaX.

Just to make sure custom functions are working, I downloaded a database from the Database Exchange with a custom function and it worked as expected. I have added custom functions to my default library and they work as expected.

There is a syntax error in the call because of a space before the ( character. Don’t know if this just a typo in the form post or if it is in your procedure as well.

Gary, that was the problem. Thanks. That little mistake on my part caused a dramatic failure of Panorama, in which I had to quit, drag the offending file out of the library, restart and log in again to my account.

Ok, I’m a bit stumped here.

Thomas sent me his database, and I moved it into position and relaunched Panorama. As Panorama launched, a notification appeared about the syntax error, and then Panorama launched normally. Everything was fine.

I did a bit of further research and the bad error message is an old bug.

But the mystery is that this bug was fixed in October 2017, before the release of Panorama X 10.0. In fact, this fix is mentioned in the 0.9.008 release notes from Oct 12.

  • Panorama now has better protection against programming errors in custom functions and libraries. If an error is detected, a notification will appear, but the initialization process will continue and Panorama will run normally.

I can’t imagine that Thomas is using a Panorama X version from over 18 months ago. So why does it work correctly for me and not for him? This is very puzzling. Could you check the SCANLIBRARY code on your copy of Panorama (in _PanoramaLib) and make sure it contains this code? This is easily accessed with the View>Open View dialog.

if arraycontains(libProcedures,".InitializeFunctions",cr())
    try
        farcall libName+"",".InitializeFunctions"
    catch
        nsnotify "InitializeFunctions Error",
            "alwaysdisturb",true(),
            "text",libName+": "+info("error")
    endcatch
endif

I will suggest, though, that it is always an excellent idea to make sure custom statements and functions are tested before putting them into the Panorama X initialization process. You can run the registercustomfunction statement at any time, not just during initialization. The reason to put them into .InitializeFunction is so that they are always available, but you can temporarily run this code from a regular database to test it. I would do that to make sure everything works before putting the code into .InitializeFunction.

I have PanX Version 10.1.2 (2854) and the code you cite is included in my SCANLIBRARY code. I see that the error was reported to have occurred about lines later, on the looparray statement (see the screen shot I uploaded earlier.)

I will certainly test the functions before putting them in the Library folder.