clojure-dev

M 2023-06-21T00:54:43.646629Z

I am new so forgive me for the blunt question. Where are string literals at?

eggsyntax 2023-06-21T00:58:27.854839Z

I assume you mean something other than

user> "foo"
"foo"
?

M 2023-06-21T01:05:08.102659Z

Yup.

M 2023-06-21T01:06:42.035739Z

JS has a pretty thourough one that includes passing values like a java format call https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

M 2023-06-21T01:07:59.960909Z

But as simple as a string that doesn't need every " escaped would be amazing. If I get a json literal string right now, I have to stick it in a file and slurp or escape every dern " in a different editor.

M 2023-06-21T01:08:36.965969Z

For example from our logs. The json is literal and not escaped.

M 2023-06-21T01:09:30.699359Z

And to clarify literal looks like {"someKey": 1} and not like {\"someKey\": 1}

M 2023-06-21T01:13:06.494729Z

Looks like its mostly denied as a replacement for JS, not just the simple version of being able to grab a string and use it in the repl.

M 2023-06-21T01:13:59.403779Z

I don't care about the JS replacement. It would save me hours a week not having to create a file to slurp in json or edn that isn't escaped.

M 2023-06-21T01:14:20.395769Z

Not exaggerating on the hours number.

2023-06-21T01:15:16.520139Z

user=> (def x (read-line))
 {"someKey": 1}
#'user/x
user=> x
" {\"someKey\": 1}"
user=>

M 2023-06-21T01:15:52.785379Z

Hmm. Ok, this is new to me.

M 2023-06-21T01:16:37.129379Z

Work smarter not harder.

2023-06-21T01:16:47.157089Z

A lot of people don't think about hijacking the repls in/out streams like that, but it is great

2023-06-21T01:17:23.477649Z

Nrepl might not like it, but if you are using the built in clojure repl or some variant of it it works great

M 2023-06-21T01:17:38.544979Z

Different backgrounds, the stdin / stdout stuff isn't as obvious until its said.

M 2023-06-21T01:19:15.635289Z

Not immediately working with Calva / VSCode but I will look deeper

M 2023-06-21T01:19:21.483989Z

Thank for the tip.

2023-06-21T01:20:12.339409Z

Well, that is the other thing, tooling authors don't think about it either and make assumptions that break it

M 2023-06-21T01:23:49.653219Z

Fair

M 2023-06-21T01:24:48.245989Z

Not working with my lein repl either

M 2023-06-21T01:27:30.989289Z

Looks like it does with cli clj

M 2023-06-21T01:37:32.482559Z

ohhh calva works, just not babashka. Randomly that was my only open repl.

đź‘€ 1
M 2023-06-21T01:42:50.350719Z

This covers most of my daily time waste. I would still like to be able to write unit tests without having to escape every dern " but that's less of an issue.

❤️ 1
borkdude 2023-06-21T06:26:28.219189Z

Feel free to file a bug report for bb if there is one

2023-06-21T12:14:01.809079Z

> Nrepl might not like it that works fine in Cider (nrepl)

M 2023-06-21T01:45:22.632049Z

So good chat above. string literals might have a connotation with JS, and don't ever expect that duplication. What about the phrase "unescaped string notation"? Unit tests with large payloads (json or edn) will be so much easier to write if we don't have to go escape every "

Darin Douglass 2023-06-21T02:02:43.750749Z

I’ve never had a use case where I’ve needed super large string payloads in test source code that couldn’t live in resource files on the classpath. Can you put the payloads in resource files instead? Could you just use maps and serialize into the string format before testing?

M 2023-06-21T02:11:11.988049Z

Medium. Just big enough for the escaping to be annoying, but not big enough for a file.

M 2023-06-21T02:13:20.246059Z

Its more like 20-40 responses that are not that large but would need to be escaped.

Darin Douglass 2023-06-21T02:30:39.282449Z

Gotcha, the anti-goldilocks zone. Just right in all the wrong ways

2023-06-21T12:17:52.149449Z

Maybe you can use a tool like http://cljson.com/ and convert your jsons to edn, and then have those payloads as edn in your tests wrapped with (json/write-str edn-payload)

2023-06-21T12:35:46.050769Z

Funny. This whole problem was somewhat confusing to me because Cursive automatically escapes " as you type them. I kind of assumed all paredits did the same.

2023-06-21T12:37:21.549639Z

yeah, same thing happens in emacs with clojure-mode

2023-06-21T12:37:51.481819Z

also if you wrap a json in quotes it will escape them automatically

2023-06-21T12:37:51.875559Z

(It also works when pasting into a string.)

2023-06-21T12:38:59.388019Z