Programming thread

  • Want to keep track of this thread?
    Accounts can bookmark posts, watch threads for updates, and jump back to where you stopped reading.
    Create account
That's functors. Monads additionally have defined way of combining them with associative binary operation.
ok.... so it's a wrapper around a type and a set of functions that take that wrapper, operate on the type contained within, and return that same wrapper?
 
hey that's what i said
yeah and i repeated it, what are you gonna do about it :smug:
Sounds about right. See how much easier that is to understand than a bunch of vague terms that somewhat remind you of testicles?
that reminds me of how i thought i didnt understand pointers, because r/programmerhumor was treating it like something advanced and hard to understand. far cry from "just a memory address lol"
 
Weird seein' Lispy folks "draw the line at continuations". call-with-current-continuation aka call/cc is one of the defining attributes of a Scheme, and the domain name of Chicken Scheme, call-cc.org . It's conceptually simple: it's a JMP that also loads the couple variables in the closure of the code that is being JMPed to. NBD. Like Creative Username said, it's "just a function call that doesn't return." As for category theory, well. I still don't track all the intricacies of the varying categories that comprise much of Haskell terminology, but it probably won't go slowly now that I'm having fun with Scheme. ADHD Mate explains that well but I don't get it still. Maybe when I have my Haskell arc. I guess that's closer than ever given that I'm in the middle of my Scheme arc.
 
Weird seein' Lispy folks "draw the line at continuations". call-with-current-continuation aka call/cc is one of the defining attributes of a Scheme, and the domain name of Chicken Scheme, call-cc.org . It's conceptually simple: it's a JMP that also loads the couple variables in the closure of the code that is being JMPed to. NBD. Like Creative Username said, it's "just a function call that doesn't return." As for category theory, well. I still don't track all the intricacies of the varying categories that comprise much of Haskell terminology, but it probably won't go slowly now that I'm having fun with Scheme. ADHD Mate explains that well but I don't get it still. Maybe when I have my Haskell arc. I guess that's closer than ever given that I'm in the middle of my Scheme arc.
Once you get the hang of the theory around it all, take a look at Continuation-passing style (which I have probably linked in this thread 100 times now) and try writing a minimal S-expression JIT compiler with it in C. It sounds more daunting than it actually is; you're (probably) not going to be writing assembly for it. CPS is the traditional basis for Scheme compilers and Scheme->C transpilation.

the domain name of Chicken Scheme, call-cc.org
I thought that was really cute when I first saw it. It's a shame call.cc is taken (and appears to be blank).
 
Last edited:
JS is a beautiful functional language used exclusively to write unholy abominations.
js itself is a bit of an abomination but i feel people shit on it a bit too much
the real worst thing about js is that npm exists
npm is a cancer on this earth and those responsible should be executed for crimes against humanity
tbh, even as someone who has a degree in this shit, category theory terminology always makes my eyes glaze over when I read it.
oh ok so it's not just me then
that reminds me of how i thought i didnt understand pointers, because r/programmerhumor was treating it like something advanced and hard to understand. far cry from "just a memory address lol"
a properly confused indian saar can make anything unnecessarily complicated and hard to understand
Weird seein' Lispy folks "draw the line at continuations". call-with-current-continuation aka call/cc is one of the defining attributes of a Scheme, and the domain name of Chicken Scheme, call-cc.org . It's conceptually simple: it's a JMP that also loads the couple variables in the closure of the code that is being JMPed to. NBD. Like Creative Username said, it's "just a function call that doesn't return."
one of the greatest ways to think of regular call/cc non-delimited continuations is that they're just a way to take the return stack and jump into that in a function-like way
basically it's like if you could take a random return statement from your program and store it into variables and pass it to other functions
delimited continuations (shift/reset, prompt tags, etc.) are better in certain ways but i don't exactly understand them yet
Once you get the hang of the theory around it all, take a look at Continuation-passing style (which I have probably linked in this thread 100 times now) and try writing a minimal S-expression JIT compiler with it in C. It sounds more daunting than it actually is; you're (probably) not going to be writing assembly for it. CPS is the traditional basis for Scheme compilers and Scheme->C transpilation.
i did indirectly explain how cps works on the last page: basically you just turn everything inside out and make continuations explicit, which results in the stack not really mattering and your program becoming an endless chain of functions calling each other
white people languages have guaranteed proper tail calls for this reason, and also so you don't need to put loops into the language as a feature like a fucking retard when you could just implement loops using λ and a couple of macros

also, fun fact: when you use dom shit in javascript you're writing in a sort of cps
see haskellers aren't the only scary functional programming autists who say things like "☝️🤓 <common idiom> is really just an application of monads you know"
 
while loops? what the fuck are those? don't you mean ((λ (f) (f f)) (λ (f) (f f)))
jokes aside there is some idealized language out there that has all of the functional style operations on collections that allows you to treat the collection's elements atomically while also having traditional loop structures for unbounded loops so I don't have to think about recursion.

the sad fact is that javascript comes really close to this if not for the fact it's unfathomable garbage in every other way.
 
far cry from "just a memory address lol"
Yeah, I never got the whole pointers are hard meme either. What did take a while for me to grok though, was recursion. In that it is literally just a function calling itself. I had the wrong belief that there would have to be more to it.
the real worst thing about js is that npm exists
I'd say that there is no good enough stdlib for js which results in a lot of stuff that should be in the stdlib instead being hundreds of small npm packages.
All you need is a trusty while loop and a beer
I challenge you to implement quicksort without recursion and without using a stack/list that emulates recursion.
 
