This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-22
Channels
- # announcements (2)
- # babashka (18)
- # beginners (87)
- # calva (22)
- # chlorine-clover (5)
- # cider (11)
- # clj-kondo (10)
- # clojure (71)
- # clojure-austin (1)
- # clojure-norway (6)
- # clojure-uk (13)
- # clojurescript (3)
- # core-async (10)
- # data-science (17)
- # datascript (1)
- # datomic (22)
- # emacs (10)
- # fulcro (32)
- # hoplon (8)
- # jobs-discuss (2)
- # malli (5)
- # meander (5)
- # nrepl (35)
- # off-topic (8)
- # pathom (38)
- # planck (21)
- # re-frame (10)
- # reagent (17)
- # reitit (7)
- # shadow-cljs (26)
- # tools-deps (3)
- # xtdb (7)
I want to import a lib called me.raynes.fs with require,and reference it as fs,how do i do
(require '[me.raynes.fs :as fs])
(fs/chdir "/")
Execution error (IllegalStateException) at me.raynes.fs/chdir (fs.clj:541).
Can't change/establish root binding of: *cwd* with set
this is source of this function
(defn chdir
"set!s the value of *cwd* to path. Only works inside of
with-mutable-cwd"
[path]
(set! *cwd* (file path)))
user=> (fs/with-mutable-cwd (fs/chdir "projects/clojure") (prn fs/*cwd*))
#object[.File 0x7e4d2287 "/home/dan/projects/clojure"]
nil
user=> (prn fs/*cwd*)
#object[.File 0x68c87fc3 "/home/dan"]
I’d like to know, how (.toString some-proxy-instance) dispatches on the proxy instance
given a proxy instance, it has a toString function stored inside its function mapping, and also an inherited toString method from class hierarchiy
So, the generated stub method will first check if a corresponding function exists in the mapping. If not, it then goes on calling its super class.
what’s the use case of proxy when compared to deftype and reify. the only case seems to avoid implementing some interface methods? kinda weird.
can you explain what you mean about checking for functions existing?
(.toString (proxy [java.util.Date] []
(toString [] "bob")))
"bob"
I couldn't use reify for a class so can't reify a java.util.Date. If i wanted to deftype something I would have to basically reinvent all of the date functions on the new deftype
https://clojure.org/reference/datatypes#_reify has some more (official) info contrasting them
check for existing, I mean something like this: https://github.com/clojure/clojure/blob/30a36cbe0ef936e57ddba238b7fa6d58ee1cbdce/src/clj/clojure/core_proxy.clj#L101
why do you have to re-define everything for deftype? You just define the method that overrides some in the superclass that you want to tweak with.
how could you use deftype to get a datetime that behaves exactly like a datetime except for the toString like i did above?
@U11BV7MTK aha, I wrongly thought deftype can extend a class.
When I read out all content of file,I want to seek the point into header of file,how do I handle it in Java??
If you're asking how to position/seek in a file, take a look at the
class.
hi, I was trying to find a way to extend a spec, but I could not find any examples
I would like to extend this spec with other keys: (s/keys :req-un [::name])
I am not sure what you mean
but the main problem is that I don’t want to repeat the original spec again
Although, the docstring says that it accepts predicates and not specs (talking about s/or
).
let me try s/merge
beautiful!
thank you!
and it is even mentioned in the spec guide
(s/def :animal/dog (s/merge :animal/common
(s/keys :req [:dog/tail? :dog/breed])))
how do i change directory with http://clojure.java.io?? is there a marco like with-open ,suck like with-mutable-cwd,which simply program proccess
how can i use http://clojure.java.io to read out
@steiner3044 working dir is a java thing, and there is no chdir equivalent: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=4045688
I don’t understand what “read out” means
is there any function in http://clojure.java.io??
(defn slurp
"Opens a reader on f and reads all its contents, returning a string.
See for a complete list of supported arguments."
{:added "1.0"
:tag String}
([f & opts]
(let [opts (normalize-slurp-opts opts)
sw (.StringWriter.)]
(with-open [^.Reader r (apply jio/reader f opts)]
(jio/copy r sw)
(.toString sw)))))
@steiner3044 can I once again ask you to ask your questions in #beginners? There are lots of folks who love to help beginners through these kinds of challenges but this isn't the best place for it
no bother at all! I'm happy to help and work through problems. But there are thousands of people in this channel who haven't necessarily signed up for that. So to be respectful we can go to the beginners channel and have lots of patient and attentive people help us
in clojure, what's the best way to take [[1]]
and get a java object of type byte[][]
? for some context, i'm trying to make an object that i can pass as the first arg to the DataBufferByte
constructor: https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/java/awt/image/DataBufferByte.html
it's kind of hard to search for byte[][]
and i'm familiar enough with java to know if it has a more searchable name
I searched for clojure 2 d java array
and found this SO: https://stackoverflow.com/questions/3868192/how-do-i-create-a-primitive-two-dimensional-2d-array-of-doubles-in-clojure
(into-array (map byte-array [[1]]))
does seem to provide a native byte[][]
...
user=> (into-array (map byte-array [[1]]))
#object["[[B" 0x74a9c4b0 "[[B@74a9c4b0"]
user=> (byte-array [1])
#object["[B" 0x54f5f647 "[B@54f5f647"]
user=>
that'll do it, thanks 🙂 on that note, maybe i'll add (for anyone searching?) that https://clojars.org/clojure-interop/java.awt doesn't yet provide a definition for the constructor that takes byte[][]
, but it seems like it would be pretty easy to define.