It seems to me that this is in the spirit o J. Many uses of @ and other symbols indicate to me that the writer is "thinking" from left to right. If the coding of J is essentially from right to left your order feels right to me.
Linda -----Original Message----- From: Programming [mailto:[email protected]] On Behalf Of bill lam Sent: Monday, December 26, 2016 7:39 PM To: Programming forum Subject: Re: [Jprogramming] unmatched parenthesis '((()' shouldn't the first unmatched at index 1 instead of 0? ie use i: instead of i. for unmatched (. On 27 Dec, 2016 8:31 am, "Raul Miller" <[email protected]> wrote: Ah, good point - I was not properly handling the case where the first unmatched parenthesis was the first character on the line. Also, the close script line is something of a special case, but it's easy enough to check for: With that fix and this change, I'd do something like this: firstunmatched=:3 :0 if. ')' -:&(-.&' ') y do. #y return. end. q=. unquoted=. -.~:/\y='''' c=. uncommented=. -. +./\ q * 'NB.' E. y n=. parendepth=. +/\q*c*-/'()'=/y if. 0 < {: n do. (n i. _1) <. 1 i:~0 1 E. 0,n else. n i. _1 end. ) Thanks, -- Raul On Mon, Dec 26, 2016 at 7:05 PM, bill lam <[email protected]> wrote: > your verb seemed to find unmatched ) only, e.g. failed for '(()' or > '(()(' > also a line of ) and whitespace belongs to class 'close definition' > and should not be flagged as mismatch. > > > On 27 Dec, 2016 2:42 am, "Raul Miller" <[email protected]> wrote: > >> I'm not sure what you mean by "containing control words" but code >> readability issues are usually a call for better code. >> >> For this, perhaps (warning: lightly tested code): >> >> firstunmatched=:3 :0 >> q=. unquoted=. -.~:/\y='''' >> c=. uncommented=. -. +./\ q * 'NB.' E. y >> n=. parendepth=. +/\q*c*-/'()'=/y >> if. 0 < {: n do. >> (n i. _1) <. 1+1 i:~0 1 E. n >> else. >> n i. _1 >> end. >> ) >> >> In other words: ignoring quoted and commented parenthesis, look for >> the first occurrence of either an unbalanced right parenthesis or an >> unbalanced left parenthesis. >> >> Let me know, though, if you see any flaws in this implementation. >> >> Thanks, >> >> -- >> Raul >> >> >> On Mon, Dec 26, 2016 at 12:57 PM, Henry Rich <[email protected]> wrote: >> > I don't think it is reasonable to treat ')' and 'NB.' as containing >> control >> > words. It makes the code very hard to read. >> > >> > Showing the mismatched parenthesis is important enough that it >> > might be better to have it even with this deficiency, but it IS a >> > deficiency and should be treated as a bug to be fixed someday. >> > >> > Henry Rich >> > >> > On 12/26/2016 11:48 AM, bill lam wrote: >> >> >> >> I double checked with j602, it has no problem in high lighting the >> >> unmatched )( in >> >> >> >> a '+' ((mno - rst) % b NB. )unmatched paren >> >> ^ >> >> a '+' ((mno - rst) % b ')' NB. )unmatched paren >> >> ^ >> >> and >> >> >> >> '(' (=:)) >> >> ^ >> >> But this is matched and is correct a '+' ((mno - rst) % b ')') NB. >> >> )unmatched paren >> >> >> >> I think it is reasonable to omit this pattern for syntax >> >> high-lighting. >> >> >> > >> > ------------------------------------------------------------------- >> > --- For information about J forums see >> > http://www.jsoftware.com/forums.htm >> --------------------------------------------------------------------- >> - For information about J forums see >> http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
