Tracy Harms wrote: > It fails when the atoms > are symbols, presumably > because empty values are > handled differently
Nah, that was just a typo. I wrote. s:'' but it should've been. s:' ' (or. s:a: etc). -Dan Sent from my Verizon Wireless BlackBerry -----Original Message----- From: Tracy Harms <[email protected]> Date: Wed, 21 Oct 2009 10:37:28 To: Programming forum<[email protected]> Subject: Re: [Jprogramming] Noun type assessment Dan, It was interesting to see your attempt to solve this without resort to External. The code you provided almost works. It fails when the atoms are symbols, presumably because empty values are handled differently in order to allow all empty nouns to serve equivalently. As for your question -- "why?" -- I'm toying with writing an equivalent to the || of JavaScript. A couple of things prevent the equivalency from being particularly close, most important of which is that || is not a function. >From the blog post which brought || to my attention: "Logical operators that return values, instead of simply booleans, are more expressive and powerful, although at first they may not seem useful — especially coming from a language without them." The logical operators in J are not limited to boolean results, so there's some natural accord from the J perspective. There's discord, too: I reject the idea that || is well thought of as a logical operator. I do, however, follow the conveniences of its function, so I'm exploring it in J. Here's my first pass: or =: ( 0((e.$) +. (=+/))[ ) >@{ [ ,&< ] UserName=:'' NB. for example... UserName or 'Default Name' Default Name This fails, however, when the left parameter is something other than numeric or null. The disadvantage I see to this approach is that it opens up a new question as to what shall count as "false". Iverson's solution (false is zero) has advantages of simplicity and ready numeric application. The JavaScript idea seems to be that the logical opposite of true is any of the following: (1) false (2) zero (3) empty (4) undefined. (Caveat lector; I'm not studied in JavaScript.) If that problem is tamed, though, the typical meaning of JavaScript's || might be useful. In J terms that meaning is "verb returning left argument, unless left argument is 'false' in which case return right argument." Because of the "flow" of J it may turn out to be more natural to reflect the arguments. I've kept their order with the left-to-right bias of JavaScript for this post, but I'm not convinced it would be best in J. Tracy On Wed, Oct 21, 2009 at 9:06 AM, <[email protected]> wrote: > Something like (very untested, written on phone at trade show) > > nt=.(;:'num char sym box other') {~ (0;' ';(s:'');<a:) i. <@:{.@:(0 $ ,)) > > .... But the question is: why? Your verbs should have defined domains (ie > know and expect a certain type, or not care). Unless you're doing some > reflecting. > > -Dan > > > Sent from my Verizon Wireless BlackBerry > > -----Original Message----- > From: Tracy Harms <[email protected]> > Date: Wed, 21 Oct 2009 08:51:15 > To: Programming forum<[email protected]> > Subject: [Jprogramming] Noun type assessment > > Off the top of my head, I don't know of a way other than 3!:0 by which > to determine whether I'm working with an array of numeric, literal, or > box atoms. My sense of "internal" vs "external" considerations has me > thinking that this quality is "inside" what J primaries naturally > involve, as opposed to implementation details that count as external > (and thus call for !: ) > > Is there a better way for me to distinguish among the major types of > atoms? If 3!:0 is the best way, is there an explanation as to why > examining atomic type is considered an external task, not a primary > one? > > Thank you, > > Tracy > ---------------------------------------------------------------------- > 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
