Fork me on GitHub
#clojure
<
2024-02-08
>
rickmoynihan09:02:47

👋 Does anyone know of any free (preferably without signup) clojure/clojurescript/babashka playground environments or REPLs that can easily be parameterised with some code snippets of your choice? I think ideally I’m looking for something light weight like https://tryclojure.org/ but with the ability to preload the REPL with a code snippet e.g. via a query parameter. I basically want to link people to short code snippets for them to evaluate and play with.

rickmoynihan09:02:01

oh this looks good… Not sure I want to give it access to my private gists though

iperdomo09:02:41

@U06HHF230 I didn't login, just visited the page and create a snippet of code

rickmoynihan09:02:12

Are those snippets shareable and persistent?

rickmoynihan09:02:58

@U04V15CAJ: what is the difference?

borkdude09:02:02

2.maria is based on SCI :)

1
1
1
Jacob Emcken10:02:35

I want to cache data fetched by an URL: http:/somedomain.com/path/to/resource?signature=ABC http:/somedomain.com/path/to/resource?signature=DEF I have looked at core.cache and core.memoize I had assumed I could give the full URL (`http:/somedomain.com/path/to/resource?signature=DEF`) and use the part without the "signature" as my lookup key, and then the entire URL to fetch the data on miss. But I can't seem to figure out how to do this without implementing my own CacheProtocol. Have I gotten that right or am I overlooking something? (I would like to write and maintain as little of my own code as possible 😄 )

p-himik10:02:43

With core.memoize, you can use :clojure.core.memoize/args-fn metadata to specify how to derive a cache key from the args.

nice 2
p-himik10:02:48

