lainchan / λ

(untitled)

Six · 2022-03-22 05:42
Do you get to the point where you cant understand a simple function after some hours in front of the PC? I wonder if I am simply retarded or forcing my mind too much after some time.
The Phantom Phreak · 2022-03-22 05:59
I forgot, but how to recover? Lol, do you make breaks or even use the pomodoro technique?
Dox · 2022-03-22 09:01
>>30484 Best ways to recover in my experience are going for a quick walk outside without listening to anything or meditation. Reading a book that you can get lost into is a good one as well
Koichiro · 2022-03-22 10:59
Yeah it happens a lot to me, i think its just how computers work on your mind over time. Its really frustrating, the worst part is my mind cant drop it and keeps thinking even when i do something else.
Nobody special · 2022-03-23 02:13
Could somebody give an example of what you mean? what would count as a simple function? what does it mean to "understand" it?
Void · 2022-03-23 04:57
>>30500 def create_adder(x): def adder(y): return x+y return adder add_15 = create_adder(15) print(add_15(10)) I understood what it does, but didnt understand how, I use decorators for daily projects, but yet when I tried to rationalize this one, understanding how the fuarrrk print(add_15(10)) parsed to y made me mad. I just had to sleep.
progn · 2022-03-23 06:14
>>30501 Nobody can think straight if they are sleepless. It's a common problem. Rest is important lainon. Although, everyone should pomodoro technique. It helps you regain efficiency after some time of work.
Nameless · 2022-03-23 16:11
>>30501 The inner function tries to resolve x in its scope, the only x out there is the one that gets passed to create_adder. Therefore the inner x gets bound to the parameter of create_adder, then a function with a bound x gets returned, y is resolved when that function is called ...>>30501
Jet Black · 2022-03-23 18:31
>>30501 >>30501 Adder object that you defined with def adder is add_15, right? This is same as calling CreateAdder.adder(10) after you initialized CreateAdder(15) Decorators are great for logging and timing, a func around a func, best to use it to log or time, right?
Spooky · 2022-11-23 13:45
>>30525 There is no initialization happening here, as adder() is not an instance object of create_adder(). In fact this is not object oriented. Every function has a scope linked to it, an inner function can see the scope of an outer function and so on and so on until you reach the global scope.
Nguoi La · 2022-11-23 14:16
>>30501 create_adder returns a function of a single variable(y). That is easy to understand. Create-adder accepts a variable(x) who becomes part of the environment of the function that it returns. The function returned by create_adder has the variable x = 15(in your example) as part of its environment(thus, closure). So create_adder(15) returns a function adder defined as: def adder(y): return 15 + y Thus, add_15 is a variable that points to the function adder(y) which has x = 15.
Mario Rossi · 2022-11-24 05:58
>>30501 Look up closures, they're fairly simple. If you want to learn more about this style of programming you can also look into lambda calculus, since you're effectively using Currying with this.
Hitomi · 2022-11-27 08:06
>>33457 One thing that helped me understand closures is I started using them as simple objects as described in let over lambda, but works in any language with closures
Joe Bloggs · 2022-11-28 20:35
Funnily enough, I was doing closures before I even knew what they were called. I just made a python function that returned a function and thought that was the most obvious thing to do for some problems. Once I learned C and found you couldn't do that, I was disappointed.
Fred Nurk · 2022-12-08 10:14
I'm currently working on re-implementing the most important parts of bash (execution, redirections, pipes, parsing) for my studies and find myself continuously braindead. I can understand the code fine but I'm so fuarrrking burnt out that I just don't want to write the rest. It doesn't help that I have to commute four hours a day. I'm hoping to get the project done before Christmas break rolls around, if I don't I won't be having a break for a while.