1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Clojureで挿入順を維持するマップは?

Last updated at Posted at 2014-04-30

ClojureでJavaのLinkedHashMapのように挿入順を維持するマップはないようです。まあ厳密にはイミュータブルだからそんなのないでしょうが。

array-map関数を使えば、マップ構築時に引数の順番は維持してくれますが、assoc等で変更したマップまで順番が維持される保証はありません。

(type {})
(type {1 1})
(type {1 1 2 2 3 3 4 4 5 5 6 6 7 7})
(type {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8})
(type {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9})

(type (assoc {1 1 2 2 3 3 4 4 5 5 6 6 7 7} 8 8))
(type (assoc {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8} 9 9))
(type (assoc {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9} 10 10))


{1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11}
(array-map 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11)
(assoc {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8} 9 9)
(assoc {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9} 10 10)

WS000002.JPG

つづき

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?