This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-16
Channels
- # atlanta-clojurians (8)
- # beginners (103)
- # boot (22)
- # boot-dev (1)
- # cider (36)
- # cljs-dev (55)
- # cljsrn (3)
- # clojars (25)
- # clojure (104)
- # clojure-brasil (1)
- # clojure-dusseldorf (2)
- # clojure-italy (8)
- # clojure-norway (9)
- # clojure-russia (15)
- # clojure-spec (6)
- # clojure-uk (26)
- # clojurescript (246)
- # cursive (26)
- # data-science (1)
- # datomic (22)
- # dirac (11)
- # editors (1)
- # emacs (8)
- # fulcro (50)
- # graphql (11)
- # hoplon (1)
- # jobs-discuss (27)
- # leiningen (44)
- # luminus (33)
- # lumo (2)
- # mount (1)
- # off-topic (8)
- # onyx (5)
- # parinfer (4)
- # reagent (94)
- # ring-swagger (14)
- # shadow-cljs (37)
- # spacemacs (10)
- # specter (3)
- # tools-deps (4)
- # unrepl (14)
- # yada (5)
using clojure.java.jdbc, is there a way to execute a sql statement not in a block?
=> (clojure.java.jdbc/execute! -db "DISCARD ALL")
PSQLException ERROR: DISCARD ALL cannot run inside a transaction block org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse (QueryExecutorImpl.java:2422)
@wei Use db-do-commands
instead of execute!
-- then you can tell it to not use a transaction.
(clojure.java.jdbc/db-do-commands -db false "DISCARD ALL")
assuming -db
is the symbol that is bound to your db-spec(also, if it helps, there's a #sql channel for in-depth JDBC / SQL questions)
@seancorfield perfect-- thanks!
In general, the assumption is that DDL should be run with db-do-commands
and SQL run with query
/ execute!
(and the various insert and delete functions)
I see. for context, this is a workaround to a problem I discovered after upgrading postgres. the most recent version caches prepared statements, so sometimes a migration that changes a table will trigger an error when a cached query is run against that table
PostgreSQL is a strange beast.
clojure.spec
is very useful for taking apart structured data. What is the most similar option for strings? I'd like to put a string into a parser and get a labeled tree out of it.
@dottedmag, maybe Instaparse is what you want? https://github.com/Engelberg/instaparse
@jduhamel, we do use gloss in production even though it's been archived and it works fine for us (although it could maybe have more batteries included and nicer exceptions and...). I'm not aware of a replacement.
@miika Thanks. I was not thrilled by a string-based parser declaration when I looked at it. I'll give it a second try.
Search the README for instaparse.combinators
- you can declare the parsers with Clojure data as well
Yep, read up to it already. This README is long, and I didn't expect it to have two interfaces 😃
How can I insert record into this table with clojure.java.jdbc and postgresql?
CREATE TABLE accounts (
id serial primary key
);
I’ve tried these functions.
;; This function call throws PSQLException. It generates invalid query for postgresql.
(clojure.java.jdbc/insert! db :accounts {})
;; This works, but cannot get generated ID as return value
(clojure.java.jdbc/execute! db ["INSERT INTO accounts (id) VALUES (DEFAULTS);"])
general question about lib deployments to clojars. Is there a best practice for the naming of artifacts? I've seen quite a number of projects deployed without an artifact name prefix, and when there is a prefix, is it considered narcissistic to use your own handle vs some generic grouping or possibly the artifact name itself (`[somename/somename "1.0.0"]`)?. How about the clj-
pattern for the project name part of the artifact id?
For reference and as two examples of well known clojure libs with both patterns in them, [clj-http "3.8.0"]
has no prefix and uses the clj-
pattern, whereas [com.rpl/specter "1.1.0"]
has a prefix and no clj-
pattern.
single-segment artifacts are a bad practice that is being weeded out slowly. using your own handle is fine, but the recommended approach is to use https://en.wikipedia.org/wiki/Reverse_domain_name_notation if you own a domain
note that the single-segment clj-http
artifact is equivalent to clj-http/clj-http
i think
well I own a business which owns a domain and I think this relationship with domains might be fairly common, i.e. devs often live two lives, one in which they work for some entity with a domain, and one where they do open source projects but are possibly not associated with a domain. Ok, well I'll try to refrain from the single-segment pattern then
I assume that goes for the pattern where you use the project name twice as well then...repeating the same string twice doesn't exactly improve the macro behavior of the system
yeah makes sense...ok I guess I'll meditate over the prefix a bit, need to publish a few libs
using your own handle feels a bit narcissistic though, that would be forcing people to essentially write my name in their project files...a tad intrusive
there are those that use their github username and the reverse domain convention like so: com.github.username
then again, if you ever move your project from github to some other place, then that prefix starts to look pretty weird
in fact for this purpose, it would have been good with a domain extension specifically for library publications .lib
or something
would be quite nice to have something like https://js.org/ for Clojure i suppose
Hi all, why doesn't this work (map #(% 2 3) '(+ / * -))
but this does? (map #(% 2 3) (list + / * -))
In particular, I'm confused about why the former yields (3 3 3 3)
Quoting the list will return a list with the symbols '+ '/ '* '-
(list + / * -)
will return a list with the vars that are bound to the functions clojure.core/+
etc.
Using a backtick instead of a quote will return a list of namespaced symbols that clojure can resolve to be functions, that is:
;; passing `(+ * / -)
(map #(% 2 3) `(+ * / -)) ;;=> (3 3 3 3)
(= '(+ * / -) (list '+ '* '/ '-))
(not= '(+ * / -) `(+ * / -))
(not= `(+ * / -) (list + * / -))
(= (map (comp deref resolve) `(+ * / -))
(list + * / -))
@tsulej yes, it's the '(+ / * -)
version that returns (3 3 3 3)
, seems + - / * are read as symbols and not as functions
=> (take 10 (map #(apply * % (range 1 %)) (iterate inc 1)))
(1 2 6 24 120 720 5040 40320 )
Is there a way to do it with corecursion? something like (this doesn't work) (def fact (lazy-cat [1] (map * fact (map inc fact))))
🙂 @rauh’s solution is special to me because making that work was my first commit to the ClojureScript compiler. There is a cool Fibonacci sequence example like that in https://dev.clojure.org/jira/browse/CLJS-817
@devicesfor you can take the matter into your own hands and avoid whatever any REPL might be doing, by evaluating (.printStackTrace *e)
I was thinking about starting a “Elements of Clojure” book club. I posted some thoughts here: https://clojureverse.org/t/elements-of-clojure-book-club/1769 Feedback and possible participants welcome.
Doesn’t look like you got much response to this, but I’d be quite interested if you do go ahead …
@devicesfor And of course some code may have caught the original exception and thrown their its own exception, which has the effect of obscuring the original stack trace. Not sure how common this still is in the Java world, but back when I was doing plain old Java it was an all to common thing to do in Java libraries.
I need some help interpreting part of the description of agent semantics on http://clojure.org - I'd welcome comments here. Here's the quote in question: > The actions of all Agents get interleaved amongst threads in a thread pool. At any point in time, at most one action for each Agent is being executed. Actions dispatched to an agent from another single agent or thread will occur in the order they were sent, potentially interleaved with actions dispatched to the same agent from other sources.
my question is about the last sentence and what it means for actions dispatched from 2 separate sources to be interleaved
I've been assuming that a single action runs until it is finished before yielding to another, regardless of the source
and I'd like it if that second sentence really means that given sources A and B, actions dispatched from both may be executed thus: A1 B1 A2 B2 A3 B3 etc
what I wouldn't like (which would cause me to rethink some things anyway) would be for actions A1 and B1 to be non-atomically interleaved
anyone got the truth to hand? If not, I'll write some kind of experiment later today to figure it out
actions from send or send-off are enqueued to be applied to an agent and can be interleaved. Each particular send or send-off function runs atomically. There will never be more than one thread applying an action on an agent at one time.
@alexmiller so does that mean that the A1 action (by my understanding, a function) may be partially executed, then paused, and B1 partially executed, paused, and then A1 completed?
A1 will complete, then B1
there is no “partial”
is it true that defn- is considered not a good idea? wondering why if that's the case
@squarenegative This is an educational thread about private definitions https://groups.google.com/forum/#!topic/clojure/NolgUR4KLis
In particular, @alexmiller said "At one point all of the current metadata niceties didn't exist (used to be #^{:private true}
some may recall) and defn-
seemed worth doing I presume (pre-dates my involvementT). But then that was all simplified down to just ^:private
and it's preferred to compose the pieces rather than copy N things."
@krukow Incanter 1.9.2 was released last month. It is true that for a period it saw very little development, but it is usable.
There are a couple libraries that were recently mentioned in the #data-science channel.
I hit an interesting edge case with logging and macros, overcame it, and blogged about it: https://medium.com/@hlship/macros-meta-and-logging-575d5047924c
the 1.9 command line tools look interesting; we may be able to get rid of boot in some cases, except for the uberjar creation: can you make an uberjar with the clojure
tool?
thanks @sundarj, looks great
@sundarj i've also been pointed to http://github.com/juxt/pack.alpha which looks similar