(memoize/lru (with-meta fetch-from-url
                        {::memoize/args-fn #(remove-sig-from-url (first %))})
             :lru/threshold 1000)

❤️ 1
Jacob Emcken11:02:09

Nice ❤️ thanks

evocatus11:02:38

May I ask for your advice? I give a talk at a Go meetup in my company in April. And the topic is main ideas of the functional programming world. The audience is software developers of various levels the vast majority of which have no first-hand experience seriously using any functional language, most are typical PHP/Python/Java/C# guys who started to use Go not long ago. My plan (for now) is to mostly retell core ideas of Rich Hickey talks (also Stuart Halloway's) like • the value of values • what is PLOP, the danger of it with examples how it hurts us across different domains • how thinking in values naturally brings us to pure functions • how objects are lacking and bring complexity • X-as-a-Code vs X-as-a-Data with the ultimate example of LISP (Code-as-Data) • Data Model > API > DSL (this one is from Stuart Halloway) So I would appreciate you giving advice on all that. Isn't it too much for 40 minutes? Or maybe I'm missing some valuable ideas (not necessarily from Clojure/LISP world bt functional programming in general)?

Robert Todea13:02:35

Sorry for my ignorance, but what is PLOP?

1
Jacob Emcken13:02:51

I also had to look it up... I came to the conclusion it stands for: Principle Of Least Privilege

🙏 1
evocatus13:02:26

It’s “Place oriented programming” a term invented by Rich Hickie

👍 1
evocatus13:02:09

I highly recommend to watch this talk in full (and all others done by him) but here is a link with timecode to the description of PLOP https://youtu.be/-6BsiVyC1kM?t=243&amp;si=TxQNtydII_P_KUz_

Jacob Emcken13:02:27

It is a very worthwhile topic indeed, and I don't think 40 minutes is too much 😄 Time flies when people are having a good time. I guess whether 40 mins is enough or too little depends on your experience - how many times you have explained these things before e.g. in smaller groups or 1-1 Choosing the right words matters to get the points across with as little confusion as possible. The size and composition of the group can also play a part (how many questions/interruptions during the talk) I would order the topics in a way that allows you to skip stuff at the end if times become an issue. Put down a foundation and build up understanding from there (without relying too much on something you should get back to at the end) Also don't be "different" just to be different. Copy what you see works, and add to it where you see fit. I found that immutable data structures are A LOT more important to me than I expected, and I didn't realize this until several years into my Clojure career.

👍 1
Robert Todea14:02:47

I would go with a multi-part approach if you feel it's too much content. Have a series of talks related to the main ideas. But nevertheless, prepare for more material, and cut it afterwards. Also, having live coding is a nice touch to any programming presentation ⌨️ The Clojure REPL is too cool not to showcase everywhere.

👍 1
Omer ZAK15:02:27

I, too, needed to look up PLOP and have no patience for YouTube videos. Google was not helpful, neither was https://en.wikipedia.org/wiki/Plop The most computer-sciencey meaning I found is that PLOP = Pattern Languages of Programs (https://en.wikipedia.org/wiki/Pattern_Languages_of_Programs) and I found no explanation (outside of the video) why it would hurt across different domains. Edit: even the acronym finder did not have Hickey's meaning for PLOP: https://www.acronymfinder.com/PLOP.html

👎 2
mx200016:02:14

Can you send the link/reference for your point *data model > api > DSL? I would be interested in this

evocatus17:02:10

you may start watching at 8:05 but the whole talk is brilliant https://youtu.be/LEZv-kQUSi4?si=ORxy3ZqiDSkehIEZ

mrnhrd17:02:21

I've watched those talks also a lot and have come to the conclusion that some of the remarks are too highlevel (or philosophical/ideological, in a sense) to immediately be obvious and you can talk about each individual one for much longer. Those in Value of values in particular. Imho you will also have to know whether those people already code functionally by convention, or if there actually is rampant mutation present in their programs that VoV was trying to adress.

evocatus17:02:22

@U05N15QDUHX yes, I have the same feeling. Actually my idea was to go over a fictional Go code example showing how we have to read code in order to understand what went wrong with mutable state passed by pointers in place. Essentially we're doing BFS in a graph.

evocatus17:02:25

it was inspired by this diagram in "Narcissistic design" and I would like to make it palpable

Ingy döt Net17:02:13

I need to release a java library to maven central soon. I do have a sonatype account. I've never released to maven central before, but I have released to clojars... Can I get some advice or a good tutorial to help me out with this? (I've looked at it before and releasing to maven central seemed pretty intense compared to releasing libs in other languages...)

jpmonettas17:02:05

I think I never tried, but shouldn't it be the same as Clojars? like : mvn deploy:deploy-file -Dfile=my-lib.jar -DrepositoryId=maven -DpomFile=pom.xml -Durl= having your settings like :

cat ~/.m2/settings.xml

  
    
      maven
      YOUR_USER_NAME
      YOUR_PASS
    
  

jpmonettas17:02:37

nvm, I did some reading and I see there are a couple of other steps involved like signing and then login into Sonatype Nexus Repository Manager

Ingy döt Net19:02:53

@U0739PUFQ well what did you read? Might be of help...

Mark Wardle22:02:26

I do this with one of my libraries and I have written about putting your credentials into your .m2/settings.xml and how to generate a valid GPG key and make it public. See https://github.com/wardle/hermes-api

Mark Wardle22:02:54

Sorry just noticed this was from 8 days ago, so presumably you've sorted already.

Ingy döt Net23:02:56

Hi Mark. I don't have it sorted yet. Mind if I DM you if I need to?

Mark Wardle14:02:53

Of course - or in this thread is fine too.

dpsutton22:02:36

Trying out new 1.12.0-alpha6 following the amazing announcement in https://clojurians.slack.com/archives/C06MAR553/p1707431025302139 . Running into an issue starting up metabase. Details in thread 🧵

dpsutton22:02:36

metabase on  master [$!?] via ☕ v21.0.2 on ☁️  metabase-query took 20s
❯ echo $ALIASES
dev:ee:ee-dev:drivers:drivers-dev:alpha:socket:morse:reveal

metabase on  master [$!?] via ☕ v21.0.2 on ☁️  metabase-query
❯ clj -M:"$ALIASES"
Warning: environ value /Users/dan/.sdkman/candidates/java/current for key :java-home has been overwritten with /Users/dan/.sdkman/candidates/java/21.0.2-tem
WARNING: abs already refers to: #'clojure.core/abs in namespace: clojure.algo.generic.math-functions, being replaced by: #'clojure.algo.generic.math-functions/abs
operator.clj:172 recur arg for primitive local: sum is not matching primitive, had: Object, needed: long
Auto-boxing loop arg: sum
Exception in thread "main" Syntax error macroexpanding at (core.clj:348:14).
and then it hits the stacktrace from above. Running on
❯ java -version
openjdk version "21.0.2" 2024-01-16 LTS
OpenJDK Runtime Environment Temurin-21.0.2+13 (build 21.0.2+13-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.2+13 (build 21.0.2+13-LTS, mixed mode)
. Works without issue when dropping back to 1.12.0-alpha5

dpsutton23:02:01

i’ll dig in some more. The base stacktrace quits listing frames right where it gets good it seems. > ... 234 more

Alex Miller (Clojure team)23:02:41

from the stack trace, looks like pointing to metabase.util.i18n.plural ?

Alex Miller (Clojure team)23:02:16

I guess your first error points to operator.clj loop/recur on sum

dpsutton23:02:12

That’s a warning about type mismatch in the recur. Preexisting and (presumably) not related to this issue

dpsutton23:02:02

repro:

❯ git clone [email protected]:metabase/metabase.git
❯ cd metabase
❯ clj -M:dev:alpha
Warning: environ value /Users/dan/.sdkman/candidates/java/current for key :java-home has been overwritten with /Users/dan/.sdkman/candidates/java/21.0.2-tem
WARNING: abs already refers to: #'clojure.core/abs in namespace: clojure.algo.generic.math-functions, being replaced by: #'clojure.algo.generic.math-functions/abs
operator.clj:172 recur arg for primitive local: sum is not matching primitive, had: Object, needed: long
Auto-boxing loop arg: sum
Exception in thread "main" Syntax error macroexpanding at (core.clj:348:14).
	at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:4076)

dpsutton23:02:36

i have to go walk the dog and then will attempt to debug when back

dpsutton23:02:16

:dev provided by repo :alpha is :alpha {:extra-deps {org.clojure/clojure {:mvn/version "1.12.0-alpha6"}}}

Alex Miller (Clojure team)23:02:20

I see Caused by: java.net.URISyntaxException: Illegal character in path at index 10: whitespace = #'\s+' maybe from https://clojure.atlassian.net/browse/CLJ-2783 change to use a non-deprecated path to make URIs

Alex Miller (Clojure team)23:02:53

plural.clj loads an instaparse grammar, seems like the string "whitespace = #'\s+'" is ending up getting parsed as an uri (not sure exactly how yet)

dpsutton23:02:37

thank you for looking into it. i’ll continue now as well. agree i’m not seeing anything “uri”y in there

dpsutton23:02:47

i can repro without metabase

dpsutton23:02:50

❯ clj -Sdeps '{:deps {org.clojure/clojure {:mvn/version "1.12.0-alpha6"} instaparse/instaparse {:mvn/version "1.4.12"}}}'
Clojure 1.12.0-alpha6
user=> (require 'instaparse.core)
Execution error (URISyntaxException) at java.net.URI$Parser/fail (URI.java:2995).
Illegal character in path at index 10: whitespace = #'\s+'
user=>

dpsutton23:02:21

and there it’s doing

(def ^:private standard-whitespace-parsers
  {:standard (parser "whitespace = #'\\s+'")
   :comma (parser "whitespace = #'[,\\s]+'")})
and the parser function handles lots of different args, including URIs

dpsutton23:02:20

I think it just tries slurping the string to see if it works

(try (let [spec (slurp grammar-specification)]
       (build-parser spec output-format))
     (catch java.io.FileNotFoundException e 
       (build-parser grammar-specification output-format)))
which doesn’t seem like the greatest strategy

Alex Miller (Clojure team)23:02:06

but if we've changed the behavior of slurp, certainly that was not our intent

dpsutton23:02:56

and indeed, changing that strategy to also catch the uri exception allows metabase to startup

(try (let [spec (slurp grammar-specification)]
       (build-parser spec output-format))
     (catch java.io.FileNotFoundException e
       (build-parser grammar-specification output-format))
     (catch java.net.URISyntaxException e
       (build-parser grammar-specification output-format)))
in https://github.com/Engelberg/instaparse/blob/master/src/instaparse/core.cljc#L228-L231

Alex Miller (Clojure team)00:02:25

we will likely just revert CLJ-2783 for now and release an alpha7

dpsutton00:02:51

thank you for looking into this with me. And glad was able to give some alpha feedback

dpsutton00:02:47

a good one for “just remove some deprecated uses. what implications could that have”

Alex Miller (Clojure team)00:02:09

well, we knew about this implication, just didn't mitigate for it enough apparently

dpsutton00:02:46

yeah. i meant for requestors opening a ticket thinking it’s no big deal

dpsutton00:02:25

(not that yall hadn’t throught it through. more for enlightening others how much work goes into even a simple seeming change)

1
Leaf Garland02:02:35

Came to report the same issue. Glad you're already on it.

Alex Miller (Clojure team)02:02:54

1.12.0-alpha7 is now available