clojure

How to remove multiple keys from a map?

瘦欲@ 提交于 2020-07-28 11:20:29
问题 I have a function that removes a key from a map: (defn remove-key [key map] (into {} (remove (fn [[k v]] (#{key} k)) map))) (remove-key :foo {:foo 1 :bar 2 :baz 3}) How do i apply this function using multiple keys? (remove-keys [:foo :bar] {:foo 1 :bar 2 :baz 3}) I have an implementation using loop...recur. Is there a more idiomatic way of doing this in Clojure? (defn remove-keys [keys map] (loop [keys keys map map] (if (empty? keys) map (recur (rest keys) (remove-key (first keys) map)))))

编程丨一大波锻炼程序员编程能力的【神秘网站】,先到先得哦!

心不动则不痛 提交于 2020-07-28 09:10:39
作为一个程序员,其实我们无时不刻不再为我们自己的编程水平而发愁,都想要提升自己的编程能力,因为只有这样,才能够有提升的空间,才能有更好的发展,但是我们工作就已经占据了大部分的时间,哪有这个精力来花大部分的时间来提升自己呢?那么在下不才,就来分享一下我找到的这些个能够闲余时间提升我们编程能力的网站! 嘿!有时我们需要娱乐和放松一点,但是我们可以从自己身上受益,边玩边学是不是很好呢?今天,我们将了解到一些【神秘站点】,这些站点将训练您的大脑并提高您的编码技能。(当然,对于大佬来说可能这些网站都是有了解的,不喜勿骂哈~) 游戏类 Codecombat —是一款了不起的多人游戏,可帮助您学习编程,而不是游戏课程。 Screeps- 面向程序员的全球首个MMO策略开放世界游戏。 Git游戏 —是一款终端游戏,旨在测试您对git命令的了解。 电梯传奇 -您的任务是通过使用JavaScript编写程序来对电梯的运行进行编程。目标是高效地运送人员。 CodeChef —您可以解决实际问题,并参加每月进行的各种竞赛。 Codingame 将解决方案变成了一个游戏,您可以为每组通过的测试获得积分。 Hacker.org 是衡量您的知识的一系列难题和测试。要通过该系列,您必须解决和分析很多。 Pex娱乐 -来自Microsoft的游戏,您可以在其中与其他编码人员竞争。您的武器-代码。 Rankk

Scala vs. Groovy vs. Clojure [已结束]

Deadly 提交于 2020-07-28 01:57:56
问题: Can someone please explain the major differences between Scala, Groovy and Clojure. 有人可以解释Scala,Groovy和Clojure之间的主要区别。 I know each of these compiles to run on the JVM but I'd like a simple comparison between them. 我知道这些编译中的每一个都在JVM上运行,但我想在它们之间进行简单的比较。 解决方案: 参考一: https://stackoom.com/question/5W1M/Scala-vs-Groovy-vs-Clojure-已结束 参考二: https://oldbug.net/q/5W1M/Scala-vs-Groovy-vs-Clojure-closed 来源: oschina 链接: https://my.oschina.net/stackoom/blog/4339652

编程丨一大波锻炼程序员编程能力的【神秘网站】,先到先得哦!

こ雲淡風輕ζ 提交于 2020-07-25 08:08:51
作为一个程序员,其实我们无时不刻不再为我们自己的编程水平而发愁,都想要提升自己的编程能力,因为只有这样,才能够有提升的空间,才能有更好的发展,但是我们工作就已经占据了大部分的时间,哪有这个精力来花大部分的时间来提升自己呢?那么在下不才,就来分享一下我找到的这些个能够闲余时间提升我们编程能力的网站! 嘿!有时我们需要娱乐和放松一点,但是我们可以从自己身上受益,边玩边学是不是很好呢?今天,我们将了解到一些【神秘站点】,这些站点将训练您的大脑并提高您的编码技能。(当然,对于大佬来说可能这些网站都是有了解的,不喜勿骂哈~) 游戏类 Codecombat —是一款了不起的多人游戏,可帮助您学习编程,而不是游戏课程。 Screeps- 面向程序员的全球首个MMO策略开放世界游戏。 Git游戏 —是一款终端游戏,旨在测试您对git命令的了解。 电梯传奇 -您的任务是通过使用JavaScript编写程序来对电梯的运行进行编程。目标是高效地运送人员。 CodeChef —您可以解决实际问题,并参加每月进行的各种竞赛。 Codingame 将解决方案变成了一个游戏,您可以为每组通过的测试获得积分。 Hacker.org 是衡量您的知识的一系列难题和测试。要通过该系列,您必须解决和分析很多。 Pex娱乐 -来自Microsoft的游戏,您可以在其中与其他编码人员竞争。您的武器-代码。 Rankk

Remove one set from another in Clojure

流过昼夜 提交于 2020-07-23 06:09:09
问题 (def mine '(a b c)) (def yours '(a b)) (remove yours mine) ; should return (c) I was advised to use remove in another thread but it doesn't work. Anyone can advise? 回答1: Assuming you want to remove from mine every element that also exists in yours , there are a few approaches. You can convert the lists to sets and use difference, like this: (require '[clojure.set :refer [difference]]) (def mine '(a b c)) (def yours '(a b)) (difference (set mine) (set yours)) ;; => #{c} But this does not

Remove one set from another in Clojure

喜你入骨 提交于 2020-07-23 06:08:09
问题 (def mine '(a b c)) (def yours '(a b)) (remove yours mine) ; should return (c) I was advised to use remove in another thread but it doesn't work. Anyone can advise? 回答1: Assuming you want to remove from mine every element that also exists in yours , there are a few approaches. You can convert the lists to sets and use difference, like this: (require '[clojure.set :refer [difference]]) (def mine '(a b c)) (def yours '(a b)) (difference (set mine) (set yours)) ;; => #{c} But this does not

Remove one set from another in Clojure

爱⌒轻易说出口 提交于 2020-07-23 06:07:02
问题 (def mine '(a b c)) (def yours '(a b)) (remove yours mine) ; should return (c) I was advised to use remove in another thread but it doesn't work. Anyone can advise? 回答1: Assuming you want to remove from mine every element that also exists in yours , there are a few approaches. You can convert the lists to sets and use difference, like this: (require '[clojure.set :refer [difference]]) (def mine '(a b c)) (def yours '(a b)) (difference (set mine) (set yours)) ;; => #{c} But this does not

Performance of multimethod vs cond in Clojure

守給你的承諾、 提交于 2020-06-26 12:25:09
问题 Multimethods are slower than protocols and one should try to use protocols when they can solve the problem, even though using multimethods gives a more flexible solution. So what is the case with cond and multimethod? They can be used to solve the same problem but my guess is that multimethod has a huge performance overhead vs cond . If so why would i ever want to use multimethod instead of cond ? 回答1: To follow up on @AlexMiller comment, I tried to benchmark with more randomised data and

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

淺唱寂寞╮ 提交于 2020-06-23 06:51:07
问题 How does it work? (seq #{3 1 22 44}) And why the order will be like (1 3 44 22) 回答1: 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

NullPointerException when lein ring server on Aleph+Ring

♀尐吖头ヾ 提交于 2020-06-17 07:38:27
问题 I am trying to run Aleph on top of Ring and use lein ring server for shorter feedback loop. When I'm invoking lein ring server everything seems to be fine but when I point my browser to an url I get a nasty NullPointerException with the stack trace below. However, when I run (al.app/start 3006) then no NLP shows up. The whole project is available on GitHub. What am I doing wrong? core.clj:107 lamina.core/enqueue app.clj:39 al.app/hello-handler http.clj:79 aleph.http/wrap-aleph-handler[fn]