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 3:47

(call/cc call/cc)

Name: Anonymous 2013-03-02 4:04

>>2
I need a more complete usage in order to bring the generality down to higher order functions alone...


(lambda (x) x)

Name: Anonymous 2013-03-02 4:17

ehhhhhh maybe this...

(lambda (x) (x x))

Name: THEOREM OF THE DAY 2013-03-02 4:25

Theorem. Let R be a ring and let a ∈
 Z(R). Then then the evaluation map φa : R[x] → R, φa(f(x)) = f(a) is a surjective ring homomorphism.

Name: Anonymous 2013-03-02 4:30

>>5
define "infinite set"

Name: Anonymous 2013-03-02 4:51

>>6
A countably infinite set is a set that can be put in one-to-one correspondence with the natural numbers.

Name: Anonymous 2013-03-02 5:25

>>7
define "the natural numbers"

Name: Anonymous 2013-03-02 5:39

Name: Anonymous 2013-03-02 5:48

>>8

Shalom NIKITA!

Name: Anonymous 2013-03-02 6:02

>>1
I'll give you a better task: write fibs using delimited continuations.

Name: Anonymous 2013-03-02 6:14

amb
You have 2 hours

Name: Anonymous 2013-03-02 6:16

>>9
how do you know, that "for every natural number n, if n is in K, then S(n) is in K"?

Name: Anonymous 2013-03-02 6:22

>>13
From axiom 6, step it up.

Name: Anonymous 2013-03-02 6:27

>>14
How do you know "axiom 6" is correct?

Name: Anonymous 2013-03-02 6:29

>>15

You write gibberish, please don't write random sequences of symbols.

Name: Anonymous 2013-03-02 6:43

>>16
How do you know "i write gibberish"?

Name: Anonymous 2013-03-02 6:57

>>17

Do you even write English? You know, symbols, like letters, have only meaning if you order them correctly.

Name: Anonymous 2013-03-02 8:55

Name: Anonymous 2013-03-02 9:45

>>18
How do you know?

Name: Anonymous 2013-03-02 9:46

>>20

Are you chinese or something?

Name: Anonymous 2013-03-02 9:49

>>21
How do you know?

Name: Anonymous 2013-03-02 9:50

>>22

Cannot parse alien signs.

Name: Anonymous 2013-03-02 9:50

>>23

Cannot parse alien signs.

Name: Anonymous 2013-03-02 9:51

>>24
>>26

Cannot parse alien signs.

Name: Anonymous 2013-03-02 9:51

>>25

Cannot parse alien signs.

Name: Anonymous 2013-03-02 9:54

Define "define", "cannot", "parse", "alien", "signs" and ".", Nikita.

Define Nikita.

Name: Anonymous 2013-03-02 9:55

>>1-28

Cannot parse alien signs.

Name: Anonymous 2013-03-02 9:59

>>27

Nikita:
Female name, literally delicate flower.

Female:
Female

name:
name

literally:
literally

delicate:
delicate

flower:
flower

define:
define

cannot:
cannot

parse:
parse

alien:
alien

sign:
sign, sign ..

.:
.

,:
,

::
:

Name: Anonymous 2013-03-02 10:20

>>29
AAHAHAHA NIKITA IS A FUCKING FAGGOT

Name: Anonymous 2013-03-02 10:52

I suppose there are bugs in this, but you get the idea:

(define yield-to-event-loop (lambda () (error "not set")))

(define (main-loop)
  (dispatch (get-next-event))
  (main-loop))

(define (dispatch event)
  (cond
    ; Other internal and external events
    ; ...

    ((io-event? event)
     (let ((cont (get-io-continuation (get-io-ticket event))))
       (cont (get-io-data event))))

    ((resumable? event)
     ((get-resumable-continuation event)))

    (else (unhandled-event event))))

(define (resource-manager init n)
  ; Limited number of resources, for instance file descriptors
  (define resources (make-list-of-n-resources init n))
  (define wait-queue '())

  ; Return a free resource, and wait until there is one to get
  (define (get-resource)
    (call-with-current-continuation
      (lambda (k)
        (if (null? resources)
            (begin
              ; No free resource, resume caller later
              (set! waiters (cons k wait-queue))
              (yield-to-event-loop))
            (let ((resource (car resources)))
              (set! resources (cdr resources))
              resource)))))

  ; Free a single resource and possibly let a waiting event handler run
  (define (free-resource resource)
    (call-with-current-continuation
      (lambda (k)
        (if (null? wait-queue)
            (set! resources (cons resource resources))
            (let (waiter (car wait-queue))
              (set! waiters (cdr wait-queue))

              ; Suspend the caller for a while
              (push-resumable-event k)

              ; Resume a waiting event handler
              (waiter resource)))))
    #t)

  ; Return dispatcher
  (lambda (message)
    (case message
      ((get-resource) get-resource)
      ((free-resource) free-resource)
      (else (error "unknown message")))))

(define (read-from-io-device device)
  (call-with-current-continuation
    (lambda (k)
      (let (io-ticket (schedule-read device))
        (push-event-queue-io-continuation io-ticket k)
        (start-io-event io-ticket)
        (yield-to-event-loop)))))

(define io-manager (resource-manager make-io-port 4))

; Register some event handlers
(for-each
  (lambda (event)
    (register-event-handler event
      (lambda ()
        ; Here, without continuations, you end up with node.js
        ; get-resource, free-resource and read-from-io-device all
        ; yield to the event loop if necessary
        (let ((device ((io-manager 'get-resource))))
          (display (read-from-io-device device)
          ((io-manager 'free-resource) device))))))
  '(event-1 event-2 event-3))

; Start main loop
(begin
  (call-with-current-continuation (lambda (k) (set! yield-to-event-loop k)))
  (main-loop))

Name: Anonymous 2013-03-02 11:03

>>29
it's a russian male-only name and french female name, french adopted it from russian

http://en.wikipedia.org/wiki/Nikita_(given_name)
>Beginning in the 20th century, it was adopted for female children in some countries such as France

also it has different stressing, russian name is pronounced as nik**i**ta while french one as nikit**a**

Name: Anonymous 2013-03-02 11:08

>>32

It is a Haryana name which means: as beautiful a girl as the moon.

Name: Anonymous 2013-03-02 11:09

>>33
lolol is ur nikita a girl

Name: Anonymous 2013-03-02 11:33

>>34

Yes and it's related to Yadira, which means friend in HEBREW.

Name: Anonymous 2013-03-02 11:34

Nikita Sadkov - JEW

Name: Anonymous 2013-03-02 11:39

Nikita Sadkov - JEW
Sadkov - JEW
- JEW
JEW

Name: Anonymous 2013-03-02 11:40

>>34
Why is that so many language developers are MtF transgender people? Audrey Tang, some chick from PyPy if I recall correctly, now Nikita "Delicate flower" Sadkova joins the ranks.

Name: Anonymous 2013-03-02 11:42

>>38

Audry Tang was from Pugs, Perl6 implementation in Haskell. Maybe because programmers look too much futa?

Name: Anonymous 2013-03-02 11:59

>>39

Audry tang is a faggot.

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