thank you Dan, enjoyed all the tips. I realized that going from verb or noun to noun is pretty straightforward with u"_ , and it was turning a noun as the basis for a verb that I had not previously done before, and so understandably slightly more hoop jumpy.
One huge benefit of single lines for me, you did not mention, is code file organization (cleaner to find code), and copy paste modifications of code with minor modifications are much easier when the template is a single line. ----- Original Message ----- From: Dan Bron <j...@bron.us> To: programm...@jsoftware.com Cc: Sent: Monday, February 24, 2014 2:41:26 PM Subject: Re: [Jprogramming] best way to write modifier that can have m or u Pascal wrote: > '+: y' (1 : 'if. isNoun ''u'' do. u =. (13 : u) end. u ') 3 > NB. TIL you can add code after 'end.' on same line. The reason you can put 'end.' on the same line is that in an explicit context (i.e. running under : ), 'end.' is considered punctuation, as is any control word. That is, from :'s perspective, a control word actually delimits and defines a line, as much as CRLF (or LF) does. You can see this in action by asking 5!:7 for the lines of an explicit definition: iffy=:1 : 'if. isNoun ''u'' do. u =. (13 : u) end. u ' (<a:;<<1) { (1) 5!:7<'iffy' +-+----------+ |0|if. | +-+----------+ |1|isNoun'u' | +-+----------+ |2|do. | +-+----------+ |3|u=.(13 :u)| +-+----------+ |4|end. | +-+----------+ |5|u | +-+----------+ This is perhaps interesting, but is it useful? Well, there are some circumstances where we'd like to take a large multi-line program and fit it into a single line. Sometimes we want this for technical reasons (e.g. evaluating one-liners through the J IRC bots), sometimes for pedagogical purposes ("Hey, look at what I can do with /one line/ of J code!"), and sometimes because J's syntax asks us to break up a thought we think would be clearest expressed in a single, unbroken line. In short, we'd line a "logical line break" along the same lines and for the same reasons APL has <> and C has ; etc. Puzzle: how can we take advantage of control-words-as-delimiters in order to fit multiple logical lines into a single physical line, without imposing or requiring the user to impose semantic changes to the program? Things to consider: logical lines that produce adverbs and conjunctions (which would either gobble up or choke on separators like [), the interplay of any required arguments to control words (e.g. assert. 1), brevity (we are trying to fit a large thought into a single line here), etc. Solution in: 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 3 : 'smoutput ''just'' label_. smoutput ''use'' label_. smoutput ''an unlabelled'' label_. smoutput ''label'' ' 0 just use an unlabelled label -Dan PS: One other thing you might find surprising: control words can be nested. iffier =: adverb define if. if. noun = nc<'u' do. u=. 13 : u end. 10 > u y do. 'u applied to y is less than 10' else. 'u applied to y is too big' end. ) +: iffier 5 u applied to y is too big -: iffier 5 u applied to y is less than 10 '+: y' iffier 5 u applied to y is too big '-: y' iffier 5 u applied to y is less than 10 ----- Original Message --------------- Subject: [Jprogramming] best way to write modifier that can have m or u From: Pascal Jasmin <godspiral2...@yahoo.ca> Date: Mon, 24 Feb 2014 09:28:54 -0800 (PST) To: "programm...@jsoftware.com" <programm...@jsoftware.com> For some reason, I remember there was an easier way to get an adverb to notice whether it had an m or u parameter, but I can't recall if that was the case, or how to do it. Is there an easier way to write the adverb below? isNoun =: (0 = 4!:0 ( :: 0:))@:< 2 (1 : 'if. isNoun ''u'' do. u else. u y end.') 3 2 +: (1 : 'if. isNoun ''u'' do. u else. u y end.') 3 6 '+: y' (1 : 'if. isNoun ''u'' do. (3 : u) y else. u y end.') 3 6 '+: y' (1 : 'if. isNoun ''u'' do. u =. (13 : u) end. u ') 3 NB. TIL you can add code after 'end.' on same line. 6 ---------------------------------------------------------------------- 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