Help me understand how the conflict between immutability and runtime is handled in Clojure

Clojure really aroused my interest, and I began to study it: http://java.ociweb.com/mark/clojure/article.html

Consider these two lines listed in the Install section:

(def stooges (hash-set "Moe" "Larry" "Curly")) ; not sorted
(def more-stooges (conj stooges "Shemp")) ; -> #{"Moe" "Larry" "Curly" "Shemp"}

My first thought was that the second operation should take constant time; otherwise, a functional language may have few advantages over an object-oriented one. One can easily imagine the need to start with an [almost] empty set, fill it and squeeze it as you move. Thus, instead of assigning a new result to a smaller one, we could reassign it to ourselves.

Now, with the amazing promise of functional languages, the side effects are unrelated. Thus, kits stoogesand more-stoogesdo not work with each other. Thus, the creation more-stoogesis a linear operation or they have a common buffer (for example, Java StringBuffer), which will seem like a very bad idea and conflicts with immutability (it stoogescan subsequently delete the one-element one at a time).

I probably reinvent the wheel here. it looks like it hash-setwill be more productive in clojurewhen you start with the maximum number of elements, and then delete them one at a time until the empty set is against the empty set and grows one at a time.

, - , Java/#/Python/etc. , .

, ( promises?) , . , , - ?

-, Python, . , C, Python, . , , , , , .

, .

+3
2

- . , , :

http://blip.tv/file/707974

:

  • .
  • ( <= )
  • , ( )

?

  • : ( trie).

, - ?

: a Trie - , . clojure trie, , . -. , , , , , , .

, . .

(relativly short) _ book: , " ", . , . pdf

+8

Clojure , , , "". . Clojure. ,

, , , . , , .

, Rich Rich Hickey, .

+3
source

Source: https://habr.com/ru/post/1764074/


All Articles