clojure

clojure: for loop contents not invoked

左心房为你撑大大i 提交于 2020-01-30 02:39:12
问题 I'm trying to build an XML structure using the internal data types from BaseX from Clojure. (defn basex-elem [token-name dict] (let [elem (org.basex.query.item.FElem. (org.basex.query.item.QNm. token-name))] (for [[k v] dict] (do (println "THIS IS REACHED") (let [k-name (org.basex.query.item.QNm. (.getName k)) k-attr (org.basex.query.item.FAttr. k-name org.basex.util.Token/token v))] (.add elem k-attr)))) elem)) When using this to cry to create an element, "THIS IS REACHED" is never printed:

clojure: for loop contents not invoked

六眼飞鱼酱① 提交于 2020-01-30 02:38:22
问题 I'm trying to build an XML structure using the internal data types from BaseX from Clojure. (defn basex-elem [token-name dict] (let [elem (org.basex.query.item.FElem. (org.basex.query.item.QNm. token-name))] (for [[k v] dict] (do (println "THIS IS REACHED") (let [k-name (org.basex.query.item.QNm. (.getName k)) k-attr (org.basex.query.item.FAttr. k-name org.basex.util.Token/token v))] (.add elem k-attr)))) elem)) When using this to cry to create an element, "THIS IS REACHED" is never printed:

云计算时代

别来无恙 提交于 2020-01-30 01:03:16
人们想到选择一门计算机语言时,可能会选择学校里学到的知名度高的通用过程语言之一,比如C、Java或Python。但这些经常被人选择的语 言只是计算机语言领域的冰山一角而已――如果它使用关键字和结构来传达信息,那它就是一门语言。下面是值得考虑的十大云计算语言。 SQL数据语言 云计算时代,值得重视的十大云计算语言 说到数据语言,SQL是几十年来无可争议的霸主。连非关系型数据库服务器也使用某种SQL语言。就跟IT的其他所有领域一样,云计算领域同样充斥着SQL。 这是每个地方的开发人员都会会心一笑的SQL玩笑。“有人走进一间酒吧,看到两张桌子。他说‘我可以跟你一起喝吗?’” XML数据语言 云计算时代,值得重视的十大云计算语言 XML用来描述文档,而不是传达一串指令。由于XML通常并不给计算机下达指令,它通常不被认为是一门计算机语言。 XML是大受欢迎的数据标记语言,而这主要归因于Java。只要有Java的地方,就有XML。又由于Java自从早在云计算大行其道之前就一直驱动大规模分布式系统,XML文档无处不在。Apache hadoop配置就驻留在XML文件中。 R数学语言 云计算时代,值得重视的十大云计算语言 R语言帮助广大开发人员处理统计数字、报告和图形。交互式R教程让新的开发人员领略向量、因子及关联数据集带来的乐趣。 亚马逊将RStudio集成开发环境(IDE)与其EMR

What advantage does common lisp reader macros have that Clojure does not have?

*爱你&永不变心* 提交于 2020-01-29 02:51:05
问题 I have been using Clojure alot recently but I still don't understand what functionality I do not get that common lisp reader macros provide. Can explain explain this to me in simple terms? 回答1: In short, reader macros provide you with the ability to redefine the programming language's syntax within some delimited context. For example, you could implement regular expression literals (e.g. #"pattern" ) yourself given reader macros. Without them, you would be forced to properly escape regular

Can Clojure's protocol functions be variadic like ordinary functions?

末鹿安然 提交于 2020-01-28 08:57:46
问题 With clojure functions, I can define: (defn f [x & xs] (apply some-function x xs)) I'm attempting to do this same sort of thing with a protocol, e.g. (defprotocol foo (bar [f]) (baz [f & gs])) This compiles (at least in the REPL), but any implementing type seems to fail on this (the variadic, baz) method. Is this officially not supported? The sources that I've consulted are silent. 回答1: This is not supported, for the reasons Stuart Sierra gives. To go into a little more detail, the & symbol

Can Clojure's protocol functions be variadic like ordinary functions?

谁都会走 提交于 2020-01-28 08:55:48
问题 With clojure functions, I can define: (defn f [x & xs] (apply some-function x xs)) I'm attempting to do this same sort of thing with a protocol, e.g. (defprotocol foo (bar [f]) (baz [f & gs])) This compiles (at least in the REPL), but any implementing type seems to fail on this (the variadic, baz) method. Is this officially not supported? The sources that I've consulted are silent. 回答1: This is not supported, for the reasons Stuart Sierra gives. To go into a little more detail, the & symbol

Clojure equivalent of python's base64 encode and decode [duplicate]

∥☆過路亽.° 提交于 2020-01-25 21:25:29
问题 This question already has answers here : Clojure base64 encoding (6 answers) Closed 3 years ago . I have this python code snippet and need help with a clojure equivalent. user_id = row.get('user_id') if user_id: user_id_bytes = base64.urlsafe_b64decode(user_id) creation_timestamp = int.from_bytes(user_id_bytes[:4], byteorder='big') dc_id = int.from_bytes(user_id_bytes[4:5], byteorder='big') & 31 if creation_timestamp > WHEN_WE_SET_UP_DC_IDS: row['dc_id'] = dc_id} 回答1: You can use clojure's

How do I implement this generic Java interface with a Clojure record?

白昼怎懂夜的黑 提交于 2020-01-25 16:40:06
问题 I'm trying to implement org.joda.time.ReadableInstant. It inherits from a generic interface, but apparently that shouldn't matter. The interface is: public interface ReadableInstant extends Comparable<ReadableInstant> { long getMillis(); Chronology getChronology(); DateTimeZone getZone(); int get(DateTimeFieldType type); boolean isSupported(DateTimeFieldType field); Instant toInstant(); boolean isEqual(ReadableInstant instant); boolean isAfter(ReadableInstant instant); boolean isBefore

twitter response: “error 32: Could not authenticate you” from Heroku, but not desktop

大憨熊 提交于 2020-01-25 10:38:05
问题 I'm following the instructions from Carin Meier's How I Start post and having an issue with posting to twitter (like her example) from Heroku. Note that my app does not have a web component, just a worker component. Testing on my desktop, I'm able to post to twitter and gist.github.com. But, on Heroku, I always get Exception in thread "main" java.lang.Exception: Twitter responded to request with error 32: Could not authenticate you. I am able to post to gist.github.com, so it appears to be a

More functional way to do this?

会有一股神秘感。 提交于 2020-01-24 21:14:42
问题 This post of mine discusses Thomson's paradox, and simulates it in Clojure. The state function returns the state of the lamp at time = t. (defn thomsons-lamp [] (iterate (fn [[onoff dur]] [(not onoff) (/ dur 2)]) [true 1])) (defn state [t] (let [t-vals (map second (thomsons-lamp))] (loop [i 1] (if (<= t (apply + (take i t-vals))) ((comp first last) (take i (thomsons-lamp))) (recur (inc i)))))) How do I define a cleaner state function (preferably without loop/recur)? 回答1: The only sins here