beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
Louis Kottmann 2020-11-07T07:45:49.312600Z

Oh I do care, the result is a side effect though (slack message)

Louis Kottmann 2020-11-07T07:46:23.312800Z

I don't keep a reference to the future, nor do I wanna block on it

Jim Newton 2020-11-07T08:27:44.314500Z

I very often get the following genre of error

actual: java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol
 at clojure.lang.RT.seqFrom (RT.java:553)
    clojure.lang.RT.seq (RT.java:533)
    clojure.core$seq__5387.invokeStatic (core.clj:137)
    clojure.core$empty_QMARK_.invokeStatic (core.clj:6206)
    clojure.core$empty_QMARK_.invoke (core.clj:6206)  clojure_rte.genus_spec$eval17078$_spec_to_rte__17079$strip_keys__17105.invoke (form-init10191085421504055651.clj:122) clojure_rte.genus_spec$eval17078$_spec_to_rte__17079$specify__17080$iter__17081__17085$fn__17086.invoke (form-init10191085421504055651.clj:103)
    clojure.lang.LazySeq.sval (LazySeq.java:42)
    clojure.lang.LazySeq.seq (LazySeq.java:51)
    clojure.lang.Cons.next (Cons.java:39)
    clojure.lang.RT.next (RT.java:709)
It seems it would be helpful if the error message would tell me which symbol is problematic. I think this means a destructuring somewhere has failed. If it told me the symbol, then it would be easier to pinpoint in my code. In this case I see the following in the stacktrace. clojure_rte.genus_spec$eval17078$_spec_to_rte__17079$strip_keys__17105.invoke Indeed I have a function spec-to-rte which has a local function named strip-keys defined by letfn. However, I don't see any destructuring in that local function.

Adrian Smith 2020-11-17T22:59:28.414500Z

In the meantime https://github.com/jpmonettas/flow-storm is good at showing you what happened up until the error occurred

Jim Newton 2020-11-07T10:40:58.315900Z

The https://clojuredocs.org/clojure.core/letfn`letfn` says I cannot put :pre and :post conditions on local functions. Is that intentional? I often use :pre conditions while debugging.

Jim Newton 2020-11-12T15:09:04.099Z

@andy.fingerhut good point about experimentation.

Lemonski 2020-11-07T12:02:20.319Z

Hello, i am new to Programming overall i only know a bit JS and mediocre elisp since I am using alot of Emacs for Work. I plan to create a small to medium personal webproject - I dont know if Clojure is suited well for that but where would be a good starting point?

valtteri 2020-11-08T08:39:35.339700Z

Sounds like a nice project. In my opinion there’s no size-limit when “clojure starts to make sense”. Once you grasp the repl-driven workflow and the immediate feedback that comes with it, there’s no going back. 🙂 …or in your case if you once try another kind of approaches, they will probably feel less productive and less satisfying. I’d suggest starting with the frontend (using ClojureScript) because there you actually see the changes as you write the code. Then adding a Clojure backend component for storing the data, creating PDF’s etc. Luminus will probably help you get started fast with the whole stack (clojure backend + clojurescript frontend).

Lemonski 2020-11-08T09:56:08.340100Z

Would you recommend any books? free and non-free?

practicalli-john 2020-11-08T10:03:17.342800Z

@thomasfuston I have a few free books here that I am continually adding too https://practicalli.github.io/

Lemonski 2020-11-08T10:41:54.343500Z

@jr0cket thx for the link and work! I will take a look

practicalli-john 2020-11-08T10:42:45.343700Z

There is a #practicalli channel here if you have any questions about the books

2020-11-07T13:38:17.319100Z

I do not see any mention of pre or post conditions at all in that documentation. It does not say you cannot. It does not say anything about them.

2020-11-07T13:38:46.319300Z

But agree they are absent from that documentation, from which one might guess they cannot be supplied.

2020-11-07T13:39:15.319500Z

It really only takes a minute or two to experiment and see whether they work or not, in a REPL.

2020-11-07T13:40:23.319700Z

In my several-minute experiment, they are supported inside of functions defined within leftfn

✔️ 1
2020-11-07T13:42:05.319900Z

That error can occur with no destructuring occurring, too.

2020-11-07T13:42:27.320100Z

For example:

