Enumerations: Difference between revisions

Content added Content deleted
Line 745: Line 745:
}
}
</lang>
</lang>

=={{header|jq}}==

Finite, ordered enumerations can be represented in jq as JSON arrays, e.g. ["apple", "banana", "cherry"], or as sequences,
e.g. ("apple", "banana", "cherry"). The latter interpretation corresponds to the idea of '''enumerating''' a collection, and also dovetails with the concept of infinite enumerations.

Countably-infinite ordered enumerations can be represented by generators, e.g. the non-negative natural numbers can be represented by the jq expression:

1 | while(true; .+1)

Finite, unordered enumerations can be represented as JSON objects, as in the JSON section of this article.
In this context, it is worth noting that jq allows a shorthand notation for specifying objects, so that we can for example write:

def fruits: {apple, banana, cherry}; # i.e. {"apple" : null, "banana": null, "cherry": null }


=={{header|JSON}}==
=={{header|JSON}}==