Clojurians
# beginners

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

vinai 00:18:30

@gamecubate Interesting little problem. My attempt looks like this: ``` (def my-string "a b (c d)")

((fn to-keywords [a] (if (coll? a) (map to-keywords a) (keyword a))) (read-string (str "[" my-string "]"))) ```

vinai 00:19:24

I had to surround the string with [ and ] or some other thing to make it a data structure, and then the reader works okay.

vinai 00:19:41

(:a :b (:c :d))

seancorfield 01:35:50

FYI, read-string isn’t safe to use on arbitrary input since it can execute code. Consider clojure.edn/read-string instead.

gamecubate 05:34:26

@seancorfield The cljs compiler (boot_cljs) is somehow not able to locate that namespace. Is it part of some package one must require in build.boot (this is for a CLJS project)?

vinai 07:17:45

@seancorfield Thanks, good to know!

mruzekw 20:15:27

I’m trying to require a macro from sablano into a cljc file. It loads in CLJS but not in CLJ

mruzekw 20:15:57

(ns app.ui (:require [rum.core :as rum] [sablono.core :refer-macros [html]]))

mruzekw 20:16:11

It keeps saying that it can’t resolve html

sbauer 20:39:47

does [sablono.core :as html :refer-macros [html]] result in anything different?

carly 20:48:43

you could try
#?(:cljs :require-macros [sablono.core :as [html]])

vinai 21:30:43

In the namespace foo-bar.core I've got (defrecord Baz [left right]).
In another namespace foo-bar.core-test I want to check for membership using (instance? Baz a).
I've added the import to the ns macro (ns foo-bar.core-test (:import [foo_bar.core Baz])),
But the check with instance? fails because a is a foo_bar.core.Baz, not a Baz.
Is there a way to import a record type so I don't have to specify the fully qualified name?

mtkp 21:55:26

@vinai huh, that is suprising... Baz should map to foo_bar.core.Baz when imported as you have. how is a defined?

vinai 22:22:10

@mtkp a is defined by a factory function in foo_bar.core

mfm 23:55:13

i have a list of files stored in an atom like this:
user> (take 5 @g) (#object[java.io.File 0x593890b8 "dest/file0"] #object[java.io.File 0x33e303d8 "dest/file1"] #object[java.io.File 0x2fb5d0a2 "dest/file10"] #object[java.io.File 0x5ea35c6d "dest/file100"] #object[java.io.File 0x4303ba51 "dest/file1000”]) and i want to delete some files, but it looks like delete-file accepts a string, not a file object. I see that this works:
user> (delete-file (str (.getParent (first @g)) "/" (.getName (first @g)))) true
I can tolerate this, but i get the feeling that there’s a better way than re-deriving the file path and file name. it’d be great if there was a delete-file for file objects.