Fork me on GitHub
#clojure
<
2017-11-18
>
lvh00:11:27

Does anyone know about any prior art re: using specs for autocomplete? e.g. I have a query language and an in-browser text box, [:a :b :c (|)] where | is the cursor, spec “knows” that there are only a handful of things that can meaningfully go there

lvh00:11:31

the closest I’ve found is expound

lvh00:11:13

maybe spec isn’t really the best tool for this since the set of answers can change at runtime there; I don’t necessarily know the full spec for the query language ahead of time, people can define their own helper rules

hiredman00:11:10

I know you have some core.logic experience, have you tried that? it seems like something like that would sort of be like type inference, like you want a list of possible things (|) could be, and there are constraints on what it could be based on what is around it (or just what precedes it)

qqq00:11:03

@lvh @hiredman: I was recently looking at a similar problem. Given 1. a CFG and 2 a prefix of a string ... what are all valid possible next-letter or next-2-letter or next-word combos? Turns out, https://en.wikipedia.org/wiki/Earley_parser can handle that.

lvh00:11:05

@hiredman huh that’s an interesting suggestion; I hand’t considered that but sure I could probably hack together some HM type inference in core logic 🙂

lvh00:11:51

it just seems that spec mostly has that information already but I guess maybe it doesn’t exactly

hiredman00:11:42

I am not sure spec would work directly, mainly because spec doesn't support partial parses(regardless of if you could get the information about what would complete the parse from the parser), but you might be able to walk a spec via s/form and generating the core.logic "typing" rules from it

qqq00:11:50

Is there a reason to not use an Earley Parser? It can literally tell you what values are valid for next token.

hiredman00:11:20

any parser will have that information

hiredman00:11:32

it just depends on if you can get at it

hiredman00:11:16

grammars tend to be thought of as recognizers of languages, but they are also recipes that can be used to generate strings that are members of a language

hiredman00:11:45

the parsing with derivatives stuff spec's parser is based on seems like it would be really good for that stuff, but spec doesn't do partial parses, and finding some protocol for communicating where you want the parse to stop, and how you when to generate possible completions of the parse might be tricky

qqq00:11:04

@hiredman: really? I thought for most parsers, on incomplete strings, it's okay to just barf and say "this fails somewhere"

qqq00:11:37

Earley one of the few parsers I know of where the algorithm makes it blatantly clare what values are valid for next token give current prefix

qqq00:11:56

In particular, I believe this is one of the main advantages of Earley over CYK or Packrat for parsing CFGs.

hiredman00:11:47

that is just because most other parser libraries don't provide meta information about the structure of the grammar they represent

hiredman00:11:04

the information is encoded in the structure of the parser, but it is hard to get at it

qqq00:11:25

I'm not convinced that is true, but I can't disprove it either.

qqq00:11:58

Is there a way to get the validator function of an atom ? I'm trying to create a spec that asserts: this atom has the following validator functikon.

qqq01:11:11

why is atom in core, but atom? in clojure.inspector ? https://clojuredocs.org/clojure.inspector/atom_q Is there some other way I should be checking if an object is an atom ?

tanzoniteblack01:11:14

#(instance? clojure.lang.Atom %) ?

sova-soars-the-sora02:11:08

anybody use clojure or clojurescript to write iOS apps that use the audio engine? I'm interested to see if I can port one of my apps to clj/cljs

qqq03:11:18

(defn atom? [obj]
  (instance? clojure.lang.Atom obj))
works for clojure. In cljs, how do I check if an object is an atom ?

seancorfield04:11:43

@qqq A guess but I would imagine it'll be a protocol and you can use satisfies? on it...

seancorfield04:11:08

Hmm, no, apparently (instance? Atom obj) -- cljs.core.Atom according to the Replete iOS app.

qqq04:11:32

there's an "IAtom" somewhere in the source, but I wasn't sure how to include it

qqq04:11:39

the full, appearing to work code, in case anyone else wants it, is:

(defn atom? [obj]
  (instance?
   #?(:clj clojure.lang.Atom
      :cljs cljs.core.Atom)
   obj))

Paolo05:11:22

