What fun!

When I saw this:

    <'Qsc'
┌───┐
│Qsc│
└───┘

and visualized this:

   a
┌─┬─┬─┬──┬─┬──┬─┬───┬───┐
│N│A│Q│GS│G│GM│S│Qsc│AUS│
└─┴─┴─┴──┴─┴──┴─┴───┴───┘
   
The answer just jumped off the page!

   a=<'Qsc'
0 0 0 0 0 0 0 1 0

I enjoyed the time I spent with examples of  E.  and am sure it will come in 
handy in the future. But thanks so much for the wakeup call. I have gotten 
excited about J in the last few months and maybe you'll also find it fun to 
scramble some of your ways of thinking about APL to match what is possible 
using  J  .

Thanks again.  I knew there was an easier way!

Linda


-----Original Message-----
From: programming-boun...@jsoftware.com 
[mailto:programming-boun...@jsoftware.com] On Behalf Of Simon Barker
Sent: Thursday, March 29, 2012 10:26 AM
To: 'Programming forum'
Subject: Re: [Jprogramming] one element list of an integer to an atom

Hi Linda,

Despite having followed these forums for several years I still can't read J 
very well, mainly because I don't actually use it that often, but if I 
understand what you are trying to do, does this fit the bill:

   a E.~ <'Qsc'
0 0 0 0 0 0 0 1 0
   a E.~ <'N'
1 0 0 0 0 0 0 0 0

Simon

-----Original Message-----
From: programming-boun...@jsoftware.com
[mailto:programming-boun...@jsoftware.com] On Behalf Of Linda Alvord
Sent: 29 March 2012 15:01
To: 'Programming forum'
Subject: Re: [Jprogramming] one element list of an integer to an atom

Here's how I came upon the problem.

   a=:'N';'A';'Q';'GS';'G';'GM';'S';'Qsc';'AUS'
   f=: 13 :'>"0,L:0 y'
   d=: 13 :'(''''$,}.$f y)=+/"1 ((}.$f y){.>x)="1 f y'
   'Qsc' d a
0 0 0 0 0 0 0 1 0
   'N' d a
1 0 0 0 0 0 0 0 0
   a
--T-T-T--T-T--T-T---T---¬
¦N¦A¦Q¦GS¦G¦GM¦S¦Qsc¦AUS¦
L-+-+-+--+-+--+-+---+----

Surely, this can be improved upon.

Linda

-----Original Message-----
From: programming-boun...@jsoftware.com
[mailto:programming-boun...@jsoftware.com] On Behalf Of Linda Alvord
Sent: Thursday, March 29, 2012 9:24 AM
To: 'Programming forum'
Subject: Re: [Jprogramming] one element list of an integer to an atom

Here's a summary of all your good ideas:

   ]a=:1$3
3
   ]b=:1 1 1 1$3
3
   (0{,b)=2 3 4 3 6
0 1 0 1 0
   ({.,b)=2 3 4 3 6
0 1 0 1 0
   (,/b)=2 3 4 3 6
|length error
|   (,/b)    =2 3 4 3 6
   (,/a)=2 3 4 3 6      
0 1 0 1 0
   ]a=:1$3
3
   ]b=:1 1 1 1$3
3
   (0{,b)=2 3 4 3 6
0 1 0 1 0
   ({.,b)=2 3 4 3 6
0 1 0 1 0
   (,/b)=2 3 4 3 6
|length error
|   (,/b)    =2 3 4 3 6
   (,/a)=2 3 4 3 6
0 1 0 1 0
   ''$,b
3

Thanks to everyone! All work for one element list. Some are more versatile than 
that.  I had remembered only  $,  from APL, but couldn't make it work because 
it doesn't. I guess special code  ''$,b  is the way to go.  Do you agree.


Linda

-----Original Message-----
From: programming-boun...@jsoftware.com
[mailto:programming-boun...@jsoftware.com] On Behalf Of Simon Barker
Sent: Thursday, March 29, 2012 6:47 AM
To: 'Programming forum'
Subject: Re: [Jprogramming] one element list of an integer to an atom

The old APL idiom was

        '' {reshape} data

which translates as

        '' $ , data

In J.

-----Original Message-----
From: programming-boun...@jsoftware.com
[mailto:programming-boun...@jsoftware.com] On Behalf Of Linda Alvord
Sent: 29 March 2012 09:20
To: 'Programming forum'
Subject: [Jprogramming] one element list of an integer to an atom

   a=:1$3
   a
3
   3= 2 3 5 3 4
0 1 0 1 0
   a= 2 3 5 3 4
|length error
|   a    =2 3 5 3 4
   
   ".a
|domain error
|       ".a
   a+5
8

Clearly, a is numeric. How can I change  a  to a numeric atom  3 , rather than 
a one element list  3 ?

I need to find where the 3's are in a list. The result of executing some 
expression has produced a one item list of a  3 .

I think I may have known how in APL once upon a time.

Linda 

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

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