iota question

This is a discussion on iota question within the APL forums in Programming Languages category; Hello, The dyadic iota can be used to find the position of an element in an array. This seems to work well if the array contains numbers or letter. But what if the array contains a word in each element? The iota doesn't seem to be able to tell me the index of the word in the array. Am I missing something? Also, how can I figure out all the positions of a repeated element in the array? Thank you. -pete...

Go Back   Application Development Forum > Programming Languages > APL

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 10-04-2008, 10:07 PM
Peter Keller
Guest
 
Default iota question

Hello,

The dyadic iota can be used to find the position of an element in an array.

This seems to work well if the array contains numbers or letter. But what
if the array contains a word in each element? The iota doesn't seem
to be able to tell me the index of the word in the array.

Am I missing something?

Also, how can I figure out all the positions of a repeated element in the
array?

Thank you.

-pete
Reply With Quote
  #2  
Old 10-05-2008, 03:58 AM
Jan Karman
Guest
 
Default Re: iota question


"Peter Keller" <psilord@merlin.cs.wisc.edu> wrote in message
news:48e82165$0$9895$80265adb@spool.cs.wisc.edu...
> Hello,
>
> The dyadic iota can be used to find the position of an element in an
> array.
>
> This seems to work well if the array contains numbers or letter. But
> what
> if the array contains a word in each element? The iota doesn't seem
> to be able to tell me the index of the word in the array.
>
> Am I missing something?
>
> Also, how can I figure out all the positions of a repeated element in
> the
> array?


In Dyalog 8.2.2 :
a)
'cat' 'dog' {iota} {enclose} 'dog'
2
nb. {enclose} is needed, otherwise the interpreter reads it as "d o g"

and
'cat' 'dog' 'bird' 'mouse' {iota} 'mouse' 'bird'
4 3
nb. no {enclose} is needed here

if not there it gives "outside" the array, i.e. 1+{rho}
'cat' 'dog' {iota} {enclose} 'mouse'
3


b)
iota gives you only the first occurence in an array
'cat' 'dog' 'dog {iota} {enclose} 'dog'
2
a user defined function is needed to get them all
as well as with normal searching for strings in plain text

'cat' 'dog' 'dog' {member} {enclose} 'dog'
0 1 1

you 'll find the positions by shape, enumerate and reduce:
0 1 1 / {iota}{rho} 'cat' 'dog' 'dog'
2 3

in general: (array {member} value) / {iota}{rho} array

this is what you'll get with {equal}
'cat' 'dog' 'dog' = {enclose} 'dog'
0 0 0 1 1 1 1 1 1

a strong desire and a long breath is indispensible,
but it definitely pays off ...

^/jk






Reply With Quote
  #3  
Old 10-05-2008, 04:08 AM
Jan Karman
Guest
 
Default Re: iota question


"Jan Karman" <aqxqy@planet.nl (remove the q's)> wrote in message
news:48e873fa$0$27217$ba620dc5@text.nova.planet.nl ...
>
> "Peter Keller" <psilord@merlin.cs.wisc.edu> wrote in message
> news:48e82165$0$9895$80265adb@spool.cs.wisc.edu...
>> Hello,
>>
>> The dyadic iota can be used to find the position of an element in an
>> array.
>>
>> This seems to work well if the array contains numbers or letter. But
>> what
>> if the array contains a word in each element? The iota doesn't seem
>> to be able to tell me the index of the word in the array.
>>
>> Am I missing something?
>>
>> Also, how can I figure out all the positions of a repeated element in
>> the
>> array?

>
> In Dyalog 8.2.2 :
> a)
> 'cat' 'dog' {iota} {enclose} 'dog'
> 2


[...]
>
> b)
> iota gives you only the first occurence in an array
> 'cat' 'dog' 'dog {iota} {enclose} 'dog'
> 2
> a user defined function is needed to get them all
> as well as with normal searching for strings in plain text
>

[...]

Peter,
actually it's being called "idiom" and "utility functions"
which are "user defined"


Reply With Quote
  #4  
Old 10-05-2008, 12:15 PM
Peter Keller
Guest
 
Default Re: iota question

Thanks much! That is exactly what I needed.

-pete
Reply With Quote
  #5  
Old 10-06-2008, 08:41 AM
Jan Karman
Guest
 
Default Re: iota question


"Peter Keller" <psilord@merlin.cs.wisc.edu> wrote in message
news:48e8e821$0$9895$80265adb@spool.cs.wisc.edu...
> Thanks much! That is exactly what I needed.
>
> -pete


A useful LOOKUP utility is:

Z {gets} (R,L~R) {iota} L

e.g. for updating files

a (from e.g. 10 ? 10{rho} 100)
87 45 11 98 25 86 45 3 24 69
86 46 LOOKUP a
6 11



Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 10:44 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.