Fork me on GitHub

Is setting up graphql worth the struggle? I haven't really used it a lot before. I like the thinking concerning mutations etc. Using Buddy now for authentication and authorization, anyone with a public repo where you've used graphql + authorizaiton


I think GraphQL is great. Authorization for GraphQL is the same as authorization for any other API

👍 4

ok, i think i'm starting to grasp basic recursion but i did have one question with this example. i can see why it keeps looping through the whole collection until it's gotten through all the nums but at the very end the if statement will eventually evaluate the "else" branch right which is saying return an empty list. So why isn't the result of calling that function always just the else branch (ie. an empty list)? why does it give you all the "then" portion? I can try and clarify if that is gibberish.


@chase-lambert work through on paper what happens when nums is [1]


(cons (inc 1) (inc-more ())) and then expand the nested call (list) so you get (cons (inc 1) (list)) which is (cons 2 ()) so you get (2)


and then if nums was [1 2 3] you'd get a string of nested calls to resolve that would eventually get you to (cons (inc 1) (cons (inc 2) (cons (inc 3) (list))))

hiredman00:08:24 is a good resource on how to step through evaluation by hand


thanks folks. i was having a similar issue to a simple example last night too and was given the same resource. hahaha. i think what is happening is i've gone past my programming stamina for the day and it's just not clicking in the brain. probably would have been fine a couple hours ago.


Recursion can be tricky to get your head around, if you're not used to it...


How can I test if something is equal to js/NaN ?


How do you guys approach this: (js/parseFloat "1abc")


what are you asking?


how to read "1abc" as 1?


well, reading 1abc yields a number, but abc1 gives a NaN


I would think (…) 1abc should give NaN


