[ prog / sol / mona ]

prog


Found a good "Advanced Scheme" page with good macro/continuation examples

1 2018-12-28 16:47

Finding this page (and linked slides) very helpful. Includes good examples showing more advanced macro/continuation usage.

https://people.csail.mit.edu/jhbrown/scheme/

Does anyone know of any cool applications of advanced use of continuations? Some code I could try to read?

2 2018-12-28 20:40

>>1
Continuations seem to be used for either insane abstractions like threading, tail call optimisation, & exceptions or exceeding simple things like returning multiple arguments, or return statements. I've unfortunately only ever used them for the latter like in the following function:

#!/usr/local/bin/guile -s
!#
(define (screen-file return)
  (define (screen-file-iter number)
    (define file-name (string-append (passwd:dir (getpwuid (getuid))) "/screen" (number->string number) ".png"))
    (catch 'system-error
      (lambda () (open file-name (logior O_CREAT O_EXCL)))
      (lambda response
        (if (= (system-error-errno response) EEXIST)
            (screen-file-iter (+ number 1))
            (begin (display response) (exit)))))
    (return file-name))
  (screen-file-iter 1))

(system* "ffmpeg" "-loglevel" "-8" "-f" "x11grab" "-video_size" "1366x768" "-i" ":0" "-vframes" "1" "-y" (call/cc screen-file)) 

P.S. If you started looking up continuations based off the 'what are you working on?' thread keep in mind that the anon who's using a continuation there (me) isn't actually, it's just a mutually recursive higher order function with a poorly named parameter, this thread reminded me to rename that.

3


VIP:

do not edit these