while loops? what the fuck are those? don't you mean ((λ (f) (f f)) (λ (f) (f f)))
Reminds me of this old post of mine:
Code:
(((((λ (y)
      ((λ (f) (y (λ (x) ((f f) x))))
       (λ (f) (y (λ (x) ((f f) x))))))

    (λ (factorials)
      (λ (from)
        (λ (to)
          (λ (res)
            (if (< from to)
                (((factorials (+ from 1)) to) (cons ((((λ (y)
                                                         ((λ (f) (y (λ (x) ((f f) x))))
                                                          (λ (f) (y (λ (x) ((f f) x))))))

                                                       (λ (fac)
                                                         (λ (n)
                                                           (λ (res)
                                                             (if (< n 2)
                                                                 res
                                                                 ((fac (- n 1)) (* res n)))))))
                                                      from) 1)
                                                    res))
                res))))))
   5) 15) '())
Output: '(87178291200 6227020800 479001600 39916800 3628800 362880 40320 5040 720 120).

Written in Scheme because Scheme is based.
Later, I had simplified it even further to
Code:
((λ (Y)
   ((((Y (λ (factorials)
           (λ (from)
             (λ (to)
               (λ (res)
                 (if (>= from to) res
                     (((factorials from) (- to 1))
                      (cons (((Y (λ (fac)
                                   (λ (n)
                                     (λ (res)
                                       (if (< n 2) res
                                           ((fac (- n 1))
                                            (* res n)))))))
                              (- to 1)) 1)
                            res))))))))
      5) 15) '()))
 (λ (y)
   ((λ (f) (y (λ (x) ((f f) x))))
    (λ (f) (y (λ (x) ((f f) x)))))))
which even outputs in ascending order without a (reverse): '(120 720 5040 40320 362880 3628800 39916800 479001600 6227020800 87178291200).
 
Last edited:
so I don't have to think about recursion
not very Ypilled of you to say that
recursion is epic because you can tell the computer to solve the problem by solving the first bit of the problem and then solving the rest of the problem
and named let with a when conditional in scheme is actually not too bad for writing your loops, being not too different from a traditional c-style for loop when used with regular numbers
the sad fact is that javascript comes really close to this if not for the fact it's unfathomable garbage in every other way.
perhaps lua could do it but you would need to define a bunch of functional shit by yourself because lua is really just scheme but made out of hash tables
unfortunately not many people have noticed that lua is a lisp so it doesn't really come with lisp goodness in it out of the box
Yeah, I never got the whole pointers are hard meme either.
i did find the c syntax for pointers hard for a while (thanks k&r for using the asterisk for like 3 different things)
perhaps people find pointers hard because they stumble on the c syntax for pointers and not because the pointers themselves are hard
What did take a while for me to grok though, was recursion. In that it is literally just a function calling itself. I had the wrong belief that there would have to be more to it.
it's amazing what you can do with it though
see the above post where @y a t s uses nothing but lambda magic and questionable indentation to write a factorial function (Real Men don't need let expressions or variable definitions or loops, they are all just macros over λ you know)
 
perhaps people find pointers hard because they stumble on the c syntax for pointers and not because the pointers themselves are hard
I think beginners find pointers hard because it's often their introduction to working directly with abstractions and abstract representations of values (i.e. in memory). You have to think of it as a representation of where a value is stored instead of a stored value itself. Abstract thinking isn't something that comes easily to most; it takes practice.

questionable indentation
lol fair. I had meant to collapse the if condition. I have fixed it now. My main focus with lisp indentation is keeping clarity in where values belong in the hierarchy.

Edit: I made it even less ugly bc it was starting to bug me.
 
Last edited:
Pointers are hard only because C syntax is retarded. References are easy. Anyone with a three digit IQ can understand a reference as something that 'stands in' for something else.

C syntax is just retarded and if all you did was change * to $ or some other non-overloaded symbol you would have the perfect language.

fixing UB on top of that and giving it a quality standard library and you get Odin
 
I think beginners find pointers hard because it's often their introduction to working directly with abstractions and abstract representations of values (i.e. in memory). You have to think of it as a representation of where a value is stored instead of a stored value itself. Abstract thinking isn't something that comes easily to most; it takes practice.
yeah this actually makes way more sense than what i said
My main focus with lisp indentation is keeping clarity in where values belong in the hierarchy.
i sort of just like the standard indentation style
of course that code is a bit confusing no matter how well-indented it is (most people have a let macro in their schemes and regularly use it for a reason)
Anyone with a three digit IQ can understand a reference as something that 'stands in' for something else.
beginner programmers often have a bit of trouble even with regular variables, i think it's mostly natural
C syntax is just retarded and if all you did was change * to $ or some other non-overloaded symbol you would have the perfect language.
eh c has a few other warts than just a few syntax issues and a bunch of ub scenarios
 
js itself is a bit of an abomination but i feel people shit on it a bit too much
the real worst thing about js is that npm exists
npm is a cancer on this earth and those responsible should be executed for crimes against humanity
1757611285533.webp
 
eh c has a few other warts than just a few syntax issues and a bunch of ub scenarios
For all the "C but a bit higher level" pretenders there aren't many "C but a bit lower level" languages that learn from today's programming understanding. I think there's a real niche here. Maybe this is the era of the compiled Scheme?
 
Back
Top Bottom