user=> (seq 'a)
Execution error (IllegalArgumentException) at user/eval184 (REPL:1).
Don't know how to create ISeq from: clojure.lang.Symbol

2020-11-07T13:42:59.320300Z

user=> (filter even? 'a)
Error printing return value (IllegalArgumentException) at clojure.lang.RT/seqFrom (RT.java:557).
Don't know how to create ISeq from: clojure.lang.Symbol

2020-11-07T13:43:30.320500Z

user=> (map identity 'a)
Error printing return value (IllegalArgumentException) at clojure.lang.RT/seqFrom (RT.java:557).
Don't know how to create ISeq from: clojure.lang.Symbol

2020-11-07T13:44:47.320700Z

Note that the symbol in question might not occur in your source code anywhere, e.g. it could be read from input.

valtteri 2020-11-07T15:25:48.322300Z

Clojure works well for web-development. What kind of a project are you planning?

gibi 2020-11-07T18:05:31.328400Z

Hi, I am newbie in Clojure so my question might be very stupid. Suppose thread A wants to set an atom x to 5 and thread B wants to set it to 6. We expect the value to be 5 first and 6 after. Thread A though is blocked and retried after thread B, the value of x would then be 6 first and then 5. How is consistency assured with atom when a retry happens?

sova-soars-the-sora 2020-11-07T18:43:47.329Z

@francesco.losciale what do you mean by threads? i never use forking in clojureland

2020-11-07T18:51:57.329100Z

Compare and set is a common idiom to the point where most processors actually implement an equivalent instruction

2020-11-07T18:52:42.329300Z

The retry is not around the setting, but the entire operation

phronmophobic 2020-11-07T18:52:50.329500Z

why do you expect the value to be 5 first then 6? the atom will ensure that the operations are applied atomically, but I don't see anything in your description that would imply or impose ordering

2020-11-07T18:53:40.329800Z

1. Read value 2. Apply function to get new value 3. Set new value if nothing has changed or go-to 1

sova-soars-the-sora 2020-11-07T18:56:35.330Z

Depends on how much you want to make from scratch and how much you want to use an existing template for... z

sova-soars-the-sora 2020-11-07T18:57:40.330200Z

Luminus, Fulcro, are both options for applications You could also simply start with an http-server like clj/ring or http-kit and then build a website from a basic server with HTTP requests/responses

gibi 2020-11-07T18:59:49.330400Z

I am thinking of a use case in which the state can only be increased, for example. If it changes to 6 and then to 5, the first “thread” might run logic thinking the state is 6.

gibi 2020-11-07T19:00:18.330600Z

Is it implied the functions that change the state are always commutative?

phronmophobic 2020-11-07T19:05:40.330800Z

oh, ok! here's the equivalent code

(def x (atom 4))

;; on thread A
(swap! x inc) 

;; on thread B
(swap! x inc)
it's guaranteed that the value in the atom x, will be 5 and then 6, but it's not guaranteed which thread will have its operation completed first. as @hiredman said, atoms use CAS to ensure consistency. the wikipedia page has a decent explanation, https://en.wikipedia.org/wiki/Compare-and-swap

phronmophobic 2020-11-07T19:07:40.331200Z

you can find clojure's implementation https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Atom.java#L34

public Object swap(IFn f) {
	for(; ;)
		{
		Object v = deref();
		Object newv = f.invoke(v);
		validate(newv);
		if(state.compareAndSet(v, newv))
			{
			notifyWatches(v, newv);
			return newv;
			}
		}
}

👍 1
greg 2020-11-07T22:13:46.335700Z

Hello, I'm starting the book Programming Clojure by Alex Miller. I'm trying to run (require '<http://clojure.java.io|clojure.java.io>') . I've started a repl using the lein repl command. I know little about Java and the error I'm getting hasn't been useful so far. Here's the error:

Could not locate clojure/java/io'__init.class, clojure/java/io'.clj or clojure/java/io'.cljc on classpath.
I'd also like to run the example from the code samples that can be found here: http://media.pragprog.com/titles/shcloj3/code/shcloj3-code.zip. (require 'examples.introduction') gets me a similar error. How can I fix this error?e

2020-11-07T22:17:27.336600Z

No single quote after http://clojure.java.io

2020-11-07T22:17:55.337200Z

It is not a string, but a symbol. A leading single quote in Clojure means that the following expression should not be evaluated.

greg 2020-11-07T22:18:14.337400Z

Thank you so much!