This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-23
Channels
- # announcements (3)
- # aws (2)
- # babashka (31)
- # beginners (14)
- # calva (14)
- # cider (4)
- # clj-kondo (1)
- # clojure (24)
- # clojure-europe (18)
- # clojure-gamedev (4)
- # clojure-nl (3)
- # clojure-norway (23)
- # clojurescript (24)
- # core-typed (23)
- # data-science (9)
- # datomic (1)
- # emacs (15)
- # events (4)
- # gratitude (3)
- # introduce-yourself (1)
- # leiningen (9)
- # lsp (65)
- # membrane (39)
- # music (1)
- # nbb (1)
- # obb (8)
- # reitit (17)
- # releases (1)
- # tree-sitter (2)
- # vim (28)
- # xtdb (3)
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?
example macro of this style: https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/resource.clj#L53
Is there a pure Clojure library to check whether a string is a valid IPV6?
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.*
.
Thank you @U0479UCF48H
Alternatively, what about using the IP6 parsing in the Java standard library: (
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"
doesn't sound crazy, since the docstring specifies: > If a literal IP address is supplied, only the validity of the address format is checked.
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.
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?
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.
Ideally in clojurescript.
Yea, that's what I thought too with the "registry". I'll do it that way then, thanks. 🙂
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.
@URA5DLFM1 wouldn't borkdudes suggestion work?
((-> "inc" symbol resolve)
1)
;; => 2
oh maybe bc it wouldn't resolve correctly if it wasn't a core function.
well no, the string has to have the full path to the fn. That's by defination.