I think this is close to what you want. It doubles embedded quotes and ignores leading and trailing quotes if present. That way one can still enter a string which is really supposed have a quote at the begining or end. The only real problem is that if one wanted to start or end with a quote but forgot to add one extra.
quotes=:3 : 0 '''' quotes y NB. Default left argument is quote. : 'l r'=.x=({.,{:)y NB. Remove leading and trailing quotes if present. s=.l}.(-r)}.y s=.s#~>:x=s NB. Double quotes. x,s,x NB. Put leading and trailing quotes back. ) s=:}:0 : 0 x y' z ' ) s x y' z ' quotes s 'x y'' z ' s2=:}:0 : 0 x y' z '' ) s2 x y' z '' quotes s2 'x y'' z ''' On Sun, Feb 12, 2012 at 10:16 AM, R.E. Boss <r.e.b...@planet.nl> wrote: > This is quite an adequate answer. > > The origin was that I was thinking why character strings have all these > quote rules. Obviously, to distinguish them from (user defined) nouns. > But what if I wanted to present the J-GUI to an innocent user who > certainly > will not remember these rules? Then I'm (and so she will be) stuck. > Unless, as you suggest, I "take over the REPL". > > (I wasn't (directly) thinking J-lite, but perhaps this will come in handy > in > the future.) > > For this moment I should bypass the problem and ask the user to enter the > string(s) in a csv-file and then start J by reading that file. > > Thanks for all comments. > > > R.E. Boss > > > > -----Oorspronkelijk bericht----- > > Van: programming-boun...@jsoftware.com [mailto:programming- > > boun...@jsoftware.com] Namens Dan Bron > > Verzonden: zondag 12 februari 2012 16:38 > > Aan: 'Programming forum' > > Onderwerp: Re: [Jprogramming] quote problem > > > > Of course, that part's easy. > > > > ntt =: verb def '5!:5{.;:''y''' NB. Noun To Text > > > > ntt;._2 noun define -.TAB > > a. i. '(`'3 > > a. i. '(`'3' > > 'open 'quote > > ) > > 'a. i. ''(`''3' > > 'a. i. ''(`''3''' > > '''open ''quote' > > > > But it goes back to the original questions: > > 1. What is the source of these strings? > > _Where_ is your user typing them in? > > > > 2. What is processing these strings? > > > > If the answer to #1 is a file, or a GUI (e.g. wd, web interface, etc) or > > anywhere other than immex mode, the answer is easy. But I'm getting the > > sense that the very reason you want to quote these strings is so that J > can > > process them in immex mode. You don't need them quoted for your own > > purposes. > > > > That is, you're trying to give your user access to the power of J > (because > > it's so close to what your user needs already....) but you feel that > > out-of-the-box, J is a little too picky about input. That is, J is > > powerful, but not trivial to learn and use. So you want something like > J, > > but simpler, easier. You want a "Simple J"; an "Easy J". > > > > Is that right? If so, does it sound familiar? > > > > Anyway, if that is what you're after (the user typing something J-like > but > > not-quite-J into immex mode), then you need to commandeer the IJX > > session > > manager. Because, by definition, anything typed into the IJX session > > manager has to be a valid J sentence. But once you take over the REPL, > you > > can do whatever you like; you can implement your own, J-like language. > > > > http://www.jsoftware.com/jwiki/RicSherlock/Temp/InteractiveProm > > pt > > (Note in particular the caveats at the bottom of the page) > > > > http://www.jsoftware.com/jwiki/DanBron/Temp/REPL > > (A similar program) > > > > Which leads me to question #2: what other things does your language > > permit, > > that J would not, out-of-the-box? Because, once you solve your quoting > > problem, if you're still using ". (i.e., J) to process your strings, > you're > > going to hit new hurdles. > > > > i =: 2 NB. User is typing this stuff in > > j =: 3 > > > > i j { i. 4 5 > > |syntax error > > | i j{i.4 5 > > |[-0] > > > > NB. ??? I'm a sad, confused user > > > > +:^:3 2 NB. RE told me about this power operator thing, it > > sounds so cool! > > +:^:3 2 > > > > NB. Darn, it's broken! > > > > Of course, I could be reading too much into your messages, and be totally > > off-base about this "J Lite" thing. If so, can you share the bigger > picture > > of your use case? Who is the user, what is he doing, what are his > > objectives, what is his interface to your application, etc? > > > > -Dan > > > > -----Original Message----- > > From: programming-boun...@jsoftware.com > > [mailto:programming-boun...@jsoftware.com] On Behalf Of R.E. Boss > > Sent: Sunday, February 12, 2012 9:40 AM > > To: 'Programming forum' > > Subject: Re: [Jprogramming] quote problem > > > > The (input) string should be considered as one group (of chars). > > Quoting is needed if the first or the last (or both) is not a quote, all > > inside quotes should be doubled if they are not. > > > > > > R.E. Boss > > > > > > > -----Oorspronkelijk bericht----- > > > Van: programming-boun...@jsoftware.com [mailto:programming- > > > boun...@jsoftware.com] Namens Don Guinn > > > Verzonden: zondag 12 februari 2012 14:03 > > > Aan: Programming forum > > > Onderwerp: Re: [Jprogramming] quote problem > > > > > > Given the string contains several groups of non-blanks, would each > group > > > need to be surrounded with quotes and quotes within it doubled if not a > > > number, or only if it contained one or more quotes? Or should the > string > > be > > > considered as one group? Again, when would quoting be needed? > > > > > > On Sun, Feb 12, 2012 at 1:17 AM, R.E. Boss <r.e.b...@planet.nl> wrote: > > > > > > > The problem boils down to the fact that J requires a string (of > chars) > > to > > > > be > > > > enclosed in (single) quotes and the inside quotes have to be doubled. > > > > (Contrary to a spreadsheet (e.g.) where a cell is of type char if it > is > > not > > > > a number.) > > > > But what if I don't want bother a user with these requirements, she > > enters > > > > a > > > > string and my verb does the enclosing and doubling, if necessary? > > > > > > > > > > > > R.E. Boss > > > > > > > > > > > > > -----Oorspronkelijk bericht----- > > > > > Van: programming-boun...@jsoftware.com [mailto:programming- > > > > > boun...@jsoftware.com] Namens Dan Bron > > > > > Verzonden: zaterdag 11 februari 2012 20:35 > > > > > Aan: J Programming > > > > > Onderwerp: Re: [Jprogramming] quote problem > > > > > > > > > > Oh, just saw Henry's response and he interpreted your question > > > > differently. > > > > > > > > > > If you're not typing these strings in, then what is the source? > And > > what > > > > is > > > > > processing them (is it ;: ? if it's ". there's more to worry about > > than > > > > proper > > > > > quoting). > > > > > > > > > > Anyway, if the strings are coming from e.g. a file and the trouble > is > > > > with > > > > > parsing them using ;: (instead of evaluating them in the immex > > session), > > > > then > > > > > you could try something along the lines of (#~ 2 * '''' = ]) y > (i.e. > > > > double > > > > > singleton quotes). > > > > > > > > > > -Dan > > > > > > > > > > Please excuse typos; composed on a handheld device. > > > > > > > > > > -----Original Message----- > > > > > From: Dan Bron <j...@bron.us> > > > > > Sender: programming-boun...@jsoftware.com > > > > > Date: Sat, 11 Feb 2012 14:05:16 > > > > > To: Programming forum<programming@jsoftware.com> > > > > > Reply-To: Programming forum <programming@jsoftware.com> > > > > > Subject: Re: [Jprogramming] quote problem > > > > > > > > > > Unlike C, where \ introduces an escape sequence within string > > liberals, > > > > in > > > > J, > > > > > the only special character in a literal is ' (single quote). > > > > > > > > > > So, to embed quotes in strings, double them up: a. i. '(`''3' . > > Of > > > > course, > > > > > recursively embedded quotes need quadrupling, octupling, etc (eg > 'he > > > said > > > > > ''she said ''''yes'''', but she lied'', if you can believe that'). > > > > > > > > > > The syntax error in your first example is due to the juxtaposition > of > > two > > > > > nouns, the string '(`' and the number 3 . > > > > > > > > > > -Dan > > > > > > > > > > > > > > > On Feb 11, 2012, at 1:04 PM, "R.E. Boss" <r.e.b...@planet.nl> > wrote: > > > > > > > > > > > If I want to process an arbitrary string, I may encounter a > string > > > > which > > > > > > might give a "syntax error" or an "open quote" message. > > > > > > > > > > > > How can I detect such a situation and how can I repair the given > > > > string? > > > > > > > > > > > > > > > > > > > > > > > > a. i. '(`'3 > > > > > > > > > > > > |syntax error > > > > > > > > > > > > | a. i.'(`'3 > > > > > > > > > > > > > > > > > > > > > > > > a. i. '(`'3' > > > > > > > > > > > > |open quote > > > > > > > > > > > > | a.i.'(`'3' > > > > > > > > > > > > | ^ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > R.E. Boss > > > > > > > > > > > > > > ---------------------------------------------------------------------- > > > > > > 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 > > > > ---------------------------------------------------------------------- > > 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