This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-16
Channels
- # beginners (103)
- # boot (48)
- # cider (2)
- # clara (12)
- # cljsrn (9)
- # clojure (133)
- # clojure-art (3)
- # clojure-dev (9)
- # clojure-korea (7)
- # clojure-russia (228)
- # clojure-spec (8)
- # clojure-uk (26)
- # clojurescript (131)
- # cursive (8)
- # datomic (30)
- # emacs (4)
- # events (2)
- # hoplon (47)
- # lein-figwheel (5)
- # off-topic (1)
- # om (12)
- # onyx (337)
- # perun (23)
- # planck (15)
- # proton (3)
- # re-frame (5)
- # spacemacs (20)
- # untangled (97)
- # utah-clojurians (1)
- # yada (13)
clojure
cljs.user=> (defrecord A [a b c])
cljs.user/A
cljs.user=> (A. 1 2 3)
#cljs.user.A{:a 1, :b 2, :c 3}
cljs.user=> (def a (A. 1 2 3))
#'cljs.user/a
cljs.user=> (pr-str a)
"#cljs.user.A{:a 1, :b 2, :c 3}"
cljs.user=> (def b (pr-str a))
#'cljs.user/b
cljs.user=> (read-string b)
WARNING: Use of undeclared Var cljs.user/read-string at line 1
TypeError: Cannot read property 'call' of undefined
cljs.user=> (require '[cljs.reader :refer [read-string]])
nil
cljs.user=> (read-string b)
Error: Could not find tag parser for cljs.user.A in ("inst" "uuid" "queue" "js")
cljs.user=>
Sure, assuming you've installed a data reader for it or a default data reader
I'm trying but failing to figure out which of the books in the series of The Little LISPer/Schemer have no-cost licensing. Sure, a lot of them are available online, but I can't tell if it's legally or not.
If anyone knows, let me know. Thanks.
boot.user=> (defrecord A [a b])
boot.user.A
boot.user=> (def a (A. 1 2))
#'boot.user/a
boot.user=> (def b (pr-str a))
#'boot.user/b
boot.user=> (read-string b)
<#C053K90BR|boot>.user.A{:a 1, :b 2}
boot.user=> (= (type b) A)
false
boot.user=> (type b)
java.lang.String
boot.user=> (= (type a) A)
true
I should read the whole page, it's different in cljs, but we do have an anwser http://stackoverflow.com/a/29133350/883571 thx @alexmiller
Hello, I would like to setup Clojure-NGINX.. on Ubuntu 14.04. I installed NGINX, works (http://gooapir.com - my test server). I would like to add the NGINX module.. I don’t know what is the problems: I untar the file with command tar -xzvf “nginx-clojure-0.4.4.tar.gz”.. after this I would like to run ./configure.. (as in the spec) but not works. Could you help me? What is the wrong? Maybe very trivial…
Can you paste somewhere the contents of the directory that schould contain configure ?
I suspect that you have download a binary file. What happens if you do 'sh nginx-linux-i586 ` ?
nginx-linux-i586: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped
Why do I see here two times nill :
(def the-world (ref "hello"))
(def bizarro-world (ref {}))
=> #'koan-engine.runner/the-world
=> #'koan-engine.runner/bizarro-world
(do
(dosync
(ref-set the-world {})
(alter the-world assoc :jerry "Real Jerry")
(alter bizarro-world assoc :jerry "Bizarro Jerry")
[ (:jerry the-world) (:jerry bizarro-world) ]))
=> [nil nil]
@sb @roelofw sometimes a "dot" and a "slash" can help, e.g.,
./nginx-linux-i586
which has to do with current directory not on your $PATH@johnny.martin thanks for the tip. I hope sb get s things working
@johnny.martin @roelofw Thanks guys! You save my day! 👍 👍 💪
(apply + (range 10000000000000 10000000001000))
;; ArithmeticException: integer overflow
(apply +' (range 10000000000000 10000000001000))
;;=> 1000000000499500
If I have this code : (defrecord Nobel [prize])
is it right that the price is returned back
Not sure what you’re asking @roelofw ?
When I type (defrecord Nobel [prize])
into a REPL, it prints the name of the class just defined (`boot.user.Nobel` in my case)
and now I do (.prize (Nobel. xxxx ))
where x can be a any string. Is it right that the outcome will be xxxx
It’s more idiomatic to write (:prize (->Nobel xxxx))
but, yes, if you construct a Nobel
record with xxxx
as the argument, that will be the value of the prize
field.
It would be like this expression (:prize {:prize xxxx})
in repl I only see the xxx part. See :
(defrecord Nobel [prize])
(deftype Pulitzer [prize])
(defprotocol Award
(present [this recipient]))
(defrecord Oscar [category]
Award
(present [this recipient]
(print (str "Congratulations on your "
(:category this) " Oscar, "
recipient
"!"))))
=> koan_engine.runner.Nobel
=> koan_engine.runner.Pulitzer
=> Award
=> koan_engine.runner.Oscar
(.prize (Nobel. "peace"))
=> "peace"
@seancorfield : did I do something wrong or do I misunderstood you with my other outcome as you described ?
I think it does , but according to the explanation of sean the outcome schould be (:prize {:prize peace)
instead of just 'peace'
Like I said earlier I try to understand the things I learn from the record chapter of the clojure koans
@roelofw I think you misunderstood Sean, I think he was saying that the outcome of (.prize (Nobel. xxxx ))
should be like the outcome of (:prize {:prize xxxx})
. In other words, the action of getting a value out of a record is like the action of getting a value out of a map.
☝️:skin-tone-2:
one last question : On this code :
(defprotocol Award
(present [this recipient]))
(defrecord Oscar [category]
Award
(present [this recipient]
(print (str "Congratulations on your "
(:category this) " Oscar, "
recipient
"!"))))
The Award protocol says “Any record that implements the Award protocol will have a method named “present” that takes the arguments “this” and “recipient” and does something appropriate with them”. Then the definition for “Oscar” says “This record implements the Award protocol, and here is Oscar’s implementation of the “present” method.” So a protocol is something like a Java or C interface that lets you share behaviors between record types that are similar
For small, tutorial examples like Award and Oscar, it might not be apparent how much power this gives you, but it’s a good introduction to “here are the basic principles of how you define and use a protocol."
@manutter51 so with a protocol I can have methods that I can use in different records
Right, you have the basic idea at least. It’s like having a contract that says “I know how to do ‘X’” and then you can have a number of different record types but they all know how to do “X” so they can all implement the same protocol.