## Is polymorphism supported in q?

While q has no notion of inheritance, class, metaclass, or prototype, you can create structures packaged with associated functions and invoke those functions via the structures. Consider the following tired OO example expressed in q:

Draw: {[shape] shape[`draw] shape}

(Sadly, we cannot write shape.draw shape; dot notation is not supported for local variables, including arguments.)

Given an appropriate set of constructors –

NewRectangle: {[x; y; w; h] `x`y`w`h`draw ! (x; y; w; h; {[rect] …})}

etc, the following does exactly what you would expect:

```shapes: (NewCircle[0; 0; 1];
NewRectangle[-1; -2; 4; 2]);
Draw each shapes;
```

## How can I glue two tables side by side?

If the tables have the same number of rows, you can use the function ^ (fill):

q)t: ([] x: `a`b; y: 1 2)
q)u: ([] z: “YN”)
q)t ^ u / works only when count[t] = count[u] x y z
—–
a 1 Y
b 2 N
q)

## How do I sort?

q)asc 3 5 2 0 1
`s#0 1 2 3 5
q)desc 3 5 2 0 1
5 3 2 1 0
q)

Notice that, in the case of asc, q attaches the `s attribute to the result. (There is no corresponding attribute for a descending sort.)

As an aside, you may be surprised to discover that calling asc on an attribute-free list that happens to be in sorted order will have the `s attribute applied to it as a side effect:

q)list: til 1000
q)attr list
`
q)asc list
`s#0 1 2 3 4 5 6 7 8 9 10 ..
q)list
`s#0 1 2 3 4 5 6 7 8 9 10 ..
q)

Also take a look at iasc and idesc.

Finally, to sort a table instead of a list, see xasc and xdesc. Read more about sorting tables from this faq