On 5/23/07, Terrence Brannon <[EMAIL PROTECTED]> wrote:
but then I immediately hit a problem.
c=. '(' , [ , ')' ,~ ]
  'a' c 'b' c 'c'
(a(bc))

That was all well and good, but I wanted a more "pictorial" way to form the
string, so I tried to move the "]" inside the parenthesis, since that is what c
does... 'b' c 'c' creates (bc) and so I wanted the verb to look the same way 
too.
So I tried:
c=. '(' , [ , ] , ')'
but I got a syntax error when I tried to run it.

I think your problem here is more visual than anything else.  Your first
definition of c is a verb, built up as a train of nouns and verbs.  Your
syntax error definition of c has a noun for the right-most word.  That
means that you're either defining a noun or generating a syntax error.

J will automatically promote nouns to (constant) verbs when they appear
as the leftmost tine of a train, but if you want a constant noun as the
rightmost tine of a train, you need to do this manually.  In this case:
  c=. '(', [ , ] , ')'"_

Or, since [,] is , (and since the lone comma would be in an odd
position in a fork train) more concisely:
  c=. '(', , , ')'"_

Another thing you might try, to better understand this, would be
to take your original sentence, and start throwing things out:

    'a' c 'b' c 'c'
(a(bc))
  'b' c 'c'
(bc)
  'b' ('(' , [ , ')' ,~ ]) 'c'
(bc)
  'b' ([ , ')' ,~ ]) 'c'
bc)
  'b' (')' ,~ ]) 'c'
c)

Now compare:

  ')' ,~ ]
')' ,~ ]
  ] , ')'
)

Notice how the first of these last two expressions is a verb, while the
other is a noun?   This follows through so that when you define:

c=. '(' , [ , ] , ')'

c is a noun (look at its definition).  So when you try using it as a
verb, you get a syntax error.

So why is it that [ , 'c)' will work but my attempt to have
] , ')' work will not?

I hope I've explained this well enough?

Thanks,

--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to