This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-09
Channels
- # beginners (91)
- # boot (5)
- # cider (30)
- # clara (16)
- # cljsjs (3)
- # cljsrn (6)
- # clojure (84)
- # clojure-dev (4)
- # clojure-dusseldorf (1)
- # clojure-italy (15)
- # clojure-nl (2)
- # clojure-spec (5)
- # clojure-uk (120)
- # clojurescript (54)
- # core-async (25)
- # core-matrix (1)
- # css (2)
- # cursive (20)
- # datomic (28)
- # editors (11)
- # emacs (6)
- # figwheel (4)
- # figwheel-main (28)
- # fulcro (36)
- # graphql (7)
- # hyperfiddle (2)
- # jobs (6)
- # jobs-discuss (10)
- # lambdaisland (1)
- # lumo (3)
- # nrepl (20)
- # off-topic (24)
- # pedestal (2)
- # protorepl (3)
- # reagent (3)
- # reitit (2)
- # remote-jobs (1)
- # ring-swagger (26)
- # rum (1)
- # shadow-cljs (247)
- # spacemacs (29)
- # tools-deps (12)
- # vim (15)
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
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)
Does that help @chase-lambert?
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))))
http://www.sicpdistilled.com/section/1.1.5/ 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...
This is pretty cool https://ourcodestories.com/markm208/Playlist/4
(some->> s
(re-find #"\-?\d+(?:\.\d+)?")
(js/parseFloat))
it finds a re
oh good point
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
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?
Side note, I did find this benchmark: https://gist.github.com/halgari/5d7780e6f068ae217bb2
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))))))))
my guess is you are looking at a tutorial or transducer explanation or something that is just showing you part of the definition
Btw, where/how did you learn all this kind of stuff?
the only two resources when I started were http://clojure.org and the source
ah, I see! Thank you @hiredman
should I define my single arity functions with ([arg]
or is that redundant?
just looking for best practices
thank you for the piece of mind
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.) https://youtu.be/LZDRobkxnWA
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
Could a google calendar be set up to subscribe to those?
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:
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
I suspect you are thinking there is a single nums
and that value of that nums changes over time
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.
there are some great sicp videos too https://www.youtube.com/playlist?list=PLB63C06FAF154F047
@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.
@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).
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 🙂
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."