Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/prog/ Confessions Thread

Name: Anonymous 2015-04-26 21:07

I've never really understood the Y combinator.

Name: Anonymous 2015-04-26 21:39

I don't actually use Haskell for anything

Name: Anonymous 2015-04-26 21:43

I don't even know what a monad is.

Name: Anonymous 2015-04-26 21:54

>>1
its just packaging up self application in a nice way

Name: Anonymous 2015-04-26 22:32

I'm a 33 year old virgin.

Name: Anonymous 2015-04-26 23:29

>>1
The Y combinator takes a function f. Then it calls f on itself. So f's first parameter is f itself. Then f can make a recursive call if it wants to by calling its first parameter.

Name: Anonymous 2015-04-27 1:56

"So f's first parameter is f itself"

that's not quite right, it's a delayed version of (y f) that gets passed in

Name: Anonymous 2015-04-27 2:09

Sometimes /prog/ is full of threads I don't understand because they're talking about hipster language shit that popular languages don't have.
I'm looking at you, Lispers

Name: Anonymous 2015-04-27 2:49

I enjoy doing Node.js programming.

Name: Anonymous 2015-04-27 3:14

>>7
You can curry or not curry.

Name: >>10 2015-04-27 3:16

Oh, I just understood. You're right. My mistake. You can make it work by just passing f though. Then recursive calls look like (f f 3) instead of (f 3).

Name: Anonymous 2015-04-27 5:07

I used void.h unironically once

Name: Anonymous 2015-04-27 5:47

I actually enjoy FIOC and even use Coffeescript (FIOC for JS)

Name: Anonymous 2015-04-27 7:41

I can't understand delimited continuations no matter how hard I try.

Name: Anonymous 2015-04-27 7:44

The Y combinator provides seed funding for startups. Seed funding is the earliest stage of venture funding. It pays your expenses while you're getting started.

Some companies may need no more than seed funding. Others will go through several rounds. There is no right answer; how much funding you need depends on the kind of company you start.

The Y combinator's goal is to get you through the first phase. This usually means: get you to the point where you've built something impressive enough to raise money on a larger scale. Then we can introduce you to later stage investors—or occasionally even acquirers.

Name: Anonymous 2015-04-27 11:09

>>12
You probably mean "unsarcastically". Your unsarcastic usage of void.h was ironic.

Name: Anonymous 2015-04-27 14:47

>>14
they are far simpler than call/cc - have you seen the rewrite laws that explain how they work?

Name: Anonymous 2015-04-27 14:56

>>17
Well, I don't understand call/cc either. What rewrite laws?

Name: Anonymous 2015-04-27 15:33

Name: Anonymous 2015-04-27 16:15

Dignified people of /prague/ should have already understood call/cc, Y combinator and monoids in the category of endofunctors too.
back to /g/ pls

Name: Anonymous 2015-04-27 16:30

I like Visual Studios.

Name: Anonymous 2015-04-27 16:33

>>20
GHC control flow expands from the outermost endotensor.

Name: Anonymous 2015-04-27 16:41

>>20
All jewish brain rot

Name: Anonymous 2015-04-27 17:10

>>19
Thanks, but I still can't quite get what's going on. I've gotten to do Exercise 4, it's a function that finds the product of numbers in a list but short-circuits if it sees a 0.

#lang racket
(require racket/control)

(define (product-delim xs)
(define (go ys acc)
(cond
((null? ys) acc)
(#t (reset (begin
(display (car ys))
(newline)
(go (cdr ys)
(shift k
(if (eq? (car ys) 0) ; The most salient part
0
(k (* (car ys) acc))))))))))
(go xs 1))


It's supposed to print only non-zero elements of the list. The continuation k is called only in the branch where the car of the list is non-zero, right? But when I run (product-delim '(2 4 0 1 2 3)), I get the output

2
4
0
0


The last zero is the end result, but the first one is the element of the list. But why does it print the zero element? I don't get it.

Name: Anonymous 2015-04-27 17:59

>>24
You're doing a complicated "tail recursive with accumulator" version - that lets you easily do an early exit without using continuations.

The idea of the exercise is to start with a normal, direct style version of product:

