Clojurians
#cljs-dev
<
2016-08-31
>

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

shaunlebron05:08:52

@juhoteperi: they’re not inherently compatible, but babel or webpack takes care of the differences so ES6 import syntax works for commonJS modules, and probably others

richiardiandrea23:08:06

I have a problem that I can't seem to solve and maybe it has already been adressed. Let's say I have a .cljc file with:

(defmacro safely
  "Evaluates expr within a try/catch and returns the result.

  If present, in case of errors it executes (ex-handler ex), a function
  that accepts the exception, returning its value.
  If the ex-handler is not present it just returns the exception.

  The exception is always printed with TRACE log level."
  [expr & [ex-handler]]
  (let [ex-sym (gensym)]
    `(try
       ~expr
       (catch #?(:clj Throwable :cljs :default) ~ex-sym
           #?(:clj (clojure.tools.logging/trace ~ex-sym "safely wrapped")
              :cljs (adzerk.cljs-console/trace ~ex-sym))
           ~(if ex-handler
              (list ex-handler ex-sym)
              ex-sym)))))
When I :require-macros the :clj part of the reader conditional is resolved BUT I have strict classpath isolation in my project and I do not have clojure.tools.logging in the frontend so an error is triggered

richiardiandrea23:08:37

I understand why the :clj part at the moment is evaluated where :require-macros is in place, I don't even know why I am raising this issue, maybe I would love to see only the :cljs part evaluated when Clojurescript files are in play...I know I know not possible at the moment :smile:

darwin23:08:30

@richiardiandrea: hmm, what happens when you do :require :refer… (aka implicit refer) from cljs?

anmonteiro23:08:13

@richiardiandrea I don’t think you can use reader conditionals in macros like that

anmonteiro23:08:31

it might be better to conditionalize the macro itself

anmonteiro23:08:43

based on e.g. the existence of (:ns &env)

richiardiandrea23:08:49

@darwin WARNING: Wrong number of args (2) passed to aprojectt.utils/safely at line 6 test/common/aprojectt/utils_test.cljc

richiardiandrea23:08:05

with (require [aprojectt.utils :as utils :refer [safely]])

richiardiandrea23:08:25

@anmonteiro oh that's a neat trick

darwin23:08:26

ok, it treats it as a function, not as a macro

richiardiandrea23:08:46

that above trick might work though

richiardiandrea23:08:27

@anmonteiro you are right I assumed I could and I knew it was a shot in the dark

richiardiandrea23:08:08

the problem does not really go away because at the top of my .cljc file I have a:

(:require 
  #?(:clj [clojure.tools.logging])

richiardiandrea23:08:20

that gets evaluated anyways

richiardiandrea23:08:49

I could remove it and force a require from client code

richiardiandrea23:08:46

it feels hackish (and maybe it is :))

darwin23:08:02

maybe you could require it dynamically in clj case?