Re: [personal kdb+] what's up with parse?

Reply-To: manni.patel@gmail.comX-Priority: NormalSensitivity: NormalImportance: NormalSubject: Re: [personal kdb+] what’s up with parse?To: personal-kdbplus@googlegroups.comFrom: “Manish Patel” <manni.patel>Date: Fri, 21 Aug 2009 13:43:02 +0000eW91IG5lZWQgdG8gZXNjYXBlIHRoZSBcIHdpdGggYW4gZXh0cmEgXCAgLCBidXQgSSBndWVzcyBwYXJzZSBzaG91bGQgZG8gdGhhdCBhdXRvbWF0aWNhbGx5DQoNCg0KLS0tLS0tT3JpZ2luYWwgTWVzc2FnZS0tLS0tLQ0KRnJvbTogYW5keXR1cmsNClNlbmRlcjogcGVyc29uYWwta2RicGx1c0Bnb29nbGVncm91cHMuY29tDQpUbzogS2RiKyBQZXJzb25hbCBEZXZlbG9wZXJzDQpSZXBseVRvOiBwZXJzb25hbC1rZGJwbHVzQGdvb2dsZWdyb3Vwcy5jb20NClN1YmplY3Q6IFtwZXJzb25hbCBrZGIrXSB3aGF0J3MgdXAgd2l0aCBwYXJzZT8NClNlbnQ6IDIxIEF1ZyAyMDA5IDE0OjM4DQoNCg0KSXQgc2VlbXMgdGhhdCBwYXJzZSBjYW4ndCBwYXJzZSAoc29tZSkgdmFsaWQgZXhwcmVzc2lvbnMuIEZvcg0KZXhhbXBsZS4uLg0KDQpxKTEgMiwvOjMNCjQNCjEgMiAzDQoxIDIgNA0KcSlwYXJzZSAiMSAyLC86Mw0KNCINCi86ICwNCjEgIDINCjMgIDQNCnEpMSAyLC86XDozDQo0DQoxIDMgMSA0DQoyIDMgMiA0DQpxKXBhcnNlICIxIDIsLzpcOjMNCjQiDQonIjEgMiwvOlw6MyA0Ig0KDQoNCg0KDQpTZW50IHVzaW5nIEJsYWNrQmVycnmuIGZyb20gT3Jhbmdl</manni.patel>

On Aug 21, 8:43?pm, “Manish Patel” <manni.pa…> wrote:> you need to escape the \ with an extra \Doh!KDB+ 2.5 2009.08.05 Copyright (C) 1993-2009 Kx Systemsm32/ 2()core 4096MB andy andy-turks-macbook-pro.local 10.211.55.2 PLAY2009.11.03q)parse “1 2,/:\: 3 4”: (/:;,)1 23 4q)I thought the error was coming from my explicit call to parse. Nope.The main loop parser choked before it got there.</manni.pa…>

Last night, I wrote…> The main loop parser choked before it got there.This morning, with somewhat refreshed eyes, I looked at the earlierdiscussion and thought, “Why wouldn’t ,/:: (the original problem)simply reduce to ,/:: within the quotes?” In other words, the main-loop parser got a valid expression and the invoked parser was the onethat died. So for kicks, I try:q)parse “1 2,/::3 4”/: ,1 23 4It parsed! How strange.q)1 2,/::3 41 2 31 2 4Apparently, ,/:: has the same meaning as ,/:. I don’t understand why,but at least it parses and evaluates. At this point, I was completelyconfused. Given that “1 2,/::3 4” is parseable and valid q, why isn’t"1 2,/::3 4" equivalent? A little experimentation yielded the answer.q’s parser chokes if (within a string) you try to escape a characterthat isn’t escapable. This is different than other languages, where \Xreduces to X when X is a garden variety character. E.g., in C, “\G” isthe same string as “G”. In q, however, “\G” isn’t a valid string.Which means that…The originally offending code, “1 2,/::3 4” caused a parsing error inthe main loop because : is not escapable. I’m guessing that behaviorhelps coders find problems more quickly, since \ has multipleinterpretations.But that leaves the mystery over ,/:: How many colons can we have?q)parse “1 2,/::::::::::3 4”/: ,1 23 4Apparently, quite a lot. ;-)