This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-08
Channels
- # announcements (1)
- # babashka (28)
- # beginners (13)
- # calva (10)
- # clerk (18)
- # clj-on-windows (39)
- # clj-otel (1)
- # cljdoc (17)
- # clojars (12)
- # clojure (40)
- # clojure-austin (11)
- # clojure-brasil (1)
- # clojure-europe (23)
- # clojure-nl (3)
- # clojure-norway (16)
- # clojure-uk (2)
- # clojurescript (28)
- # clr (4)
- # conjure (1)
- # emacs (14)
- # hoplon (6)
- # hyperfiddle (59)
- # interop (2)
- # leiningen (1)
- # off-topic (37)
- # pathom (1)
- # polylith (5)
- # portal (7)
- # reagent (9)
- # releases (3)
- # shadow-cljs (22)
- # spacemacs (6)
- # tools-build (12)
- # tools-deps (51)
- # web-security (6)
- # xtdb (7)
Is there an alternative to (fn [x] (if x 1 0))
? Nothing wrong with this function just wondering if theres a built-in for coercing a value to 1 or 0 depending on whether its truey or falsey
you can make it more complicated. but that’s a very readable function
(def foo (comp {true 1 false 0} boolean))
. Is more characters and less clear.
Is there any way I can read and write a record? Say for example:
(ns test.core
(:require [clojure.data.xml :as xml]
[clojure.tools.reader :refer [read-string]]))
(read-string (pr-str #xml/element{}))
gives me
#error {:message "No reader function for tag xml/element.", :data {:type :reader-exception, :ex-kind :reader-error}}
#xml/element {}
isn't a record (which have a related but distinct readable format) it is a tagged literal
The doc string for read-string should tell you how to plugin in handlers for different tags
user=> (defrecord F [a])
user.F
user=> (require 'clojure.edn)
nil
user=> (pr-str (->F 1)) ; record printing using literal record syntax
"#user.F{:a 1}"
user=> (read-string (pr-str (->F 1)))
#user.F{:a 1}
user=> (clojure.edn/read-string (pr-str (->F 1))) ; edn reader doesn't support literal records
Execution error at user/eval163 (REPL:1).
No reader function for tag user.F
user=> (defmethod print-method F [o w] (.write w "#foo/bar ") (print-method (into {} o) w)) ; install a method to serialize the record as a tagged literal
#object[clojure.lang.MultiFn 0x6d4a65c6 "clojure.lang.MultiFn@6d4a65c6"]
user=> (pr-str (->F 1))
"#foo/bar {:a 1}"
user=> (clojure.edn/read-string (pr-str (->F 1)))
Execution error at user/eval171 (REPL:1).
No reader function for tag foo/bar
user=> (clojure.edn/read-string {:readers {'foo/bar map->F}} (pr-str (->F 1)))
#foo/bar {:a 1}
user=> (type (clojure.edn/read-string {:readers {'foo/bar map->F}} (pr-str (->F 1))))
user.F
user=>
Is there some way to inspect a tap> (using Reveal, but presuming the question is more generic) and see where in the filesystem it is invoked from?
You can tap>
any data you want, so you could probably write a macro that would invoke tap>
on some data but also pass file/line data obtained by the macro.
In Portal, there's a portal.console/log
macro which "logs" a value using tap>
but also captures the file/line data...
@U04V70XH6 thanks for the link. Your posts keep nudging me towards trying Portal.
probably not the same, but maybe works for you, in #C03KZ3XT0CF you have #tap-stack-trace
, you can put it in front of any form and it will tap the current stack trace, which contains file info and line