[Jprogramming] @: and capped fork
km
km at math.uh.edu
Sat Dec 1 05:43:19 UTC 2012
(1) You could also have done
isint =: [: (= >.) ] NB. ignores left argument if given
isint 2 0.5
1 0
13 isint 2 0.5
1 0
(2) Check out the monad/dyad "core" lab. The following is from the iPad version of J.
Hlab NB. Help for labs
labs are interactive tutorials
manage labs with the following sentences:
jx '' NB. category list
jx 'core' NB. labs in category core
jx 0 NB. open lab 0
jx -1 NB. close lab
↵ with empty textfield advances lab
jx 'core'
0 A J Introduction
1 A Taste of J (1)
2 A Taste of J (2)
3 An Idiosyncratic Introduction to J
4 An Introductory Course in J
5 Function Display
6 Locales
7 Monad/Dyad
8 Object Oriented Programming
9 Sparse Arrays
jx 7
-------------------------------------------------------------
Lab: Monad/Dyad
To advance the lab, press ↵
-- (1 of 4) INTRODUCTION ------------------------------------
If u and v are functions, then f=: u : v defines f to be a
function whose monadic case is u and whose dyadic case is v
For example, if v=: +, then 3 v 4 is 7 and v 4 is 4, i.e.
since the monadic case of + is the conjugate, which produces
an effect only on a complex argument such as 6j10.
We may, however, define a function add that performs addition
on two arguments, and increments a single argument. Thus:
)
add=: >: : +
3 add 4
7
add 4
5
add 4 5 6 7 8
5 6 7 8 9
v=: +
3 v 4
7
v 4
4
(3) The use of Cap [: is explained in this four-step lab.
Kip Murray
Sent from my iPad
On Nov 30, 2012, at 10:41 PM, Alex Giannakopoulos <aegean at blueyonder.co.uk> wrote:
> Hm, yes, I hadn't realised both cases could be specified implicitly, that's
> really useful.
> Another one for the FAQ!
>
> On 1 December 2012 04:37, Alex Giannakopoulos <aegean at blueyonder.co.uk>wrote:
>
>> Great, thanks, hadn't seen that technique before!
>>
>>
>> On 1 December 2012 04:35, km <km at math.uh.edu> wrote:
>>
>>> About your closing question, you can do
>>>
>>> isint =: (= <.) : [:
>>> isint 2 0.5
>>> 1 0
>>> 2 isint 3
>>> |domain error: isint
>>> | 2 isint 3
>>>
>>>
>>> The definition of isint specifies [: as the dyadic case, and [; rejects
>>> every argument with a domain error.
>>>
>>> Kip Murray
>>>
>>> Sent from my iPad
>>>
>>>
>>> On Nov 30, 2012, at 10:14 PM, Alex Giannakopoulos <
>>> aegean at blueyonder.co.uk> wrote:
>>>
>>>> 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
>>> ----------------------------------------------------------------------
>>> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list