diff between ! and $ for enums

I dont understand the difference between ! and $ for enums . Can someone explain ? Wiki is too terse :-(

Hi,

Can you post an example code snippet of what you’re not understanding?

Kind regards,
Matt

$ is used to create an enumerated list e.g.

q)l:100?abcd

q)l

aacbcbcdcb`a..

q)x:distinct l

q)`x$l

x$aacbcbcdc`..


On the left, there is a variable name (as a symbol) containing all the unique elements of the list to be enumerated. The result is enumerated (as indicated by the `x$ at the start - if you were to store this result, and then change the values in x, the values in the stored enumerated vector would change).


! is used to reconstruct a list from enumerated indices and a list of the unique symbols e.g. (using variable x from above)

q)`x!1 2 3 2 1 3

x$cbdbc`d

Another operator worth noting here is ?. This allows you to enumerate a list against a variable without first assigning all unique elements to the variable e.g.

q)y:() / y is an empty variable

q)`y?l

y$aacbcbcdc`..

q)y

acbd


As with $, the left operand is a variable to enumerate against, however in this case it does not need to already contain the elements from the list. It can also be updated if used to enumerate another list with additional elements:

q)t:25?cdef

q)`y?t

y$fefccdede`..

q)y

acbdfe

Hope that helps

Jonathon