Idiomatic mode to loop the network to Clojure
source link: https://www.codesd.com/item/idiomatic-mode-to-loop-the-network-to-clojure.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Idiomatic mode to loop the network to Clojure
I am new to clojure and some how I find simple array manipulations which are easy in python too hard to do in clojure. For example, what is an idiomatic way to do this in clojure?
for i = 1 to len(arr)-1:
sum[i] = arr[i-1] + i
Clojure has a nice set of sequence manipulation functions that are often helpful for these common tasks. this example would be (map-indexed + arr)
user> (def arr [1 2 38 2 3 9 4 2])
#'user/arr
user> (map-indexed + arr)
(1 3 40 5 7 14 10 9)
though that's just because of the specific example you chose. A more general answer would be to use map
, mapv
, reduce
, or reductions
or for
for this sort of thing. For instance:
user> (for [i (range 0 (count arr))] (+ i (arr i)))
(1 3 40 5 7 14 10 9)
Related Articles
Idiomatic mode to write the code Clojure to read the lines of the console repeatedly?
Idiomatic mode to transform the map into kotlin?
Idiomatic mode to leave the loop ksh while
Idiomatic mode to test the generic type in C #
Idiomatic mode for decompressing the list of variable lengths of the maximum size n
looping the network from the user's input
More idiomatic way to calculate the control digit GS1 to Clojure
VBox network mode to test the Win 2008 server?
Find all computers connected to the network and get their IP addresses - Windows C
WsDualHttpBinding Does Not Work Outside the Network with WPF Client
Use Json data from the network call in UITableView
Is the network available in Android?
how to calculate the diameter of the network
Loop the select statement and assign the identifiers 1-16
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK