Fork me on GitHub
#beginners
<
2019-04-05
>
Kamuela01:04:22

Thanks @manutter51, I notice that cmd + shift + L doesn't seem to work

Kamuela01:04:56

It's listed as a command but nothing happens when I do it. And regarding a context menu, can't seem to find anything about REPL stuff, if by that you mean right click

seancorfield01:04:37

@kamuela I think alt + shift + L on Windows/Linux would be opt + shift + L on Mac (not cmd) -- but I'm not a Cursive user so... Also, there's a #cursive channel where I believe folks are pretty active in help other Cursive users.

seancorfield01:04:13

Looks like I'm wrong -- https://www.cheatography.com/pupeno/cheat-sheets/cursive-on-mac-os-x/ -- that surprises me, based on my experience in other editors, but there you go.

seancorfield03:04:24

I was wrong -- https://www.cheatography.com/pupeno/cheat-sheets/cursive-on-mac-os-x/ -- just shows that different editors behave very differently across platforms @kamuela 🙂

yuhan10:04:17

Trying to follow the instructions for tools.deps to use a local dependency: https://clojure.org/guides/deps_and_cli#_using_local_libraries

yuhan10:04:35

but it fails with the error

Error building classpath. Manifest type not detected when finding deps for clojure2d/clojure2d in coordinate #:local{:root "/Users/yuhan/Github/clojure2d"}

yuhan10:04:34

must the dependency also be required to use a deps.edn config? This one happens to be using Lein with a project.clj

alexmiller11:04:40

Yeah, that’s not supported

yuhan12:04:09

Thanks - I got it to work by running lein uberjar and pointing to the local jar instead.

Kamuela11:04:25

I'm trying to print the result of (verse i) as I go from start to 0, is this even the right approach?

Matheus Moreira11:04:20

it seems that you want dorun or doall.

Matheus Moreira11:04:03

for is a “list comprehension”, a kind of combination of map, flatmap, filter in a more straightforward way.

manutter5112:04:42

In Clojure there are 2 main ways to iterate: doseq and for. for returns a lazy seq, which means the iteration doesn’t happen until you “realize” the result in some way. The REPL always realizes the result, so you won’t notice the difference at the REPL, but as soon as you use for in some actual code, you may be saying, “Why isn’t it printing anything?”

manutter5112:04:24

The main purpose of for is to take a list, and return a modified list. doseq on the other hand, takes a list and does something to each item in the list, like printing.

manutter5112:04:23

(doseq [i (range 4)]
       (println i))
0
1
2
3
nil
app:cljs.user=> 

manutter5112:04:35

The numbers 0 thru 3 are the side effect of using doseq, and the nil at the end is the result of doseq. Every function in Clojure returns something, and so doseq returns nil.

ok13:04:42

weird that we can destructure in let but not in def 🤔

dpsutton13:04:29

what would be an example usage? you'd like to def multiple things at once?

dpsutton13:04:49

(def [a b] (range 2)) kind of thing?

ok13:04:47

(def [a b] [1 2])

ok13:04:20

(let [[a b] [1 2]] (prn a b)) but this is fine

bronsa13:04:42

you can write a macro that does it

ok13:04:22

@bronsa but is could be part of the language easily...

bronsa13:04:43

it's very rare that you need it

bronsa13:04:28

and the semantics of def are significantly different than let, so from a philosophical point of view destructuring in def doesn't make as much sense as in let

Matheus Moreira14:04:32

i want to write a defmulti that validates different kinds of “components” of my application. the definition is: (defmulti validate-definition (fn [definition user-id] (:component/type definition))).

Matheus Moreira14:04:30

i saw that multi-spec can be used to return a different spec for a different return of the dispatch function, but in my case my validation function performs more validation than would be possible only with spec (e.g. call an external service to check if a resource exists).

Matheus Moreira14:04:03

is there a way to combine my defmulti with multi-spec or other thing that would allow me to perform basic validation of input data with spec and more specific validation on code?

chocksmith15:04:55

I do really need some help here. I am getting a segmentation fault: # # A fatal error has been detected by the Java Runtime Environment: # # SIGSEGV (0xb) at pc=0x000000010e54ef9a, pid=64230, tid=16643 # # JRE version: Java(TM) SE Runtime Environment (8.0_60-b27) (build 1.8.0_60-b27) # Java VM: Java HotSpot(TM) 64-Bit Server VM (25.60-b23 mixed mode bsd-amd64 compressed oops) # Problematic frame: # V [libjvm.dylib+0x14ef9a]RUNNING Have anyone out there faced this kind of error? What situations might trigger a segmentation fault in Clojure or in Java/Clojure interoperability?

seancorfield15:04:37

@rodrigo759 It's possible that you've hit a bug in the JVM -- it does happen -- Do you get this every single time you run your program? Do it happen when you do something specific in your project?

chocksmith15:04:44

That's what is driving me crazy. It happens on the second time my routine is called via webserver. It does NOT happen if I put a breakpoint there and run it step by step. It makes no sense.

seancorfield15:04:35

What sort of project is this? Java calling (compiled) Clojure? Pure Clojure? How are you running it? Is there a project.clj file you can share?

chocksmith15:04:35

I have a grails server that call my routine. First time runs OK. Second time breaks. If I put a breakpoint and stop on the call and run it step by step, it does not throw segmentation fault.

seancorfield15:04:50

Ah, so Java calling (compiled) Clojure?

chocksmith15:04:37

It is a huge project written in Grails/Groovy, Java and Clojure. Yes... A Groovy service calls Java/Clojure routines.

seancorfield15:04:41

That's going to be really hard to debug I suspect 😞

chocksmith15:04:01

I've been trying for more than 2 days.

chocksmith15:04:09

I tryied to write integration tests to reproduce the error but I failed. I call my routine hundreds of times and it works. It only breaks when It is called from the front-end using a Grails service. Then I suspect that it has something to do with threads.

chocksmith15:04:45

When I realized that I does NOT break when I run step-by-step after a breakpoint, it blew my mind.

seancorfield15:04:04

Can you share the full segfault output in a Gist? Just in case there's something in there that might trigger an idea from someone...

chocksmith15:04:45

It writes a log file. I will attach it. Hold on.

chocksmith15:04:29

Full segmentation fault log file

seancorfield15:04:00

Can you try running it with this JVM option removed: -Xverify:none

chocksmith16:04:24

You mean to include -Xverify:none ? Or to remove from the current call?

seancorfield16:04:42

It prevent bytecode from being verified so you could be trying to run invalid bytecode. Without that option, you might get a validation error from a compiled class which would get you closer to the root cause.

chocksmith16:04:44

It seems it is not there already. Have you seen something that make you think that it is there?

seancorfield16:04:25

It's shown in the JVM dump. Along with lots of Grails-related options

seancorfield16:04:52

jvm_args: -Dendpoints.shutdown.enabled=true -Denv=development -Dfull.stacktrace=false -Dgrails.env=development -Dgrails.full.stacktrace=false -Dinfo.app.grailsVersion=3.3.9 -Dinfo.app.name=server -Dinfo.app.version=0.1 -Djdk.reflect.allowGetCallerClass=true -Drun.active=true -Dspring.output.ansi.enabled=always -Dspring.profiles.active -Dspringloaded=inclusions=grails.plugins..*;synchronize=true;allowSplitPackages=true;cacheDir=/Users/rodrigo/Nitryx/Technical/Projects/braskem/brkm_app/server/build/springloaded -Dverbose=false -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -XX:CICompilerCount=3 -agentlib:jdwp=transport=dt_socket,address=56606,suspend=n,server=y -javaagent:/Users/rodrigo/Library/Caches/IntelliJIdea2018.3/captureAgent/debugger-agent.jar -javaagent:/Users/rodrigo/.gradle/caches/modules-2/files-2.1/org.springframework/springloaded/1.2.8.RELEASE/b60bac05b0451cdc1863bfec617f39aa0dcaaa43/springloaded-1.2.8.RELEASE.jar -Xverify:none -Xms768m -Xmx768m -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant 
java_command: brkm_app.Application

seancorfield16:04:31

Whatever you're using to run your program is adding it in.

seancorfield16:04:36

and what is this class

Current CompileTask:
C1: 509202 15348       1       com.nitryx.brkmopt.util.ClojureHandler::k (123 bytes)

chocksmith16:04:17

This is a helper class I wrote. I can share it:

chocksmith16:04:58

I am looking for where to remove -Xverify:none

seancorfield16:04:27

It looks like it's failing try to compile or do something with the com.nitryx.brkmopt.opt.utils/k function but I'm not sure what the code in the stacktrace relates to...

V  [libjvm.dylib+0x14ef9a]  ValueStack::pop_arguments(int)+0x6c
V  [libjvm.dylib+0xf4941]  GraphBuilder::invoke(Bytecodes::Code)+0xae5
V  [libjvm.dylib+0xf6f61]  GraphBuilder::iterate_bytecodes_for_block(int)+0x2449
V  [libjvm.dylib+0xf382d]  GraphBuilder::iterate_all_blocks(bool)+0x6f
V  [libjvm.dylib+0xf7d21]  GraphBuilder::GraphBuilder(Compilation*, IRScope*)+0x2cd
V  [libjvm.dylib+0xfd1f6]  IRScope::IRScope(Compilation*, IRScope*, int, ciMethod*, int, bool)+0x154
V  [libjvm.dylib+0xfd2a7]  IR::IR(Compilation*, ciMethod*, int)+0x85
V  [libjvm.dylib+0xe849f]  Compilation::build_hir()+0xa7
V  [libjvm.dylib+0xe862e]  Compilation::compile_java_method()+0x58
V  [libjvm.dylib+0xe8857]  Compilation::compile_method()+0x6d
V  [libjvm.dylib+0xe8a6c]  Compilation::Compilation(AbstractCompiler*, ciEnv*, ciMethod*, int, BufferBlob*)+0x1a2
V  [libjvm.dylib+0xe91ee]  Compiler::compile_method(ciEnv*, ciMethod*, int)+0x90
V  [libjvm.dylib+0x1b55e6]  CompileBroker::invoke_compiler_on_method(CompileTask*)+0x5b2
V  [libjvm.dylib+0x1b7b2d]  CompileBroker::compiler_thread_loop()+0x291

chocksmith16:04:07

I wrote this method k() to convert java objects in clojure Keywords. It is used millions of time before breaking. And why it just works when I run in debug mode, step by step? 😰😱

seancorfield16:04:29

You're using a pretty old JVM 1.8.0_60-b27), built on Aug 4 2015 -- this may be a JVM bug that has been fixed since then. I would definitely try updating your JVM as a first line of debugging.

chocksmith16:04:01

It also breaks on the Tester's machine running a newer version. I will upgrade! anyway

seancorfield16:04:12

(I Bing'd irscope graphbuilder and got a bunch of segfault results pointing to bugs in the JDK)

chocksmith20:04:38

@seancorfield running with -client (disabling server hotspot strategies) and -XX:CompileCommandFile=.hotspot_compiler excluding my ClojureHandler class, works. But runs super slooooow.

chocksmith20:04:46

It must be a JDK1.8 bug. I will try to find another workaround without using the -client option because it dramactically decreases the performance. I am stuck to 1.8 due to Grails 3.

seancorfield20:04:40

Are you still hitting the bug with the most recent JDK 1.8? Have you tried both Oracle JDK and OpenJDK versions?

chocksmith21:04:56

I upgraded to the most 1.8 version and the bug still there.

chocksmith21:04:49

I must use Oracle JDK... I found a combination of methods exclude from Hotspot that worked with Server Hotspot. Some methods not related to Clojure at all. @seancorfield Thank you very much for your assistance.

seancorfield22:04:45

@rodrigo759 So you got it all working? Excellent!

seancorfield22:04:53

Edge case stuff like this in the JVM can be really frustrating. In the roughly nine years I've been at my current work place I think we've run into maybe three or four JVM bugs and had to switch up versions or vendors of stuff in our stack... 😐

ackerleytng23:04:22

hi! was trying to improve my repl workflow with alembic... after adding [alembic "0.3.2"] to profiles.clj, emacs is able to autocomplete alembic.still while in the user namespace, but when i do (alembic.still/load-project), i get classnotfoundexception ... alembic.still

ackerleytng23:04:02

is there a way to set it up so that i don't have to require alembic each time?

noisesmith23:04:16

you can add a require of alembic.still to your user.clj or your project.clj injections

ackerleytng23:04:54

i see, thanks!