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

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