<commit_before>#lang scheme
; examples from http://courses.cs.washington.edu/courses/cse341/04wi/lectures/15-scheme-continuations.html

(define EMPTY '())
(define times *)
(define plus +)
(define id (lambda (x) x))
(define thrush (lambda (x) (lambda (y) (y x))))
(define begin (lambda (x) (plus 2 x)))
(define then (lambda (x) (times 4 x)))

(then (begin 1)) ; 12
(begin (then 1)) ; 6 (forget about it!)

((lambda (cont) (cont (begin 1)))(lambda (x) (times 4 x))) ; 12
((lambda (cont) (cont (begin 1))) then) ; 12
((thrush (begin 1)) then) ; 12 - thrush allows chain composition
(then (call/cc (thrush (begin 1)))) ; 12 - call/cc won't invert order of operands

(define continuation EMPTY) ; empty var
(define put-cont-in-var (lambda (cont) (set! continuation cont)))
;(define (put-cont-in-var cont) (set! continuation cont))
(define print-line (lambda(msg) (display msg)(newline)))

(print-line (call/cc put-cont-in-var)) ; call/cc returns void - only side effects matter
; you may now type (continuation "whatever") in the REPL

(continuation "Muzietto rulez")
(print-line "Muzietto rulez")

(define naive-find
  (lambda (pred x)
    (cond ((null? x) '())
          ((pred (car x)) (car x))
          (else (naive-find pred (cdr x))))))

(define (larger-than-two x) (> x 2))
(naive-find larger-than-two (list 1 2 3 4))

(define find (lambda (pred aList)
               (call/cc (lambda (cont)
                          (letrec ((helper (lambda (pred x)
                                             (cond ((null? x) (cont '()))
                                                   ((pred (car x)) (cont (car x)))
                                                   (else (helper pred (cdr x)))))))
                            (helper pred aList))))))

(find larger-than-two (list 0 1 2 3 4))

(define printing-naive-find
  (lambda (pred x)
    (cond ((null? x) '())
          ((pred (car x)) (car x))
          (else (let ((retval (printing-naive-find pred (cdr x))))<commit_msg>a heed of warning<commit_after>#lang scheme
; examples from http://courses.cs.washington.edu/courses/cse341/04wi/lectures/15-scheme-continuations.html

(define EMPTY '())
(define times *)
(define plus +)
(define id (lambda (x) x))
(define thrush (lambda (x) (lambda (y) (y x))))
(define begin (lambda (x) (plus 2 x)))
(define then (lambda (x) (times 4 x)))

(then (begin 1)) ; 12
(begin (then 1)) ; 6 (forget about it!)

((lambda (cont) (cont (begin 1)))(lambda (x) (times 4 x))) ; 12
((lambda (cont) (cont (begin 1))) then) ; 12
((thrush (begin 1)) then) ; 12 - thrush allows chain composition
(then (call/cc (thrush (begin 1)))) ; 12 - call/cc won't invert order of operands

(define continuation EMPTY) ; empty var
(define put-cont-in-var (lambda (cont) (set! continuation cont)))
;(define (put-cont-in-var cont) (set! continuation cont))
(define print-line (lambda(msg) (display msg)(newline)))

(print-line (call/cc put-cont-in-var)) ; call/cc returns void - only side effects matter
; you may now type (continuation "whatever") in the REPL

(continuation "Muzietto rulez")
(print-line "Muzietto rulez")

(define naive-find
  (lambda (pred x)
    (cond ((null? x) '())
          ((pred (car x)) (car x))
          (else (naive-find pred (cdr x))))))

(define (larger-than-two x) (> x 2))
(naive-find larger-than-two (list 1 2 3 4))

(define find (lambda (pred aList)
               (call/cc (lambda (cont)
                          (letrec ((helper (lambda (pred x) ; fucking 'lambda (x)' in the paper!!!!
                                             (cond ((null? x) (cont '()))
                                                   ((pred (car x)) (cont (car x)))
                                                   (else (helper pred (cdr x)))))))
                            (helper pred aList))))))

(find larger-than-two (list 0 1 2 3 4))

(define printing-naive-find
  (lambda (pred x)
    (cond ((null? x) '())
          ((pred (car x)) (car x))
          (else (let ((retval (printing-naive-find pred (cdr x))))
{'fraction_non_alphanumeric': 0.16783391695847924, 'fraction_numerical': 0.018509254627313655, 'mean_word_length': 2.4864864864864864, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3787759', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1282, 'n_words': 456}