possibly something simpler to start. The square root by Newton's method is good and another is finding the root mean square as discussed in this forum in the past. One can't hit those that are unfamiliar with J with a long line of pure tacit code.

initially one could define

root=:%:
square=:*:
mean=: +/ % #   which  is a fork using primitives
define: a=: 1 o. o.0.01 *i.200
plot a and then execute root mean square a
or put it as a one line explicit program
and introduce tacit variations of this as in the following script (the first is the fixed version of an explicit one liner which puts in the caps. to get rms1

rms1=:[:%: [:(+/%#) *:  NB. [:root ([; mean square)
rms2=:%: @:(+/%#)@:%:   NB. root after mean after square
rms3=:(+/%#)&.:*:  NB. inverse square of mean square  u&:v is vinverse u v

For lottery fans 6?49 or 6?49 49 49
a sort program  a{/:a replaces a lot of code

Don




On 17/01/2014 9:01 AM, Devon McCormick wrote:
Thanks for the tips.

I will attempt to emphasize the practical values of 1) being able to hold
an entire solution in one's head
  at once, and 2) time-to-completion as a good metric of efficiency, not
"how quickly code runs".

For the parens example, I'm thinking of showing it something like this:

    phrase=. '0{11{22{333}222}1}0'
    +/\ 1 _1 0 {~ '{}' i. phrase

Then backing up  to explain successive sub-expressions in order of
evaluation.  I may further elaborate by assigning the verb to a name and
generalizing this to take a left argument of the paren pair to use.  This
will allow me to introduce the tacit/explicit distinction as well.

I think my basic problem is to avoid trying to cover too much, so I'm now
thinking of showing a few other variants of scan, then maybe "cut" or the
"power" conjunction.



On Fri, Jan 17, 2014 at 11:24 AM, Roger Hui <[email protected]>wrote:

Suggestion:  Make more of a distinction between the data and the code.
  Thus:

x=: '@{ foo; if (abc) { if (q) { m; } } }'

+/\ 1 _1 0 {~ '{}' i. x





On Fri, Jan 17, 2014 at 7:50 AM, Joe Bogner <[email protected]> wrote:

If it's helpful for the presentation, I wrote up how the parentheses
nesting idiom looks in a few other languages:

There are two relevant concepts - the array thinking and the
implementation
J
+/\(1 _1 0){~'{}' i. '@{ foo; if (abc) { if (q) { m; } } }'
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 3 3 3 3 3 2 2 1 1 0

Javascript
var runsum=0;'@{ foo; if (abc) { if (q) { m; } }
}'.split('').map(function(x) { var opp={'{':1,'}':-1}; return
opp[x]||0;  }).map(function(x) { runsum = x+runsum; return runsum; })
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2,
2, 2, 2, 3, 3, 3, 3, 3, 2, 2, 1, 1, 0

PicoLisp
(reverse (mapcon '((X) (list (apply + X))) (reverse (mapcar '((X)
(cond ((= X "{") 1) ((= X "}") -1) (T 0))) (chop "@{ foo; if (abc) {
if (q) { m; } } }")) ) ))
(0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 3 3 3 3 3 2 2 1 1 0)



http://csilo.com/!article?2014/01/15/J-vs-Javascript-vs-PicoLisp-short-comparison
On Fri, Jan 17, 2014 at 10:41 AM, Devon McCormick <[email protected]>
wrote:
I'll be talking on J to a meetup here in New York this coming Tuesday -
http://www.meetup.com/7-Languages-in-7-Months-NYC/ - so I've been
watching
the "fork examples" discussion w/some interest.

I did a dry run of my talk at NYCJUG this past Tuesday and, at that
time, I
was looking to build up to a final, mind-blowing example like the
Newton-Raphson iterator, but now am thinking that that's too "tricky"
and
what I'd really like to do is go into detail on some simpler examples.
  Joe
Bogner's interest in the parenthesis-nesting idiom reminded me of how
innovative the array approach still is, so I'm definitely using that
one.
David Lambert, who was at the NYCJUG meeting has also given me a couple
of
good ideas since then but I'm interested in anyone else's favorite J
idiom
- "Jems" as Dan would have it - that illustrate the usefulness of array
thinking.

Thanks,

Devon
--
Devon McCormick, CFA
----------------------------------------------------------------------
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

Reply via email to