epic post you linked to. Thank you. This was new to me: > You'd also be surprised how often 1=*/'' helps you out, either directly or >indirectly (the phrase means that the product of an empty list is 1, because 1 >is the identity element of *
on coerce, I'm using it for functions that normally expect boxed data, but if provided a scalar will go retrieve that data. I like spelling out coerce over ^: (or my original) due to ^: being able to do so many things. It adds legibility and intent to use the named version. (a 0 or 1 condition, and coerceif). coerceif is probably a better name for it. The ^: definition is great, though I liked (without having a concrete use case) the idea of passing it a gerund. Your */'' trick ties into another bit of code that I like in shaping function input. defaults =: ([`]@.(0=#@>@[))"0 0 NB. will work without checking for length errors (a:,;/2 3) defaults 1 2; 3; 4 ┌───┬─┬─┐ │1 2│2│3│ └───┴─┴─┘ and used within functions as: 'a b c' =. y defaults 1 2; 3; 4 (from this essay: http://www.jsoftware.com/jwiki/PascalJasmin/J%20tricks%20with%20assign) defaults only works with boxed input, and my attempts at a more comprehensive version seemed too wordy. is there a function that returns true if its entire input is '', i.0, or true if any of its boxed parameters is a: ? The workaround that seemed good enough so far is to just always call with a: if the input parameter is optional, and unbox if preferred. ----- Original Message ----- From: Dan Bron <[email protected]> To: [email protected] Cc: Sent: Monday, October 7, 2013 8:33:43 PM Subject: Re: [Jprogramming] How to make this conjunction tacit Pascal wrote: > something a little silly with the original coerce definition is: > <`> coerce (1-L.) <<2 > +-+ > |2| > +-+ > or > <`>`(>@>)`> coerce (1-L.) <<<2 > +-+ > |2| > +-+ This is J. You don't need silly tricks. You only need algebra: coerce =: ^: < coerce (1-L.) <<2 +-+ |2| +-+ < coerce (1-L.) <<<2 +-+ |2| +-+ < coerce (1-L.) <^:100] 2 NB. Try writing that using @. +-+ |2| +-+ I'll have to think more about your "super conjunction" idea before I can comment. -Dan PS: For more on the power of coercion and the elegance of J's algebra, scroll to about the middle of the message below, starting at "Or, have you seen the power operator?". http://www.jsoftware.com/pipermail/programming/2009-November/017042.html ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
