Fork me on GitHub
#clojure-uk
<
2017-05-08
>
agile_geek06:05:31

morning Not a good start to the morning... train arrived 8 mins late already...wonder how much time it will lose due to slow local services all the way down east coast now? 🚂

seancorfield06:05:33

agile_geek: Where are you commuting from/to?

agile_geek07:05:59

From Newcastle Upon Tyne (actually Washington, Tyne and Wear but trains from Newcastle) to Londinium...my once a week commute to the big smoke.

agile_geek07:05:35

I stay in London for the week and go back on Friday evening

seancorfield07:05:17

That's quite the commute, but at least it's only once a week each direction. Not sure whether I'd prefer that over 2 hours each way every day which lots of folks do here 🙂

thomas07:05:39

how is the journey progressing @agile_geek ?

agile_geek07:05:25

So far so good..train status webpage is still predicting we'll only be 8 mins late into London...but I never believe it.

agile_geek07:05:57

Still in South Yorkshire (just south of Doncaster) so a way to go yet

thomas07:05:12

good luck! I hope you get there on time(ish)

agile_geek08:05:21

I was right to be sceptical. Now delayed 13 mins... once you're out of your time slot by more than a couple of mins on East Coast line you're frequently held up by slower local services.

agile_geek08:05:48

Still. Could be a lot worse....the worse delay I've ever had was in 2011...stuck stationary in train on afternoon of hottest day that year for over 5 hours making trip over 8 hours long.. fun!

Rachel Westmacott08:05:32

rcfotd:

-------------------------
clojure.core/definline
([name & decl])
Macro
  Experimental - like defmacro, except defines a named function whose
  body is the expansion, calls to which may be expanded inline as if
  it were a macro. Cannot be used with variadic (&) args.

agile_geek09:05:20

@peterwestmacott I'm not sure I fully understand definline. PLease use it in a sentence.

agile_geek09:05:34

"Someone said I cut in but I was definline"

bronsa09:05:00

think of definline like defining a macro that can also be used as a HOF

bronsa09:05:36

user=> (definline a [x] `(+ ~x ~x))
#'user/a
user=> (a 1)
2
user=> (map a [1 2])
(2 4)

bronsa09:05:46

higher order function :)

bronsa09:05:25

it has some gotchas which is why it's still marked as experimental

bronsa09:05:07

the gotchas are that because it can be used both at runtime and at compile time, you can't do any rewriting in the body that assume the arguments won't be evaluated

Rachel Westmacott09:05:11

it sounds too powerful to be a free lunch

bronsa09:05:25

but you have to assume they might not be evaluated and guard against it

bronsa09:05:50

e.g. my example suffers from double execution

user=> (a (do (println "foO") 1))
foO
foO
2

bronsa09:05:11

should be defined as (definline a [x] (let [x# ~x] (+ x# x#))

bronsa09:05:43

yeah, the official stance (as in, rich and alex's) on definline is: avoid it

agile_geek10:05:42

sounds like one of those features that you overuse when you first find it and becomes painful when your codebase grows?

bronsa10:05:43

there's very little reason to use it

reborg12:05:49

Agree with @bronsa here, not a lot of uses for definline. Looking at the standard lib, they have been used on functions to 1. carry over type info 2. during interop calls 3. still allowing them to be used as higher order fns. If that is not specific enough! 🙂 Anyway, there is some notable example in clj/java mixed projects. Manifold makes good use of them: https://github.com/ztellman/manifold/search?utf8=✓&amp;q=definline&amp;type=

thomas12:05:29

but I am not sure Zach Tellman is actually human... that might explain why he understands how to use it.

geek-draven13:05:19

I've made the mistake of trying to do something clever. As I'm working with a lot of database extracts at the moment I'm trying to dynamically create a function that uses juxt, but takes the fields as an argument, so I end up with something like #((juxt :field1 field2... ) %). I've been able to generate the field names and order them, but I'm stuck trying to figure out how to pass a bunch of keys to a function. Is there a way to do this?

dominicm13:05:39

@geek-draven What do you mean by: > how to pass a bunch of keys to a function ?

dominicm13:05:22

Do you mean something like:

(let [x [:a :b :c]]
  ((apply juxt x) {:a 1 :b 2 :c 3}))
;; => [1 2 3]
?

geek-draven13:05:13

@dominicm Thanks, I was passing the keys as a list rather than vector 🙂

dominicm13:05:11

@geek-draven a list works with apply too. I might have misunderstood you though.