[Jprogramming] @: and capped fork
Bo Jacoby
bojacoby at yahoo.dk
Sat Dec 1 22:48:38 UTC 2012
Alex, What I had in mind is even more elementary, such as using J for explaining addition and multiplication of nonnegative integers like this.
1 NB. this is a one
1
14#1 NB. this is a list of fourteen ones
1 1 1 1 1 1 1 1 1 1 1 1 1 1
9#2 NB. this is a list of nine twos
2 2 2 2 2 2 2 2 2
(14#1),(9#2) NB. here are the two lists concatenated
1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2
#((14#1),(9#2)) NB. counting the concatenated list
23
plus=. 4 : '#((x#1),(y#2))' NB.make a program 'plus' to count such concatenated lists
14 plus 9 NB. test the program
23
14+9 NB. the same program is provided by the J system in a more efficient version called +
23
3#1 NB. three ones
1 1 1
9#(3#1) NB. nine examples of the three ones
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
#(9#(3#1)) NB. count it
27
times=. 4 : '#(x#(y#1))' NB. make a program 'times'
9 times 3 NB. test the program
27
9*3 NB. the program is provided by the J system in a faster and smaller version called *
27
I see no reason to tell the beginner that some of his parentheses are superfluous. Let him write them until he is familiar with elementary programming and arithmetic.
- Bo
>________________________________
> Fra: Alex Giannakopoulos <aegean at blueyonder.co.uk>
>Til: programming at jsoftware.com
>Sendt: 5:14 lørdag den 1. december 2012
>Emne: Re: [Jprogramming] @: and capped fork
>
>On 30 November 2012 16:17, Bo Jacoby <bojacoby at yahoo.dk> wrote:
>
>> J is a rich language, and it might be a good idea to define an elementary
>> subset for beginners.
>
>
>Couldn't agree more.
>A simple startup configuration file. Define verbs for trig functions so
>they don't look stupidly arbitrary.
>Some other elementary functions too, like polar2rect and rect2polar
>conversions that act on vectors (none of this xfy binary stuff here
>please), you know, stuff like you can find on *calculators*.
>Define dot-product, matrix-multiplication, cross-product, determinant, etc,
>as user-friendly built-in verbs. When I am a beginner, I DO NOT, repeat
>NOT want to know about the . operator at the level of the jdict, it is a
>highly advanced subject, intriguing - yes, but not for newbies. Yet I do
>want to do matrix ops. I was told this was a language for linear algebra.
>It would probably be a good idea, then, if we could do some linalg -
>straight out of the box - without serious brain damage. I have had abuse
>hurled at me by math teachers who have seen J's linalg primitives (LOL).
>Add some nice libs for equation solving while we're at it. Simultaneous
>and also some numeric solvers. This is what people want. A language, not
>an assembler for a language.
>
>
>> J is a nice calculator for elementary computations. You can do a lot of
>> computing without knowing anything about binomial coefficients and taylor
>> expansions and capped forks.
>
>
>Agree with the first two, NO way on the third. Even the 13 verb gives you
>capped verbs, there is no way to begin learning J without it. Also they
>solve the problem of having to figure if you should use At or Atop,
>invaluable for a beginner who hasn;t quite mastered rank yet.
>
>This problem, which once again gives rise to a long thread, could easily be
>solved by a highly visible Programming FAQ page, with lots of links to.
>Deal with capped forks, @ and @: and why you can't have things like +/ a
>b c You know, the questions people *keep asking*. Remove ancient
>irrelevant stuff like the use of x. and y. We are not at J401 any more.
>
>
>> If you need to understand everything in order to be happy, then you may be
>> unhappy. I taught my son elementary APL when he was 10 years old, and he
>> loved it!
>>
>
>Would he have been just as happy at 14 when he had to use the cosine rule
>to solve a triangle? Would he really prefer
>cosrule_getang =: 13 : '_2&o.(((+/*:}.y)-*:{.y) % */ 2, }.y)'
>or
>cosrule_getang =: [: _2&o. (([: +/ [: *: }.) - [: *: {.) % [: */ 2 , }.
>to
>cosrule_getang := (Aa,B,C) -> acos((B^2+C^2-Aa^2)/(2.0*B*C));
>Just wondering...
>
>These are simple enough things to do, and I speak as a J newcomer. There's
>not many languages you can say that about after two and a half years! The
>Zen of J, grasshopper.
>
>Incidentally, is there a way to cap a monadic hook on the left?
>For example (=<.) was mentioned, but obviously it allows dyadic arguments,
>and fails if they are offered.
>Short of wrting monad : 'y=<.y' is there a way I can keep it monadic (and
>implicit)?
>----------------------------------------------------------------------
>For information about J forums see http://www.jsoftware.com/forums.htm
>
>
>
More information about the Programming
mailing list