Fork me on GitHub
#beginners
<
2018-08-09
>
dangercoder00:08:23

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

lilactown04:08:22

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

👍 1
Chase00:08:53

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.

seancorfield00:08:36

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

seancorfield00:08:26

(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)

seancorfield00:08:34

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

http://www.sicpdistilled.com/section/1.1.5/ is a good resource on how to step through evaluation by hand

Chase00:08:49

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.

seancorfield01:08:32

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

chrisps12:08:41

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

chrisps13:08:39

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

bronsa14:08:42

what are you asking?

bronsa14:08:23

how to read "1abc" as 1?

chrisps16:08:32

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

chrisps16:08:06

I would think (…) 1abc should give NaN

danielneal14:08:30

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

bronsa14:08:48

#"(\-?\d+).*?"?

bronsa14:08:58

i can never remember how re-find works

bronsa14:08:12

oh wait nvm

danielneal14:08:23

it finds a re

bronsa14:08:31

not a re-?

danielneal14:08:39

oh good point

bronsa14:08:45

or what if it finds the same thing multiple times

danielneal14:08:48

I always assumed the - was separating

danielneal14:08:06

god knows what then

danielneal14:08:17

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

danielneal14:08:12

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

danielneal14:08:25

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?

hiredman16:08:24

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}
  ([pred]
    (fn [rf]
      (fn
        ([] (rf))
        ([result] (rf result))
        ([result input]
           (if (pred input)
             (rf result input)
             result)))))
  ([pred coll]
   (lazy-seq
    (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))))))))

hiredman16:08:30

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

hiredman16:08:14

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?

hiredman16:08:53

the only two resources when I started were http://clojure.org and the source

Logan Powell16:08:36

ah, I see! Thank you @hiredman

hiredman16:08:43

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

hiredman16:08:08

(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

hiredman16:08:11

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 😄

mfikes18:08:27

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.) https://youtu.be/LZDRobkxnWA

👍 4
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 😉

Chase23:08:39

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:

hiredman23:08:21

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

Chase23:08:06

true. what about "initially true"

andy.fingerhut23:08:09

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

Chase23:08:00

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

hiredman23:08:41

the condition isn't initially true

hiredman23:08:13

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

hiredman23:08:22

but that isn't how evaluation works

☝️ 1
hiredman23:08:51

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

Chase23:08:04

oh! i think something is about to click. hehe

andy.fingerhut23:08:36

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.

andy.fingerhut23:08:52

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

andy.fingerhut23:08:59

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

lilactown23:08:30

@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

andy.fingerhut23:08:42

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.

Chase23:08:02

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.

Chase23:08:08

i just need to pore over this a few times.

eggsyntax23:08:35

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

Chase23:08:53

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

😆 1
👍 1
andy.fingerhut23:08:38

@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.

eggsyntax23:08:43

(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"))

Chase23:08:01

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.

Chase23:08:49

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

eggsyntax23:08:52

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.

eggsyntax23:08:25

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

eggsyntax23:08:39

Writing it out on paper might help a lot.

noisesmith23:08:49

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

👍 1
Chase23:08:55

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?

eggsyntax23:08:16

@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"))

eggsyntax23:08:40

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

eggsyntax23:08:58

Taking breaks is probably really helpful 🙂

andy.fingerhut23:08:11

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.

andy.fingerhut23:08:00

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."

Chase23:08:51

lol! Thanks again folks.