Gian Medri wrote:
> 
> Hi!
>  I have a function:
> bestfit=:(],0{&<.&<.0.5+(1+0.01*(?30)-15)*(((+/ % #)*1+#)-(+/)))
> that calculates the n+1 element.
> bestfit 90 90 90
> 90 90 90 81
> The tacit form doesn't work properly, because the "?" is not active every
> time I call bestfit 90 90 90.
> When I use
> (],0{&<.&<.0.5+(1+0.01*(?50)-25)*(((+/ % #)*1+#)-(+/))) 90 90 90
>  then the function works properly.
> 
> My question is if it is possible to have a tacit verb with the "?" active.
> 
> Thanks
> 
> Gian Medri
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> 
> 
In J, when you write (f x) in your tacit code definition, J replaces (f x)
with its value.  That's fine as long as verb f is a function,
but since verb ? is not a function, every appearance of (? x) will give
you a different value. 

Simply said, (>:30) in your code would mean: put 31 here, while
(?30) means: put a random number between 0 and 29 here.

Henry's solution to this is to replace (?@30) with (?@(30"_)).
How does this work?

x"_ is a constant function that returns x for any argument(s) given.

Now let's consider the following simple equation:

  f@(x"_) y === f x

Is it true?  Yes, if f is a function, for any noun y and x in the domain 
of f .  Verb ?, however, is not a function, so the Eq. breaks down.
Let's try some examples:

   verb =: >:@(30"_)
   verb 0
31
   verb 0
31
   verb 1
31

It gives us 31 every time as expected according to the Eq.
Now let's try verb ? :

   verb =: ?@(30"_)
   verb 1
0
   verb 1
8
   verb 0
6
   verb 0
16

Output looks random alright.  The problem solved, 
another one exposed. 


-- 
View this message in context: 
http://old.nabble.com/Tacit-vs.-Explicit-tp32595211s24193p32595276.html
Sent from the J Programming mailing list archive at Nabble.com.

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

Reply via email to