# kont.scm -rw-r--r-- 1.9 KiB View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
(use-modules (ice-9 control))

(define kont)
(define tmp (lambda (k)
              (set! kont k)
              (k (+ 1 2))))


(define kont)
(* 2 (+ 1 5))
(+ 1 5)
(+ 1 [])

(* 2 (reset (+ 1 (shift k (set! kont k) (k 5)))))

(* 2 (reset (+ 1 (shift k (set! kont k) (k 5)))))

(kont 7)


(begin
  (let ((x 1))
    (reset
     (display "before\n")
     (+ 1 (shift k (set! kont k) 2))
     (display x)
     (display "after\n")
     4)))

(kont (kont 9))

(* 2 (reset (+ 1
               (dynamic-wind
                 (lambda () (display "entered\n")) ; pre-hook
                 (lambda () (shift k (set! kont k) 2)) ; body
                 (lambda () (display "exited\n")) ; post-hook
                 ))))

(with-continuation-barrier
 (lambda ()
   (define tmp #t)
   (display (+ 1 (call/cc (lambda (k) (set! kont k) 3))))
   (when tmp
     (set! tmp #f)
     (kont 6)))) ;; prints 4 7

(kont 3)

(define adder
  (reset (+ 1 (shift k k))))

(define adder
  (+ 1 (call/cc (lambda (k) k))))
(adder
 (adder 5))

(define my-real-lambda
  (my-lambda t (+ 3 t)))

(my-real-lambda (my-real-lambda 7))


(define-macro (my-lambda arg-name body)
  `(reset
    (let ((,arg-name (shift k k)))
           ,body)))

(define (loop res c)
  (if (= c 3)
      res
      (loop (cons c res) (+ 1 c))))
(loop '() 0)

(let loop ((res '())
           (c 0))
  (if (= c 3)
      res
      (loop (cons c res) (+ 1 c))))

(define (range)
  (define (get-elem return)
    (let loop ((i 0))
      (set! return (call/cc (lambda (k) (set! get-elem k) (return i))))
      (loop (+ 1 i))))

  (lambda ()
    (call/cc get-elem)))

(define rg (range))
(rg)

;; (define rg (range 0 3))
;; (rg)

;; (reset
;;  ((lambda (x)
;;     (display "entered")
;;     (let* ((return (lambda (t) (shift k (set! kont k) t)))
;;            (val (return x)))
;;       (display "exited")
;;       val
;;       "hi")) 5))

;; (kont 3)


(+ 1 (+ 3 4))
(+ 1 [])

;; (* 2 (reset (+ 2 (shift k k))))