(define (product xs)
(display (list 'trace xs)) (newline)
(if (null? xs)
1
(* (car xs) (product (cdr xs)))))


and then insert a shift (fun _ -> M) to discard the continuation in the case where you see a 0.

Name: Anonymous 2015-04-27 18:15

>>21
Which Visual Studio is your favorite? Mine is Universal Studios.

Name: Anonymous 2015-04-27 18:30

>>25
But I still don't understand my code. Which means I don't understand delim. conts as a whole.

Can you explain where I'm wrong if I simplify the question?

In the below snippet, when the "if" takes the "true" branch, why does (some-foo) get called? Didn't we discard the continuation in that branch?

(reset
(some-foo)
(shift k (if (...)
0
(k ...)))

Name: Anonymous 2015-04-27 18:57

inside reset is an implicit begin: (begin (some-foo) (shift k ...)) so it will run some-foo always.

If you would do it this way instead, maybe it will act how you expected:

(define (fook v) (begin (some-foo) v))

(fook (shift k ...))

Basically: You have the right idea but got bit by an unusual situation with an implicit special form. Don't worry about it - try to solve ex 4 in the intended way.

Name: Anonymous 2015-04-27 19:07

>>28
Ah, so it was the begin. Now I get it, thanks.

Name: Anonymous 2015-04-27 20:24

Basically, Y is a function that applies a function F (which expects some recursive function as it's first argument), to itself.

(define (y f) (f (y f)))

this only works in lazy languages though, otherwise Y will continually be called recursively until the stack blows up.

To make it work in strict languages you have to add another layer of indirection. Rather than passing (Y f) to the function, you pass a function (called Z) that when called will again call the original function
with a newly created version of Z, which again will pass a new version of itself into F, ad infinitum, but the infinite recursion only recurs stepwise as necessary this time, as it is delayed behind a lambda indirection.

(define (y f)
;; always pass a copy of this function to itself
(let ((make-wrapped-func (lambda (wrapper-maker)
(lambda (arg) ;; original function's argument

;; next-wrapped-func is equivalent to the function we're current evaluationg
(let ((next-wrapped-func (wrapper-maker wrapper-maker)))
;; call original func with wrapped func (which will in turn call it again with a wrapped func, if necessary)
;; then pass in the argument
((f next-wrapped-func) arg))))))
(make-wrapped-func make-wrapped-func)))

Name: Anonymous 2015-04-27 23:05

#lang racket
(require racket/control)

(define (product xs)
(display (list 'trace xs)) (newline)
(if (null? xs)
1
(if (= 0 (car xs))
(shift _ 0)
(* (car xs) (product (cdr xs))))))

Name: Anonymous 2015-04-27 23:40

>>30
That almost reads like Java.

Name: Anonymous 2015-04-28 0:03

>>32
dont post

Name: Anonymous 2015-04-28 3:03

>>30
Terrible!

(define (y f)
(lambda args
(apply f (cons (y f) args))))

(define factorial
(y (lambda (f n)
(if (= n 0)
1
(* n (f (- n 1)))))))

Name: Anonymous 2015-04-28 3:21

>>34
that's a pretty clever way of doing it

Name: Anonymous 2015-04-28 3:39

>>35
Why thank you!

Name: Anonymous 2015-04-28 3:57

I've never liked the Y combinator, or any of the hardline functional programming shit that leads to such ridiculous crap. If I wanted to λ calculus, I would do actual λ calculus, not half ass it in Scheme. Sure, it's good to understand and is important to have some knowledge about, but I will never pollute my toy programs with such hideous stuff. I am not a trash compactor for such programmatic garbage.

Name: Anonymous 2015-04-28 4:25

>>37
If you've got too much trash to compact, why don't you unload it into my anus!

Name: Anonymous 2015-04-28 5:12

>>1
it's a site! https://www.ycombinator.com/

>>13
Coffeescript is Ruby for JS

Name: Anonymous 2015-04-28 16:08

>>37
(lambda (f)
((lambda (w)
(lambda (a)
((f (w w)) a)))
(lambda (w)
(lambda (a)
((f (w w)) a)))))


there you go, actual λ calculus
don't you find it pretty fascinating that you can recursion from just lambdas though?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List