A question about enlist function

Hi,

I’m currently reading q for Mortals chapter 3, which talks about how to create a single item list. Below is the code:

singleton:enlist 1 2 3

When counting the number of element, it returns 1

count singleton 1

However, when I tried to print out singleton, I got all three element. 

singleton 1 2 3

I don’t understand now. Shouldn’t the list only contain 1?

Thanks!

Jerry

the stringyify for the console tries to make the result more readable.
If you want to see the full underlying structure of the result, use 0N!

e.g.

q)0N!singleton;

,1 2 3

where the , means enlist.

Hi Charles,

I have same question as Jerry. But your comments does not provide much clarification. Can you please elaborate more?

A singlton should have only one element in the list. but we can assign multiple atoms to a singlton list.

I don’t see any difference in the output of multi-element list and singleton.

q)multi:(1 2 3)q)singleton:enlist 1 2 3q)multi1 2 3q)singleton1 2 3

Please clarify. Thanks.

If you’d like a more explicit result, use 0N!

eg

 0N!singleton

Q console does not print the actual structure but format it so that it becomes more readable. To view actual structure, use 0N!

  q) 0N!multi;
  1 2 3    / list of 3 items

q) 0N!singleton;
 , 1 2 3   / comma shows that its  a list with one item which is again a list of 3 items

Ok, now it is a bit clear.

The Borror book isn’t very clear on this but enlist does more than just create a singleton from an atom.  It increases the rank of an atom or a list by one by essentially prepending a 1 to its “shape” vector.

E.g.

enlist enlist 5

creates a simulated 1x1 matrix.

Question:

APL2 has a pretty good DISPLAY function…is 0N! the best tool for displaying the structure of a list in Q?