Fork me on GitHub
#beginners
<
2015-06-25
>
andrut03:06:47

hey, I want to change the way record works:

andrut03:06:56

(:method record)

andrut03:06:04

which should invoke some method

andrut03:06:06

the closest I can get is

andrut03:06:11

((:method record))

andrut03:06:13

to achieve that, I can just do: (assoc record :method (fn []))

andrut03:06:21

Now, I thought of extending ILookup, but I can't (`extend-type` doesn't work with interfaces)

andrut03:06:32

I also thought of creating a deftype that implements ILookup but then I have to implement Associative as well and it gets pretty nasty...

andrut03:06:36

Any idea how to solve the problem? (or if it's feasible?)

alexmiller04:06:36

well setting aside that I think it's a bad idea to do this in the first place, the recommended path would be to use deftype and implement the necessary interfaces

alexmiller04:06:32

the scaffold macro is helpful to get started with this https://gist.github.com/semperos/3835392

andrut04:06:47

I generally agree it's not the best idea, I wanted to make my API a bit better: instead of writing (-> (find-items countries) (.find-items cities)) I wanted to have (-> (find-items countries) (:cities)) (`find-items` returns a record that I want to modify)

andrut04:06:22

thanks for the scaffold macro... I'm not sure if I want to go this way, it looks too dirty to me

entrobe05:06:19

hey i have a beginner question… what is the difference between

(defmacro one [x] `’~x)
and
(defmacro two [x] x)
… the whole `’~ is confusing me

ergl06:06:10

(macroexpand (one "foo"))
=> user/x
(macroexpand (two "foo"))
=> "foo"

ergl06:06:38

the first one will return the literal namespace-literal definition of x

ergl06:06:50

second one just returns the value of x

entrobe07:06:07

when i run (macroexpand (one "foo”)) i just get ”foo” back. not the user/x

ergl07:06:59

hmm, really?

ergl07:06:32

oops, seems like I forgot a ~ in my macro

ergl07:06:18

you're right, then

andrut07:06:29

the simpliest explanation (though I'm not an expert in the field 😉 ) is that ` is syntax quoting, if you use it, then you have to unquote all the variables you passed in macro

andrut07:06:13

so you can do: (defmacro one [x] (some-function ~x))`

andrut07:06:51

oops, should I write (defmacro one [x] \(some-function ~x))`

entrobe07:06:58

that makes sense to me. but i read it as sytax-quote quote unquote

entrobe07:06:09

i use triple backtick to use backtick in markdown

andrut07:06:16

I don't know how to escape tilde in the code block 😛

entrobe07:06:19

and i don’t really know the use case

entrobe08:06:22

i’m going through joy of clojure book and its used in an example

andrut08:06:10

if you have access to it, there's a really good book called Programming Clojure by Stuart Halloway and Aaron Bedra

andrut08:06:18

macros are explained pretty well there

entrobe08:06:39

simple_smile thx, i have it but read it long ago and forgot everything. will take another look

entrobe08:06:25

although that string

`’~
doesn’t appear in the book 😞

entrobe08:06:43

or the reverse pattern i’ve seen

`~’

andrut08:06:07

you can read the whole chapter but look at the page 169, it's pretty interesting

andrut08:06:44

and about ' symbol - I'm not sure but I think it just doesn't matter, because it resolves to symbol anyway... simple_smile but somebody can correct me if I'm wrong

andrew22:06:05

is there any reason to prefer referring to clojure.string/lower-case over .toLowerCase besides the nice-name?