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

continuations

Name: Anonymous 2013-03-02 2:18

In this thread, you may post code that makes use of continuations, and I will attempt to produce code that does the same and looks reasonably similar, without using continuations.

Name: Anonymous 2013-03-02 21:24

>>46
Still nobody wants to sleep with you.

Name: Anonymous 2013-03-02 22:33


(define (producer return)
  (return 1 (lambda (return)
    (return 2 (lambda (return)
      (return 3 '()))))))

(define (consumer produsa)
  (if (not (null? produsa))
    (produsa (lambda (return-value produsa)
      (display return-value)
      (newline)
      (consumer produsa)))))

(consumer producer)


maybe something....

Name: Anonymous 2013-03-02 23:41

>>47
Oh! Oh! Eye-Do! Eye-Do! And >>47-Too!

Name: Anonymous 2013-03-03 3:28

Continuations are like violence, if they doesn't solve your problem, you're not using enough of them.

Name: Anonymous 2013-03-03 4:13

>>50
my program segfaults, how much violence should i use to solve it?

Name: Anonymous 2013-03-03 4:37

>>51
More.

Name: Anonymous 2013-03-03 6:54

>>1
Implement amb without continuations. I fucking dare you.

Name: Anonymous 2013-03-03 7:02

>>53
Can it be implemented with delimited continuations? I wonder.

Name: Anonymous 2013-03-03 7:04

>>49
Slut.

Name: Anonymous 2013-03-03 7:07

>>53,12
We're waiting.

Name: Anonymous 2013-03-03 10:42


?BREAK  IN 10
READY.
CONT
?CAN'T CONTINUE  ERROR
READY.
CUNT
?SYNTAX  ERROR
READY.
SYS64738

Name: Anonymous 2013-03-03 11:14

>>41
Sorry, it doesn't run on anything. I just wrote it to show "blocking" calls on a single threaded event loop without having to resort to CPS.

While you can do much without first class continuations, trying to emulate them with closures most often forces you to write code in CPS. If you prefer that, then fine.

Name: Anonymous 2013-03-03 15:47

>>56
All non deterministic programming can be expressed as deterministic operations on lazy lists that invoke continuations upon evaluation.

Anything that can be done with continuations, can be done with tail recursion in programs that don't use the native stack.

Translating....


(define (fact-normal n)
  (if (= n 0)
    1
    (* n (fact-normal (- n 1)))))


To.....................


(define (fact2 return n)
  (if (= n 0)
    (return 1)
    (fact2 (lambda (ret-val)
             (return (* n ret-val)))
           (- n 1))))

Name: Anonymous 2013-03-03 16:02

>>59
All non deterministic programming can be expressed as deterministic operations on lazy lists that invoke continuations upon evaluation.
Right. Such is how amb is implemented on deterministic machines.
Your code example is fibs, not amb. We're still waiting.

Name: Anonymous 2013-03-03 21:43

>>60
After further inspection of amb, it has come to my attention that the interface is dependant on mutations. Hence, my religious convictions prevent me from implementing it, as it's interface is inherently flawed and harmful. Thus rather that using amb, I will explicitly use lazy lists that call functions which emulate continuations. As shown in this example...................................................................................................................................................................

http://mitpress.mit.edu/sicp/full-text/sicp/book/node91.html

(if-fail (let ((x (an-element-of '(1 3 5 8))))
           (require (even? x))
           x)
         'all-odd)



(let ((success (lambda (x) x))
      (fail (lambda () 'all-odd)))
  (an-element-of '(1 3 5 8) (lambda (x fail)
                              (if (even? x)
                                (success x)
                                (fail)))
                            fail))

Name: Anonymous 2013-03-03 21:44

missing definition.......very sorry............................


(define (an-element-of lis success fail)
  (if (null? lis)
    (fail)
    (success (car lis) (lambda () (an-element-of (cdr lis) success fail)))))

Name: Anonymous 2013-03-03 22:27

I support amb because combining mutable state with continuations is awesome. Haskell's continuation monad is boring.

Name: Anonymous 2013-03-04 1:47

>>63
I support amb because combining mutable state with continuations is awesome.
How do you deal with race conditions and so? Not trolling, I really want to know.

Name: Anonymous 2013-03-04 1:49

>>59
All non deterministic programming can be expressed as deterministic operations on lazy lists that invoke continuations upon evaluation.
Does the converse hold? Can continuations be implemented in terms of non-deterministic operations?

Name: Anonymous 2013-03-04 3:56

>>65
I'm sure they can, since continuations are implemented on deterministic turning machines, but what do you have in mind?

Name: Anonymous 2013-03-04 4:18

>>66
Like almost everyone else on this board four years ago, I am trying to achieve computational enlightenment. I wish to see the true essence of computation, and I wonder whether it is purely functional, how powerful macros are, what kind of continuations there are, and so on. So far I am certain that evaluation must be strict, and that it must look and behave mostly like Lisp.

So more to the point, I am wondering whether continuations can be elegantly expressed in terms of some non-deterministic operations which would then generalize them.

Name: Anonymous 2013-03-04 5:16

>>67
Master brainfuck and unlambda.

Name: Anonymous 2013-03-04 5:19

Holy shit guy............................................... Are you a child?......................................................................................................................................................................................................................................

Name: Anonymous 2013-03-04 5:34

>>61
False. The only mutations in the linked example implementation are in amb-collect-thunk which is not touched by amb itself. Could you stop holding down your period key too? It makes you look like a fucking idiot (though was that the intention and HIBT?)
http://bugs.call-cc.org/browser/release/4/amb/trunk/amb.scm
It is quite easy to replicate the functionality of amb without continuations, but with a load of cruft as seen in your example. I want to see amb alone.

Name: Anonymous 2013-03-04 23:23

>>70
Thanks...................................I was thrown off a little by the (require (even x))...................................................don't ask me why..........................................................................Forgot continuations.................................are..like.....................................................................................don't need....to return from....where they are...................................................................I don't like them.

Ok............I will do it.................just..give me some time....please..........

Name: Anonymous 2013-03-05 2:05

I'm.....really..not looking forward....to this. It sounds hard....I have to translate....


XS
(require (even x))
YS


to..............................................something..


XS
(require (even x) fail (lambda ()
                         YS)


how do I do......it?????

Name: Anonymous 2013-03-05 4:50

>>63
you can use Cont in StateT

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