This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-06
Channels
- # bangalore-clj (7)
- # beginners (51)
- # bigdata (1)
- # cider (97)
- # cljsjs (2)
- # clojure (41)
- # clojure-dev (2)
- # clojure-dusseldorf (5)
- # clojure-nl (16)
- # clojure-russia (43)
- # clojure-spec (13)
- # clojure-uk (59)
- # clojurescript (24)
- # community-development (16)
- # datomic (18)
- # defnpodcast (1)
- # editors (96)
- # figwheel-main (6)
- # fulcro (13)
- # jobs-discuss (2)
- # jobs-rus (8)
- # off-topic (8)
- # onyx (11)
- # pedestal (3)
- # re-frame (18)
- # reitit (2)
- # shadow-cljs (158)
- # spacemacs (7)
- # tools-deps (3)
- # vim (3)
https://github.com/trptcolin/reply/issues/184 -- just in case Colin feels like adding deps.edn
to REPL-y (or someone wants to send a PR).
Is this a bug in clojure? (inc nil) returns NullpointerException and the Stacktrace is missing
it does the same thing as (+ nil nil)
. this is a garbage in garbage out situation i believe. I get a stacktrace in CIDER. I don't know what environment you are using
@mx2000 - you might need to do a (println *e)
to get a full stacktrace - if you haven't tried it already on the repl.
@mx2000 If you are doing (pst *e)
or something similar to try to look at the exception, and the stack trace is one line long or empty, that is unusual, but I believe possible depending upon optimization and other command-line options when you started the JVM. More details here than I know myself: https://stackoverflow.com/questions/2411487/nullpointerexception-in-java-with-no-stacktrace
If you are just doing (inc nil)
and seeing only one line mentioning the NullPointerException, that is normal for a REPL to only show that much information when an exception occurs.
I know that functions only support primitive type hints with four or fewer args. Does loop-recur form have the same restriction?
The other possible explanation for the warning is that a function I'm calling with a primitive type hint on the return type isn't getting called properly. What I mean by that is when I look at the decompiled Java code for the function with the primitive type hint, I see that it has an invokeStatic and invokePrim method that return a primitive double, but it also has a regular invoke that returns a boxed Double. When I look at the decompiled Java code produced at the call site, I see that it is calling invoke and thus getting an Object back, not a double. Any idea why the call site would not be invoking the primitive return version of my function? Any restrictions on using functions with primitive return types that I need to know about? It's not being called as a higher-order function, which is the main thing I would think might cause the primitive version to be ignored.
Yes, I'm now certain that at the call site, it's not invoking the compiled version of the function with the primitive return type. What's the trick to getting Clojure to actually use the version of the function with the primitive return type?
I think I figured it out. I had incorrectly placed the return type hint on the function name rather than the arg list.
Eastwood has some warnings about ineffective or erroneous Clojure type hints. Not sure if it would have caught that for you or not.
If I do (defrecord R [foo bar]) and then I want to type hint something in the same namespace as an R, I can do ^R. From another namespace, however, it doesn't seem so user-friendly. I am able to do ^myns.core.R as a type hint, but if I've aliased myns.core as n, I can't do ^n/R. Is there any way to refer to the type of a defrecord, deftype, definterface through a namespace alias?
(ns my-ns (:require [my-record-ns :refer [..]]) (:import my_record_ns.R))
and then you can type hint using ^R
What is the proper way to cycle a string: eg beatles --> sbeatle, esbeatl, lesbeat etc
?
Maybe close to what you want: (map #(apply str %) (partition (count "beatles") 1 (concat (seq "beatles") (seq "beatles"))))
But @domonicm answer may lead to something in the order you requested.
(defn last-to-front [s] (apply str (last s) (butlast s)))
hi everyone. I’m experimenting with time
in clojure. i’m using clj-time
at the moment. I’m trying to create a script, that will change the logo on my website, based on the period of time. so I have these holidays
(def holidays [{:from '(12 23)
:to '(12 27)
:label "Christmas"
:logo "/img/logos/christmas.png"}
{:from '(10 27)
:to '(11 3)
:label "Halloween"
:logo "/img/logos/halloween.png"}])
and what I want to do is to create a function that accepts the current year and then loops over that vector and checks, if the current date is between the range of from
and to
of a holiday period, I want it to return the holiday map. I thought I would get the current year somehow and then use cons
to add that year to those lists in the beginning and then use the whole thing with t/date-time
to parse datesok I think I got it
(ns logo-chooser.core
(:require [clj-time.core :as t])
(:gen-class))
(def holidays [{:from [12 23]
:to [12 27]
:label "Christmas"
:logo "/img/logos/christmas.png"}
{:from [10 27]
:to [11 3]
:label "Halloween"
:logo "/img/logos/halloween.png"}
{:from [1 1]
:to [12 31]
:label "Default"
:logo "/img/logos/default.png"}])
(defn- check-holiday-date-range
[{:keys [to from]} current-date]
(let [current-year (t/year current-date)
interval (->> [from to]
(map (comp #(apply t/date-time %) #(cons current-year %)))
(apply t/interval))]
(t/within? interval current-date)))
(defn- get-current-holiday
[holidays current-date]
(first (filter #(check-holiday-date-range % current-date) holidays)))
(defn -main
[& args]
(println (get-current-holiday holidays (t/now))))
@bravilogy If you're on Java 8 or later, you should probably use Java Time instead of Joda Time -- unless you have a specific reason to use the latter?
Using Java Time directly from Clojure isn't bad, but you could also look at clojure/java-time
as an idiomatic wrapper for it.
(note: I'm one of the maintainers of clj-time
and I'm trying to encouraging people to migrate away from it now that we have Java Time built-in)
Spec question- are s/merge and s/multi-spec composable? As in, can you s/merge a normal s/keys and a s/multi-spec?