(some->> s
         (re-find #"\-?\d+(?:\.\d+)?")




i can never remember how re-find works


oh wait nvm


it finds a re


not a re-?


oh good point


or what if it finds the same thing multiple times


I always assumed the - was separating


god knows what then


if I was it I'd give up after the first job done


I do something like that, my regex is probably wrong though


for some reason it works most of the time but sometimes it locks and unlocks master

Logan Powell15:08:38

Quick question: I'm looking through some of the source code for some transducers in Clojure and many of them use a variadic form even when they only take a set number of arguments. Can someone help me with the reason for this? Does it perform better?


the full definition of filter is

(defn filter
  "Returns a lazy sequence of the items in coll for which
  (pred item) returns logical true. pred must be free of side-effects.
  Returns a transducer when no collection is provided."
  {:added "1.0"
   :static true}
    (fn [rf]
        ([] (rf))
        ([result] (rf result))
        ([result input]
           (if (pred input)
             (rf result input)
  ([pred coll]
    (when-let [s (seq coll)]
      (if (chunked-seq? s)
        (let [c (chunk-first s)
              size (count c)
              b (chunk-buffer size)]
          (dotimes [i size]
              (let [v (.nth c i)]
                (when (pred v)
                  (chunk-append b v))))
          (chunk-cons (chunk b) (filter pred (chunk-rest s))))
        (let [f (first s) r (rest s)]
          (if (pred f)
            (cons f (filter pred r))
            (filter pred r))))))))


my guess is you are looking at a tutorial or transducer explanation or something that is just showing you part of the definition


a clojure function like (fn [x] x) is actually sugar for (fn ([x] x))

Logan Powell16:08:09

Btw, where/how did you learn all this kind of stuff?


the only two resources when I started were and the source

Logan Powell16:08:36

ah, I see! Thank you @hiredman


where each group inside the fn is an arity + function body


(fn ([x] x) ([x y] (+ x y)))

Logan Powell16:08:32

should I define my single arity functions with ([arg] or is that redundant?

Logan Powell16:08:53

just looking for best practices


use the short hand

Logan Powell16:08:19

thank you for the piece of mind

Logan Powell16:08:54

I was worried all my transducers needed to be rewritten 😄


We’ll be starting an Apropos episode shortly. (If you are a beginner, you may like this because we spend half the time solving problems in the REPL.)

👍 16
David Reno21:08:14

What was the reference to the kafka talk? It wasn’t this, was it? > Turning the database inside out with Apache Samza” by Martin Kleppmann

Logan Powell22:08:11

Could a google calendar be set up to subscribe to those?

Logan Powell22:08:28

or would we get notifications of upcoming streams by subscribing to the youtube chan 😉


hello, I'm back from last night! I think I understand where I was confused on my simple recursion problem. with an if statement, if the condition is true at any point the "then" branch will execute its expressions and return that value to you. After the recursion has run it's course and the collection is empty so the condition is now false you still get what was evaluated under the "then" branch returned. You don't just get the "else" branch because it's now false (and in this function should give you an empty list (list). Do I understand it now? Here was the function:


hard to say, I am skeptical of "at anytime" because time has nothing to do with it


true. what about "initially true"


Time does have something to do with it if you consider the order that function calls and function returns occur, yes?


"if the condition is initially true" then give me the result of this then branch, including it's recursions


the condition isn't initially true


I suspect you are thinking there is a single nums and that value of that nums changes over time


but that isn't how evaluation works

☝️ 4

every time you call inc-more that evaluation of inc-more has its nums


oh! i think something is about to click. hehe


In the most common implementations of recursion, there is a run-time call "stack". For every function call, you "push" an "activation record", i.e. a collection of values for the parameters and local variables of the function, and the values bound to parameters and local variables can be completely different in each activation record.


That may not clarify anything for you, but in case it does ...


And actually that behavior is the same for function calls between different functions, too, not only when recursion is happening.


@chase-lambert I’m not sure I understand your question. if nums is empty, you will certain get an empty list returned by inc-more


I added an example output from using a Clojure library called tools.trace to the link that @hiredman made, showing the run-time sequence of calls and returns that it produces.


i think my question was why would you ever get an incremented nums collection instead of just getting that empty list. but i think i was just way off on my understanding of what was happening. i'm looking over that gist and i've been talking with my self proclaimed mentor, eggsyntax, privately so i think i'm on the right track now.


i just need to pore over this a few times.


Hey now, I never proclaimed myself your mentor, just offered 🙂


lol. i meant i proclaimed you my mentor whether you accepted or not

😆 4
👍 4

@chase-lambert When you make a call like (inc-more [5 7]), there will be 3 separate calls made to the inc-more function. The 3rd one will be called with an empty list, and return an empty list, but the return value will not go back to the original caller, but to the 2nd call of inc-more, which hasn't finished yet.


(I originally saw the PMs, not the discussion here, didn't mean to bypass other folks' efforts 🙂 ) I sent chasote this, hoping it would maybe be clearer:

(defn f [x]
  (if (pos? x)
    (str "(before-f-of-" x ") "
         (f (dec x))
         " (after-f-of-" x ") ")
    "last call"))


so now i'm understanding the separate function calls happening i think. now i still haven't connected that to how i call something multiple times but only get the one collection returned to me. but i haven't given this new info enough thought yet.


oh wait, i think i know why. because my 2nd or 3rd calls into the function or whatever already have the previously done updates (increments) to them right


Not exactly, but closer! inc-more (or f) only receives what's passed to it (a sequence of nums in the case of inc-more; a number in the case of f). But it gets consed onto the previous result on the way out, ie when it returns.


@hiredman’s gist above shows the substitution step by step (and it really is just a simple substitution of the result for the call).


Writing it out on paper might help a lot.


the code making those strings might be easier to read if you use format

👍 4

thanks everybody! I'll get it. I just need to take a step back and then tackle all this good info you folks gave me. its frustrating that everything was going nice and simple and then just total roadblock for me this early in the game. sounds like these should be simple concepts still at this point. but hey, if it was easy it wouldn't be so intriguing right?


@noisesmith good thought.

(defn f [x]
  (if (pos? x)
    (format "(early-in-f-of-%d) %s (later-in-f-of-%d)" x (f (dec x)) x)
    "last call"))


Nope, recursion ties most people's brains in knots when they first try to learn it. Not just you 🙂


Taking breaks is probably really helpful 🙂


I tried adding another comment to the gist above, with a time order sequence of events for the call (inc-more [5]), attempting to describe the operational sequence of steps that occur.


Recursion does tie many people's brains in knots. It is common enough that there are probably many jokes about it, but this one is fun: "In order to understand recursion, you must first understand recursion."


lol! Thanks again folks.