On 5/19/07, Terrence Brannon <[EMAIL PROTECTED]> wrote:
rec_case  =: fib (] - 1) ( + ( fib (] - 2) ) )

the rec_case is where I am failing.

Your rec_case has a couple problems:

  rec_case  =: fib (] - 1) ( + ( fib (] - 2) ) )

When I type the body of this definition into a J session where fib
has not been defined, I get:

  fib (] - 1) ( + ( fib (] - 2) ) )
|value error: fib
|   fib(]-1)(+(    fib(]-2)))

Why?  Well, the parenthesized expression
  (] - 2)
evaluates as:
_2
Likewise
  (] - 1)
_1

So your above expression is equivalent to:
  fib _1 (+ (fib _2))

So, evaluating right to left, the first thing J is going to try to do
with your expression is find
  fib _2
which, of course, is not what you want.

Note also that if you got past this point, you would then add 1 to
the result of fib _2 and then use fib on that value.  So, even if you
were subtracting from your right argument, you would need another
set of parenthesis around the left most fib to make things come out
right.

Put differently, you need to be careful in how you apply your
parenthesis -- the value inside parenthesis will be completely
evaluated and the resulting object (noun, verb, adjective or
conjunction) will be used in the place where the parenthesis appear.

Also, if you are trying to create tacit verbs, but are not familiar
with the rules, I highly recommend you try working with 13 :''

  13 :'(fib y-1) + (fib y-2)'
([: fib 1 -~ ]) + [: fib 2 -~ ]

This lets you use normal expression syntax and (with x as a dummy
variable for your left arg, and y as a dummy variable for your right arg)
and find an equivalent tacit form.  Of course, if there isn't one you
won't get a tacit result.  For example, try:
  13 :'(((((this has syntax problems'

That said, this is just a starting point.  For example, the above
is equivalent to
  (1 -~]) +&fib 2-~]
and could also be expressed as
  -&1 +&fib -&2

(but note that & has two different meanings here -- in this last sentence,
there are two instances of the 'bond' meaning, and one instance of the
'compose' meaning.)

Also note that the dictionary page on power has another relatively
simple inductive approach for defining a fibonacci function, and the
Fibonacci Sequence wiki page has a version of this function almost
exactly like what you asked for above (it uses $: for recursion rather
than a name, and uses ^: instead of @. but the recursive case looks
rather like my last j sentence, above).

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

Reply via email to