---Alex Rufon wrote:
> I have to admit that I'm new to this type of programming with J so
> please be patient with my questions.
> 1. I initially tried doing a tacit definition of
>    cmp0=: I. 0 =
> |syntax error
> |   cmp0=:    I.0=
> So why does the following script not fail anymore (although it doesn't
> work)?
>    cmp0=: I. 0 =,

The tacit:
   x (I. 0 =) y
Is the same as explicit:
   (x I. y) 0 (x = y)
Which you will recognise as a syntax error.

The tacit
   x (I. 0 = ,) y
Is parsed as a 2-verb hook
   x (I. (0 = ,)) y
The first verb (0 = ,) is a noun followed by 2 verbs and so (according to the 
dictionary page you quote below) is equivalent to (0"_ = ,) so we have:
   x (I. (0"_ = ,)) y
Which is the same as the explicit
    x I. (0"_ y) = (, y)
0"_ is a verb that will return 0 for any x & y. So this is the same as:
    x I. 0 = , y

Not what you want!

> 2. M is 2 dimension matrix. The result of ([: I. 0 = ,@]) is 6 and 8.
> The code proceeded to amend the data as if it was a vector!!! If I try
> to do that manually, I'll get errors. Why?

This is due to the different forms of amend  m}  and  u} where m is a noun and 
u is a verb.

The Learning J chapter I referenced explains this in more detail.

> 3. This is the first time I use [: symbol. I looked it up in the help
> file and my brains threw a breaker after reading this :
> "For example, 5(+*-)3 is (5+3)*(5-3). If f is a cap ([:) the capped
> branch simplifies the forks to g h y and g x h y . The train N g h (a
> noun followed by two verbs) is equivalent to N"_ g h . The
> ranks of the
> hook and fork are infinite."
> I would appreciate it if somebody can provide a better explanation ...
> please. :)

The key bit here is "If f is a cap ([:) the capped branch simplifies the forks 
to g h y and g x h y"
This is saying that if you have the following tacit
   ([: g h) y    NB. g and h are verbs
It is the same as the explicit
    g h y
And
   x ([: g h) y
Is the same as
   g x h y

The tacit expression:
  x ([: I. 0 = ,@]) y
Is the same as
    I. x (0 = ,@]) y
Which is equivalent to
    I. 0 = x ,@] y
And x [EMAIL PROTECTED] y is the same as: f x g y    so we can rewrite as:
    I. 0 = , x ] y
And x ] y is just y, leaving us with:
    I. 0 = , y

You might want to check out this wiki page:
http://www.jsoftware.com/jwiki/Guides/Reading_Tacit_Verbs
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to