Fork me on GitHub
#beginners
<
2017-04-09
>
zcassini01:04:03

if anybody is looking for more clojure katas to learn from I just ported the first set of 16 javascript katas from http://freecodecamp.com to clojure and put them on codewars at https://www.codewars.com/collections/unofficial-fcc-challenges-basic-algorithm-scripting

samueldev21:04:12

Hey folks! I'm trying to write my first macro to get rid of some boilerplate

samueldev21:04:23

And I'm running into some confusion

samueldev21:04:32

what I have so far (just testing some stuff)

samueldev21:04:36

(defmacro def-sdk-fn [name spec body]
  `(defn ~name
     ([& args]
      (if true
        (e/wrong-number-of-args-error)
        (js/console.info "lawl")))))

samueldev21:04:49

Produces the error: ERROR: Can't use qualified name as parameter: cxengage-javascript-sdk.macros/args at line 15

samueldev21:04:59

I'm not sure what it means by qualified names in this context

noisesmith21:04:00

you need to use args#

noisesmith21:04:07

` tries to fully qualify things

noisesmith21:04:21

ugh - the bot interprets too much - the input was

`(foo)

samueldev21:04:50

okay I think that was a missing link in my head! thanks @noisesmith, works great now

noisesmith21:04:12

what args# does is generate a temporary local symbol that will be unique

noisesmith21:04:27

(but match another usage of args# in the same scope)

samueldev21:04:07

which is something I'll need to do whenever needing to output function arguments in a macro

samueldev21:04:14

like my case, a macro that generates a defn

noisesmith21:04:16

or let bindings

noisesmith21:04:19

or loop bindings

noisesmith21:04:30

or for bindings, etc.

samueldev21:04:00

@noisesmith I just had to do some let bindings and same deal, makes more sense now. thanks.

samueldev21:04:18

I'm wanting to call a cljs fn inside my macro... does the cljs namespace have to be a cljc namespace in order for that to be possible?

noisesmith21:04:13

you can use reader-macros for clj/cljs in a cljc file - but remember a macro doesn't have to find the thing it compiles to, it just needs to emit the right forms

noisesmith21:04:52

it's neccessary that the thing the macro refers to exist when it is expanded though, or you'll get a compiler error

samueldev21:04:38

so I just need to quote it

samueldev21:04:10

` = quote? or unquote

samueldev21:04:13

anyway I needed `

noisesmith21:04:35

` is syntax-quote, ' is quote, and is unquote and @ is unquote-splicing

samueldev21:04:41

thanks! back to brave-clojure for a bit for me, so I can try and not gloss over those details this time.. ><

polymeris22:04:01

Hi. Is there no thrown?/`thrown-with-msg?` in cljs.test?

polymeris22:04:00

it's mentioned in the documentation of the ns and of the is macro

polymeris22:04:23

maybe I am requiring it wrong?

noisesmith22:04:29

@polymeris works for me in 1.9.482

+cljs.user=> (t/is (thrown? js/Object 1))

FAIL in () (at evalmachine.<anonymous>:14:4)
expected: (thrown? js/Object 1)
  actual: nil
nil
+cljs.user=> (t/is (thrown? js/Object (throw (js/Object.)))
+       #_=> )
#js {}

noisesmith22:04:04

you can't require thrown? - it's a special syntax of is, it isn't defined anywhere

noisesmith22:04:43

(well it's defined as part of the is macro, but isn't bound anywhere, is what I mean)

polymeris22:04:14

was trying to do :refer [thrown-with-msg?] or :refer-macros [thrown-with-msg?]

polymeris22:04:27

didn't even try to leave that out