Because the language is so rich with powerful verbs, you will often work
hard to  achieve a result as you did here. Later you learn that it is  an
important enough that it already exists in J and is ready to use like
factorial.

   !5
120

Don't let this bother you. As you learn to define ideas yourself you will
become better at using  these handy verbs when you need them.   

You don't learn a foreign language by memorizing the dictionary. You study a
single word when you need it. Along the way you begin to understand how to
make more and more complex sentences.

Linda
 
 
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of bob
therriault
Sent: Friday, November 16, 2012 12:56 AM
To: [email protected]
Subject: Re: [Jprogramming] Verb definition + inadvertent train formation.

Hey Vijay,

Nothing wrong with a novice question, especially when it is so clearly
phrased.

Take a look at these examples and see if this gives you some ideas.

fact1=: */@:>:@:i.
   fact1 5
120
   fact2=: [:*/>:@:i.
   fact2 5
120
   fact3=: [:*/[:>:i.
   fact3 5
120

You want to have the verbs act sequentially on the argument and your
original definition is a fork which has the outside verbs act on the
argument and then send the results to the left and the right of the centre
verb.
(v1 v2 v3) y is actually ((v1 y) v2 (v3 y)). In this case (*/ >: i.) 5
becomes ((*/ 5) >: (i. 5)) and then (5 >: 0 1 2 3 4) which becomes 1 1 1 1 1

A  good reference link would be
http://www.jsoftware.com/jwiki/Guides/Language%20FAQ#Guides.2FLanguage_FAQ.2
FSentence_Train.Why_.2B-.2F_.2A:_a_works.2C_but_when_I_say_foo_.3D:_.2B-.2F_
.2A:.2C_foo_a_doesn.27t_work.3F

Hope this helps. There is a lot to this language, even when you have been
playing with it for a while, so keep at it.

Cheers, bob

On 2012-11-15, at 9:20 PM, Vijay Lulla wrote:

> Please forgive me for asking a novice question.
> 
> I tried
> */>:i.5   NB. results in 120
> 
> But I define
> fact=: */>:i.
> fact 5  NB. results in 1 1 1 1 1
> 
> I remember reading about this somewhere but I cannot seem to find the 
> relevant pages now. Any pointers as to where I could find these 
> documents or a brief explanation (which can be easily remembered) will 
> be very helpful and is highly appreciated.
> Thanks,
> Vijay Lulla.
> ----------------------------------------------------------------------
> 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

Reply via email to