Hi John,

Here is my take on your situation:

anmatch=: 4 : 0
NB. I usually reassign parameters so I dont modify them
NB. accidentally
bal=. x
values=. y

NB. Use this style of definition so that you wont have 
NB. the extra box. Also notice that this is a local
NB. variable. Good programming practice.
countmatches=. 0 $ a:

NB. Loop through values
for_a. values do. 
  countmatches=. countmatches,(<( {: /:>(+/ each a e. each x)))
end.

NB. the value of the last operation is the return value
NB. so you dont actually need this but is good programming practice.
countmatches
)

Actually, you can make a tacit definition for this but this is more
"readable". 

r/Alex

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Mike Day
Sent: Friday, August 29, 2008 3:59 PM
To: Programming forum
Subject: Re: [Jprogramming] Create Dyad ?

John

Let's try again, with line-throws this time.  I forgot Thunderbird (or
something) messes up my J copies. Sorry!

annmatch=: 3 : 0 

NB. this default monad call assumes existence a global bals 

bals annmatch y 

NB. following colon ":" separates monad & dyad sections
:   

 NB. this is the start of the dyadic section 
 NB. next line uses the x input/argument

bals =. x

countmatches=: a:     NB. you could keep this local by the alternative  
(next line)

NB. countmatches=. a: NB. ... unless you need the array after return

NB. rest as before

)

Alternatively, you can create the dyad with 4 : 0 (or dyad : 0) as
follows:

annmatch=: 4 : 0

NB. don't include the single colon ":"

NB. next line uses the x input/argument

bals =. x

NB. the rest as before

)

Mike Day wrote:
> John
>
>    3 : 0 (or indeed monad : 0) defines a monad by default,
> but may be used to create both; try for example
>
> ... [see layout in new post above]
I expect you'll get many other helpful replies once they wake up 
stateside (and elsewhere!)
>
> Mike
>
>
> Saunders, John (HEALTH) wrote:
>> Hi guys I have the below verb annmatch and would like to make it a
dyad
>> the noun bals is what I want to replace with an X value so I can make
>> this more flexible and not tied to bals ; just not exactly sure how
to
>> go about it ; hope I'm making sense and using the appropriate
j-language
>> here.
>>
>> Any direction would be appreciated
>> annmatch=: 3 : 0 countmatches=: a:
>> for_a.
>>   y
>> do. countmatches=: countmatches,(<( {: /:>(+/ each a e. each bals)))
>> end.
>> }.countmatches
>> )
>>
>> thanks
>> John
>>
>>
>> -----Original Message-----
>> From: [EMAIL PROTECTED]
>> [mailto:[EMAIL PROTECTED] On Behalf Of
>> [EMAIL PROTECTED]
>> Sent: Thursday, 28 August 2008 1:30 PM
>> To: [email protected]
>> Subject: Programming Digest, Vol 35, Issue 59
>>
>> Send Programming mailing list submissions to
>>     [email protected]
>>
>> To subscribe or unsubscribe via the World Wide Web, visit
>>     http://www.jsoftware.com/cgi-bin/mailman/listinfo/programming
>> or, via email, send a message with subject or body 'help' to
>>     [EMAIL PROTECTED]
>>
>> You can reach the person managing the list at
>>     [EMAIL PROTECTED]
>>
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of Programming digest..."
>>
----------------------------------------------------------------------
>> For information about J forums see
http://www.jsoftware.com/forums.htm
>>
>> No virus found in this incoming message.
>> Checked by AVG - http://www.avg.com Version: 8.0.138 / Virus 
>> Database: 270.6.9/1637 - Release Date: 27/08/2008 07:01
>>
>>
>>
>> No virus found in this incoming message.
>> Checked by AVG - http://www.avg.com Version: 8.0.138 / Virus 
>> Database: 270.6.9/1637 - Release Date: 27/08/2008 07:01
>>
>>
>>
>>   
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> No virus found in this incoming message.
> Checked by AVG - http://www.avg.com Version: 8.0.138 / Virus Database:

> 270.6.12/1640 - Release Date: 28/08/2008 18:58
>
>
>
> No virus found in this incoming message.
> Checked by AVG - http://www.avg.com Version: 8.0.138 / Virus Database:

> 270.6.12/1640 - Release Date: 28/08/2008 18:58
>
>
>

----------------------------------------------------------------------
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