Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why will (seq #{3 1 22 44}) comes out (1 3 44 22) in clojure?

Tags:

set

clojure

How does it work?

(seq #{3 1 22 44})

And why the order will be like

(1 3 44 22)

like image 795
procr Avatar asked Mar 03 '14 14:03

procr


People also ask

Why we use seq in R programming?

seq() function in R Language is used to create a sequence of elements in a Vector. It takes the length and difference between values as optional argument.

What is transcriptomic study?

Transcriptomics is the study of the transcriptome—the complete set of RNA transcripts that are produced by the genome, under specific circumstances or in a specific cell—using high-throughput methods, such as microarray analysis.

Can sequencing?

Can-Seq offers an accurate, cost-effective method for classifying new mutants into known versus unknown genes. It has several advantages over existing genetic and DNA sequencing approaches that are currently being used in forward genetic screens for gene discovery.

What is RNA-seq short for?

RNA-Seq (named as an abbreviation of RNA sequencing) is a sequencing technique which uses next-generation sequencing (NGS) to reveal the presence and quantity of RNA in a biological sample at a given moment, analyzing the continuously changing cellular transcriptome.


1 Answers

Because the set data structure is, by definition, unordered: http://en.wikipedia.org/wiki/Set_(data_structure)

To be more precise, Clojure's built-in set (which #{blah blah blah} gives you) is a hash set -- that is, a set backed by a hash table (http://en.wikipedia.org/wiki/Hash_tables). It provides you with the following guarantees:

  • Uniqueness of every element (no duplicates allowed).
  • O(1) performance characteristics for insertion and containment checks.
  • Iteration works -- calling seq will give you every element in the set, but in an undefined order.

Undefined order, here, means that the iteration order depends on the elements you inserted in the set, their number, the order in which you inserted them, all the other operations you may have tried on that set before, and various other implementation details that might change from a language version to the other (and even between implementations -- you might, and probably will, get different results in Clojure, Clojure running on a 64-bit JVM, or ClojureScript).

The important thing to take away is, if you're writing code that works with sets (or maps), never make it depend on any notion of order in said sets/maps. It'll break.

like image 182
Max Noel Avatar answered Oct 08 '22 17:10

Max Noel