Possible problem with assign( function?

In Pan6, this code

local Array1, Temp, Sep, MaxMin
Array1 = "4;6;1;8;3;7"
MaxMin = array(Array1,1,";") + " 1"

ArrayFilter Array1,Temp,";",assign(?(val(import())<val(MaxMin),import()
        +" "+str(seq()),MaxMin),"MaxMin")

message MaxMin

determines the lowest number in an array of numeric values and its position in the array. In this case, the result is “1 3”, meaning “1” is the lowest number and it is in position 3.

In Pan X, the ArrayFilter expression returns an error message of “No value for import( function.”

Why?

michael

Thinking that this might be related to the precedence issue (BitBucket #141), I tried putting curly brackets around val(import())<val(MaxMin). This gave the result 4 1 which is the initial value of MaxMin, but it gets rid of the “No value for import( function.” message.

michael

I doubt if it’s related to the precedence issue. Whether the comparison returns the right value or not, import() should still have a value. Putting curly braces around that comparison formula just turned it into a string of text. Since Panorama needs for that parameter to be a number, it converts that text to a number. Since the text doesn’t begin with a numeral, or minus sign, or decimal point, it converts it to zero, which means false. Now it’s returning the false value every time, and that doesn’t have an import() function in its formula.

Do you have any ideas on what’s causing it?

m

Somehow, the assign( function is interfering with the import() function. Removing the assign( function from the formula causes it to run without error. Replacing import() with array(Array1,seq(),";") causes it to run without error, and return the right answer.

That’s great! Thanks Dave.

m

Just a thought, but should this assign( and import() incompatibility be a BitBucket entry?

michael

I just submitted it as issue #567.

I’m not certain this is related, but I may have another piece to this problem. I’m not certain mine is related, but I’m getting the same error regarding import(). Nothing else here or on BitBucket seems to fit and #567 remains unresolved.

importtext fileload(iFile), "REARRANGE",import()

gives me the runtime error “No value for import( function.”

iFile is a crlf delimited file from Windows with fixed text length fields which can include commas. Without the REARRANGE iFile imports as expected; the commas split fields where they fall. In Pan6 I handled this with importusing and strip(import()[1,Whatever])+tab()+strip(import()[Whatever+1,nextWhatever])... as needed to split fields where I wanted. I knew importuning was deprecated; moreover, it fails syntax checks although it is still mentioned within a few help topics. Help suggests putting the same import() containing formulas that I’d used after importuning, after "REARRANGE", should give the same results. But even this most basic formula, to put each entire line into the first field of each record fails with the above error. Might PanX be doing something internally here with import() similar to whatever caused Michael’s problems between assign( and import(), which might help Jim fix both? Or am I misunderstanding something about importtext?
I’m glad Dave’s workaround sufficed for Michael, but I don’t see how to fit it into an importtext statement unless the following would work:

local Array1
array1=fileload(iFile)
importtext array1, "REARRANGE",array(Array1,seq(),crlf())

and it doesn’t, instead adding the correct number of records, all full of empty text.

As a workaround, you could use an arrayfilter between the fileload( and the importtext.

local Array1
Array1=fileload(iFile)
arrayfilter Array1,Array1,crlf(),strip(import()[1,Whatever])+tab()+strip(import()[Whatever+1,nextWhatever]) + etc.
importtext Array1

I think this is a different bug. I’ve added it to BitBucket.

Dave,

Your workaround finally worked, but required an interesting extra step, which may make sense to those more knowledgeable than I. I had to change your second line to
Array1=binarytotext(file load(iFile)) or I’d get the error “arrrayfilter( function: ARRAY parameter must be text.” Adding binarytotext( with the optional encoding parameter left out removed that error and iFile proceeded to import properly. Thanks!

I’ll add some more details that might help Jim debug this. It took some trial and error plus closer reading of PanX’s help for me to figure out which parameter Arrayfilter( hadn’t thought was text. Fileload('s help says it returns binary data but automatically converts that to text, assuming UTF-8 text, when presenting that to another function requiring a text parameter. Running binarytotext( also without the optional encoding parameter gave something Arrayfilter accepted as text but whatever Fileload( did automatically hadn’t. Importtext would accept Fileload(iFile) without the added binarytotext( if I didn’t “Rearrange” things, but if I “Rearranged” I got the same error on import() with or without binarytotext( on the Fileload(.

My iFile is a generated file exported by a Windows database which TextWrangler’s status bar claims uses UTF-8 encoding. Pan6 always imported it fine via importusing and import() with text funnels. From the Windows side, although it has a “.txt” extension, in the Save File dialog there was a pop-up menu which had to be set to “Text Emulation Report” or some such, rather than to “Text,” to get the desired file. So maybe there is something odd about its text encoding I don’t understand.

Here’s what the Panorama help actually says:

Panorama performs this conversion automatically when binary data is passed to a function or statement that requires text.

It’s not the fileload( function that does this conversion, it is the receiving statement or function, and not every statement or function does this, only statements or functions that could not ever make sense of binary data. Arrayfilter could receive a binary data array as a legitimate value, so it does not perform this automatic conversion. ImportText, on the other hand, always requires text so it does perform the automatic conversion when it encounters binary data. When in doubt, it’s always best to use binarytotext(.

If Panorama 6 imported it correctly, it must have been ASCII. Panorama 6 would not correctly import any format except ASCII or MacOS Roman encoding. (If the text only contained basic letters, numbers and punctuation then UTF-8 and ASCII are the same, but if there were any accented characters or characters above 127, Panorama 6 would choke.)

I haven’t played, yet, with binary arrays so overlooked their possibility. Yet the error message said “arrrayfilter( function: ARRAY parameter must be text.” Am I correct in guessing that ArrayFilter analyzed the formula I’d supplied and determined that text input, rather than the binary I’d unthinkingly supplied, was required? With some kinds of formula it only accepts text input and with some other kinds it accepts only binary input?

The rest of your explanation makes sense and the file should qualify as ASCII. Dave’s workaround will serve me until you fix the bug.

The arrayfilter( function has two formats. If there are 3 parameters, it expects a text array, if 2 parameters, a data array. The arrayfilter statement always expects a text array. So – it actually could do the automatic conversion, but it doesn’t.

By the way, I would agree that the documentation for fileload( is not really very clear on this topic.

Ah, that makes more sense, and is doubtless much faster, than pre-evaluating the formula as text vs. binary.

Documentation is never as good as the human capacity to invent confusion. Yours has generally been very good, based on many years reading many versions worth of it. Your problem is that Panorama’s vast needed documentation, proportional to its vast power, makes it hard to keep the documentation 100% accurate, complete and current. And the imperfect minority draws disproportionate comments. At least in PanoramaX you’ve added multiple mechanisms to crowd source checking the documentation and updates to it go out with each program update. Improve it appropriately but don’t over-prioritize that vs. fixing/adding code.

Don’t worry, I wasn’t going to :slight_smile:

As a prodigious consumer of documentation as well as an author, I am well aware that documentation cannot be perfect. For example, Apple’s developer documentation leaves me scratching my head in confusion on a regular basis!

However, I did want to acknowledge that your imperfect knowledge in this area was more my fault than yours.

My workaround actually used the arrayfilter statement, rather than the arrayfilter( function. The statement doesn’t work with data arrays, and apparently always converts binary to text, so it worked fine when I tested.

I wish I could say I chose the statement, rather than the function, for that reason, but it was really just force of habit. In Panorama 6, I avoided the function when the statement would do as well, and even though the reasons for that don’t apply to Panorama X, I tend to do that there as well.

Scratch that. I just realized, the reason it worked was that I didn’t use fileload(. I just pasted the sample text I was using into the procedure.

I was using the ArrayFilter statement, not the function, when I received the error message containing “arrayfilter( function.” In context it obviously referred to something wrong with the statement although it took a little while for me to approximate just what. Jim’s better educated me since. But if Jim intended such error messages to match references to statements vs. functions he could add this to his list of trivial bugs to correct. I don’t need to know whether he did that.