hello all, I'm storing some information on a atom and, in the end, I have this atom data (type data) => clojure.lang.Atom that, when I put @ become (type @data) => clojure.lang.PersistentVector. I need to convert this PersistentVector(ou the original atom) into a json array. Is there a built-in way of doing this?

noisesmith06:11:13

there are two popular json libraries - cheshire and clojure.data.json

noisesmith06:11:19

there's nothing built in

Paolo06:11:14

nothing canonical I could do to avoid add any lib? any loop specific strucutre or somethig?

noisesmith06:11:11

neither the jvm nor clojure itself comes with a json generator, you need a library (even if you write that library yourself, which I don't recommend)

Paolo06:11:21

json is not the problem as I'm using a ring middleware to convert, the problem is that PersistentVector doesn't provide a valid json array, due to the lack of comma or something

Paolo06:11:40

this is my real problem

noisesmith06:11:30

you are using the middleware wrong then

Paolo06:11:32

is there any built-in convertion instruction for persistentVector?

noisesmith06:11:34

the vector is not the problem

noisesmith06:11:55

if commas aren't coming out, you aren't generating json

Paolo06:11:59

if a write { :structures "like that" } a valid json comes out. But { :information any-persistentVector } not

noisesmith06:11:22

that's not my experience of wrap-json at all

noisesmith06:11:28

something else is wrong here

noisesmith06:11:05

(unless there's been a regression and you are somehow the first one to see it)

Paolo06:11:31

well, when I do what I wrote, I got something like {"information": [{:index 0, :data 1} {:index 1, :data 100}] } the problem of commas are related only to vector elements, not every element internally

Paolo06:11:49

I've been trying a lot of conversions the whole day but nothing worked

noisesmith06:11:52

the only way I could see getting that result is if somebody called str on the vector before it was passed to the middleware

noisesmith06:11:11

because the middleware uses a proper json generator that wouldn't do that

Paolo06:11:20

(str @block)
=> "[{:index 0, :data 100} {:index 1, :data 500 }]"

seancorfield06:11:59

@paolocmo here's a REPL session showing that ring-json/wrap-json-response works as expected:

boot.user=> (require '[ring.middleware.json :as json])
nil
boot.user=> (defn handler [req] {:body [1 2 3 4] :status 200 :headers {}})
#'boot.user/handler
boot.user=> (defn app (json/wrap-json-
json/wrap-json-body       json/wrap-json-params     json/wrap-json-response
boot.user=> (app {})
{:body "[1,2,3,4]", :status 200, :headers {"Content-Type" "application/json; charset=utf-8"}}
Note that the response -- the :body -- needs to be a vector not (str some-vector)

seancorfield06:11:16

Don't call str on the vector.

seancorfield06:11:02

Here's another example (using ring.util.response/resp):

boot.user=> (require '[ring.util.response :as resp])
nil
boot.user=> (defn handler [req] (-> (resp/response {:my-vector ["I" "am" "a" "vector"]}) (resp/status 200)))
#'boot.user/handler
boot.user=> (def app (json/wrap-json-response handler))
#'boot.user/app
boot.user=> (app {})
{:status 200, :headers {"Content-Type" "application/json; charset=utf-8"}, :body "{\"my-vector\":[\"I\",\"am\",\"a\",\"vector\"]}"}

Paolo06:11:02

I'm doing something like that:

(defn output-json
  [information]
  {:status 200
   :headers {"Content-Type" "application/json"}
   :body information })

(defn show-data
  []
  (output-json {:length (count @core/data) :chain (str @core/data)} ))

seancorfield06:11:13

Don't call str!

Paolo06:11:24

ok, let me try

noisesmith06:11:30

@paolocmo you are doing exactly the thing I said would cause your bug

Paolo06:11:45

yup, the str. That damn str was driving me crazy

Paolo06:11:53

thank you

seancorfield06:11:54

@paolocmo BTW, welcome to Clojurians! I saw you just joined half an hour ago.

seancorfield06:11:14

Are you new to Clojure? Or did you just find out about us?

Paolo06:11:32

Thank you! And yes, I just found about this slack

Paolo06:11:46

I'm actually from erlang

Paolo06:11:01

joining a clojure project on my work

seancorfield06:11:01

Oh cool. The Functional Prolog LOL 😆

Paolo06:11:18

clojure is awesome

Paolo06:11:37

I'm just having some small issues to get used

seancorfield06:11:37

I did a lot of Prolog back in the day, and I did an Erlang workshop at Lambda Jam a few years ago. Interesting language.

Paolo06:11:08

I work with payment processing in erlang

Paolo06:11:51

is nice, works well and I write new things in LFE(lisp flavored erlang). This led us to start some clojure experiments

Paolo06:11:05

and, well, JVM got my boss heart

Paolo06:11:03

and we are rewriting somethings in clojure, to check if we can go with this

Paolo06:11:14

I rather go with clojure than elixir

Paolo06:11:02

Pure erlang is no longer an option as is not too easy to find programmers

seancorfield06:11:23

And BEAM is an island. The JVM opens a lot more doors.

Paolo06:11:45

yup, this is the main point

Paolo06:11:08

and clojure is nice to code with, you feel productive

seancorfield06:11:23

(don't get me wrong: BEAM is a great island, but I don't know how broad that "church" will ever be... Erlang, LFE, Elixir)

Paolo06:11:49

yup, this is true. BEAM is great, but JVM is a world

seancorfield06:11:14

I've been on the JVM since '97... Java, Groovy, Scala, Clojure... and, would you believe, among all of that: CFML on the JVM too 🙂

seancorfield06:11:25

ColdFusion or the open source engine Lucee

Paolo06:11:56

lol didn't even know there was cfml on jvm

seancorfield06:11:23

Most people don't.

Paolo06:11:51

JVM is battle tested, the banks that we have to interface with use it, so is just natural

Paolo06:11:15

BEAM is good, really really good

Paolo06:11:25

and we have a lot of lobby for elixir here

Paolo06:11:35

as the creator, jose valim, is from here

Paolo06:11:45

I'm from Brazil, btw

Paolo06:11:06

and his company, plataformatec, try to make people use elixir

seancorfield06:11:46

It's late for you in Brazil (or early, depending on how you look at it)

seancorfield06:11:09

10:23pm here in San Francisco

Paolo06:11:17

haha nice

Paolo06:11:51

but is common for us to be online this time at friday/saturday. We grab some beers, go code in a beach or any pool, and this hour we start to fell human again

Paolo06:11:00

I was trying to get some pictires but I'm too drunk lol

Paolo06:11:22

well, thank you guys, see you later. You are awesome

sam1607:11:08

Hello developers, i have now been using spacemacs for my clojure development since last 4 months but there is one feature which i am still not able to configure. That is auto-complete for inbuilt library functions, eg. when i type fil then it should already suggest me filter or any other functions available for it Currently i have installed auto-completion layer in my spacemacs and set (global-company-mode t) which enables dumb auto-complete everywhere that is now when i type anything if that function or variable name is used previously only then it will suggest me, its not smart. I have did alot of research and read ac-cider gives it but it shows now its depricated and i am not able to configure it in my spacemacs. I have been stuggling for this since long now and i am pretty sure someone might have configured this in there setup can anyone help me out.??

scknkkrer14:11:10

How you guys manage Errors and Failures in Clojure. of course in functional way.

drbigdata14:11:31

Anyone in Hong Kong?

borkdude15:11:38

Hmm, why does Clojure accept doubles as array indices? (aget (into-array [1 2 3]) 0.1)

mfikes15:11:22

@borkdude Not an answer to your question, but this is the one last difference that we could ideally patch up in ClojureScript in order to make behavior be consistent. (We can't round down right now without breaking code that is misusing aget by passing property names.)

borkdude15:11:46

That’s exactly where my question comes from (reacting on your twitter announcement)

borkdude15:11:09

I would rather have aget accept strings than doubles 😂

mfikes15:11:38

Yeah, if the entire ClojureScript community used :checked-access then we could conceivably safely fix things by adding an inexpensive operation to round down.

borkdude15:11:09

It’s no big deal switching to goog.object. But why on earth would you pass doubles when you want ints. It seems a bug to me.

mfikes15:11:10

Perhaps the answer is: Clojure only accidentally works on doubles, and it is not the intended API.

mfikes15:11:53

There is a cast to int sitting right in the :inline definition, though, so perhaps it is intentional.

bronsa09:11:03

that's to avoid boxing

bronsa09:11:08

ah, sorry didn't notice I was this back in the scrollback :)

borkdude15:11:04

JavaScript also accepts doubles but interprets them as keys. Another source of confusion: should aget be more like the host or weird behavior in JVM Clojure

mfikes15:11:07

Valid question IMHO

borkdude15:11:50

x = {1.5: 1}
x[1.5] // 1

mfikes15:11:53

I successfully wrote lots of ClojureScript, relying on Clojure's semantics, without ever having learned JavaScript. Perhaps this is an argument for staying away from host semantics when you can.

borkdude15:11:00

Numbers and regexes have host semantics/implementations as well.

borkdude15:11:39

But like I said, it’s no big deal to move to goog.object for objects… just don’t understand the double behavior… maybe it has a reason… 🙂

mfikes15:11:42

Maybe there is no reason for it @borkdude. It could well just be an accident of a change made to avoid reflection https://github.com/clojure/clojure/commit/742619e583400400e69cd46ab9e9536c10afb738

borkdude15:11:59

Hmm, commit message says ‘hints’ indeed…

noisesmith15:11:28

isn't the int cast there so that clojure defaulting to longs doesn't make things inconvenient?

mfikes15:11:01

That's the hypothesis (better support for long, not an intention to support double)

noisesmith15:11:40

without all the int casting clojure does, our code would get ugly with all the long->int conversions we would be doing every time we interact with methods

mfikes15:11:22

So perhaps (aget (into-array [1 2 3]) 0.1) is not correct code and only works as an accident.

borkdude15:11:29

I think so yes

dominicm16:11:17

I was doing some inspection of stacktraces, and I noticed that I don't have clojure/lang/RT.java on the classpath, only clojure/lang/RT.class. Is that normal?

dominicm16:11:26

If it is normal, why is it this way? I have some other java sources on the classpath.

noisesmith16:11:04

why would a java file be on classpath?

noisesmith16:11:15

you can't run it

dominicm16:11:11

@noisesmith I presumed so that tooling could read it, is that not correct?

juhoteperi17:11:31

@dominicm sources are often distributed as separate source jars, to reduce jar sizes

dominicm17:11:19

ah, I've found that jar. Looks like cider has an open discussion about this: https://github.com/clojure-emacs/cider-nrepl/issues/64

dominicm17:11:25

https://gitlab.com/vise890/lein-pocketbook works, even if very verbose. Interesting tool.

byron-woodfork18:11:47

Does anyone have any preferred Clojure libraries/wrappers for working with Apache Kafka?

noisesmith18:11:43

YMMV but I've had the most luck with avoiding clojure bindings as much as possible and using interop, I use a few things from clj-kafka (mostly for creating the objects) and a lot of interop once I have the things to work with

noisesmith18:11:57

@byron-woodfork hi, btw, I think we met at clojure/west for an example of why I avoid clojure bindings, there's a tendency to wrap side effecting IO operations in lazy abstractions, which is a technique that creates more problems than it solves

noisesmith19:11:01

the abstraction of lazy computation over IO is very lossy, you can't ignore the IO so now you have to keep track of two abstractions (the IO abstraction itself, plus the laziness abstraction) and the lazy thing will tend to break things

byron-woodfork19:11:12

:thinking_face: interesting! Yeah, I think I remember meeting you at the conference!

byron-woodfork19:11:47

Those are some things I definitely hadn't thought about or considered. I was trying to weigh using interop vs using an existing kafka library like clj-kafka.

gklijs19:11:03

@byron-woodfork Have not seem one I’m really happy with, but not doing kafka now, but worked on a java library which wrapped the java clients. I almost used it for a pet project so did some research. Most likely I will use the java client. If I would want to to do something with the stream api, I would probably just use java.

noisesmith20:11:43

teng - read takes a stream, you can use it to repeatedly access a stream and get the next form

greg_arcara20:11:48

I haven't used lein in a while and upgraded before I created a new project and am getting errors like this when I try and do lein deps:

Could not transfer artifact enlive:enlive:jar:1.1.6 from/to central (): Connect to  [localhost/127.0.0.1] failed: Connection refused (Connection refused)
Could not transfer artifact enlive:enlive:jar:1.1.6 from/to clojars (): Connect to  [localhost/127.0.0.1] failed: Connection refused (Connection refused)

greg_arcara20:11:15

Any ideas why it's trying to connect to localhost?

noisesmith20:11:15

@teng

(with-open [rdr (->  "clojure/conduit/src/conduit/status_transmitter.clj"       
                    (io/reader)                                                 
                    (java.io.PushbackReader.))]                                 
  (doall                                                                        
   (take-while #(not= ::done %)                                                 
               (repeatedly #(try (read rdr)                                     
                                 (catch Exception _ ::done))))))
((ns conduit.status-transmitter (:require [taoensso.timbre :as timbre] [conduit.kafka :as kafka] [noisesmith.component :as component] [conduit.tools.component-util :as util]) (:import (java.util.concurrent ScheduledThreadPoolExecutor TimeUnit) (java.util Date) ( InetAddress) (java.lang.management ManagementFactory) (javax.management ObjectName))) (defn get-cpu [] (let [mbs (ManagementFactory/getPlatformMBeanServer) oname (ObjectName/getInstance "java.lang:type=OperatingSystem") ls (.getAttributes mbs oname (into-array ["ProcessCpuLoad"])) usages-raw (map (fn* [p1__249#] (.getValue p1__249#)) ls) usage (map (fn* [p1__250#] (/ (* p1__250# 1000) 10.0)) usages-raw)] usage)) (defn get-all-stacks [] (map (fn*...

tengstrand20:11:05

@noisesmith Wow, that worked! Thank you so much! I was surprised that I couldn’t find this anywhere though 🙂

qqq20:11:28

(defstyles media
  (at-media {:orientation :landscape}
            {:html
             {:transform "rotate(-90deg)"}}))

(css media)
(comment
 @media (orientation: landscape) {
  html-transform: rotate(-90deg);
})


@media screen and (min-width: 320px) and (max-width: 767px) and (orientation: landscape) {
  html {
    transform: rotate(-90deg);
    transform-origin: left top;
    width: 100vh;
    overflow-x: hidden;
    position: absolute;
    top: 100%;
    left: 0;
  }
}
how do I inject the 'screen and' into the @media part ?

qqq20:11:05

found it, {:screen true}

greg_arcara21:11:36

any ideas how I can figure out what's going on with my lein? is there a better place to ask?

seancorfield21:11:37

@greg_arcara There's a #leiningen channel -- but you could try your question since a lot of people here use lein...

greg_arcara21:11:28

@seancorfield Thanks, my question is above https://clojurians.slack.com/archives/C03S1KBA2/p1511036688000045 I found the lein channel too and posted there as well

seancorfield21:11:36

Maybe something odd in your ~/.lein/profiles.clj file?

greg_arcara21:11:54

I deleted my .lein folder to try and fix it

seancorfield21:11:00

'k... Do you have any network proxy running or perhaps a firewall that might be messing with things?

greg_arcara21:11:15

nope, I am at home and using a standard ubuntu install

seancorfield21:11:37

Can you get to those repo URLs in a browser on that machine?

greg_arcara21:11:46

curl and chrome both

greg_arcara21:11:10

Connect to [localhost/127.0.0.1] failed: Connection refused (Connection refused) seems unusual to me, but I could be wrong

greg_arcara21:11:19

should it be trying to connect to localhost?

seancorfield21:11:29

Yeah I've never seen that.

greg_arcara21:11:09

proxy env's are all empty

seancorfield21:11:00

Did you try lein repl outside a project folder? (Just to make sure there's nothing odd in your project.clj file)

greg_arcara21:11:12

yes, I did, I tried it from ~/

seancorfield21:11:22

I'm out of suggestions at this point, sorry 😞

greg_arcara21:11:45

no problem, thanks