Fork me on GitHub
#clojure
<
2022-10-23
>
jaide03:10:40

With clojurescript macros, does that mean they can access java APIs during compile time? For example an asset macro that uses the java io apis to copy a file to an assets dir and returns a hashed file name string in place?

👍 1
jaide03:10:51

Oooh perfect. Thanks!

jaide01:10:31

That helps a lot. Thanks!

Yehonathan Sharvit08:10:52

Is there a pure Clojure library to check whether a string is a valid IPV6?

hifumi12321:10:04

You can likely come up with a regular expression to detect this and simply use re-matches . But this will get complicated fast and super hard to debug. I recommend just using Apache Commons Validator. It is battle tested library and easy to invoke from Clojure. When I write specs for data that need to be valid e-mail addresses or IP addresses, I always use Commons Validator. It's as easy as adding [commons-validator "1.7"] in your project.clj and then using any of the classes in org.apache.commons.validator.routines.*.

ami05:10:25

you have my thanks as well.

Martin Jul09:10:54

Alternatively, what about using the IP6 parsing in the Java standard library: (.InetAddress/getByName x) raises an exception if x is not a valid address and you can check if it returns a java.net.Inet6Address - see docs for limitations of how it defines "valid"

vemv13:10:48

doesn't sound crazy, since the docstring specifies: > If a literal IP address is supplied, only the validity of the address format is checked.

hifumi12316:10:29

Be careful using InetAddress! While it may work, the description of the javadoc seems to suggest it performs DNS lookups, since its intended to resolve the IP address of hosts. And a quick Google search brought me to https://stackoverflow.com/questions/29235689/validate-ipv6-ipv4-address-using-inetaddress stating "if DNS configuration is not valid in our network then validation method takes more time to return result." Commons Validator will just verify a string claiming to be an IPv6 address, but not spend time doing anything else.

Hankstenberg10:10:42

Hi guys, quick question: I would like to write a function that, given a string with the name of a function "e.g. "str", returns the actual function. Is there any way to do that other than eval? The only thing I could think of is to create some kind of "registry" with a cond in it. But maybe there is a better way?

1
borkdude10:10:04

Is a macro also ok?

borkdude10:10:16

else you can also use resolve + symbol

Hankstenberg10:10:44

Hm, I'm not sure. I'd actually like to be able to serialize references to functions that I know will be available at runtime in a certain namespace. I would then like to be able to turn the symbol or string into the actual function.

Hankstenberg10:10:13

Ideally in clojurescript.

borkdude11:10:01

The #C015LCR9MHD interpreter does this using maps of symbols to functions

🙌 1
Hankstenberg11:10:30

Yea, that's what I thought too with the "registry". I'll do it that way then, thanks. 🙂

pppaul17:10:24

would reader macros work for this?

Hankstenberg17:10:56

Oh, interesting idea. I found a solution for cljs now (npm imports are just objects that can be transformed to clj maps, then I can get the functions out and re-transform them into js). But I will need the same for Clojure soon, I'll try it then.

Drew Verlee01:10:25

@URA5DLFM1 wouldn't borkdudes suggestion work?

((-> "inc" symbol resolve)
   1)
  ;; => 2

Drew Verlee01:10:53

oh maybe bc it wouldn't resolve correctly if it wasn't a core function.

Drew Verlee01:10:24

well no, the string has to have the full path to the fn. That's by defination.