You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _posts/2024-10-01-CollaborativeEditorPatterns.md
+78-48Lines changed: 78 additions & 48 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,8 @@ There are too many books and papers that deal with a multitude of algorithms.
18
18
19
19
I will add some sections like this to explain the reason for experimenting with new paradigms. In many cases the code is too dense and will seem complicated when new techniques are introduced needlessly but Effect handlers are interesting to learn. Application though should be selective. There will be many usecases for these in the future.
20
20
21
-
So the following is an experiment.
21
+
So the following is an experiment in the sense that the code quality will be fixed only later. So, for example, global references are used to complete the code even though they
22
+
are unnecessary.
22
23
23
24
# Breaking paragraphs into lines
24
25
@@ -36,50 +37,53 @@ type entry = {
36
37
mutable score : int}
37
38
38
39
39
-
let l = ref []
40
+
let gl = ref []
40
41
41
42
let is_space= function ' ' -> true | _ -> false
42
43
43
-
let final_state (start, idx) =
44
+
let final_state l (start, idx) =
44
45
45
46
let e = {first = start; last = idx; next = -1; score = -1} in
46
47
l := !l @ [e];
47
-
Printf.printf " Final state %d %d%!" start idx
48
+
Printf.printf " Final state %d %d\n" start idx;
49
+
Printf.printf " Size of list is %d\n" (List.length !l);
50
+
l
48
51
49
52
type _ Effect.t += Skipping_spaces : (int * int ) -> unit Effect.t
50
53
51
-
let parabreak text ideal_width max_width =
54
+
let parabreak l text ideal_width max_width =
55
+
Printf.printf " parabreak\n";
52
56
let start = ref 0 in
53
57
let idx,_ =
54
58
String.fold_left (fun (idx,word_or_space) c ->
55
59
match (is_space c, word_or_space) with
56
60
| (true,true)
57
61
->
58
-
(*Printf.printf "Space at index %d, skipping\n%!" idx;*)
62
+
Printf.printf "Space at index %d, skipping\n" idx;
59
63
60
64
if !start < idx then
61
-
perform (Skipping_spaces (!start,idx));
65
+
perform (Skipping_spaces (!start,idx));
62
66
63
67
start := idx + 1;
64
68
(idx + 1,false);
65
69
| (true,false)
66
-
-> Printf.printf "No Space at index %d, skipping\n%!" idx;
70
+
-> Printf.printf "No Space at index %d, skipping\n" idx;
67
71
(idx + 1,false)
68
72
| (false,_)
69
73
->(idx + 1,true)) (0,false) text
70
74
in
71
75
72
76
if !start < idx then
77
+
Printf.printf "Final - Skipping spaces %d %d\n" !start idx;
73
78
perform (Skipping_spaces (!start,idx));
74
-
final_state (!start,idx)
75
-
let effective text =
76
-
Printf.printf "Handling effects%!";
77
-
match_with (fun () -> parabreak text 10 29)
79
+
final_state l (!start,idx)
80
+
let effective text l =
81
+
match_with (fun () -> parabreak l text 10 29)
78
82
()
79
-
{ effc = (fun (type c) (eff: c Effect.t) ->
80
-
match eff with
83
+
{ effc = (fun (type c) (eff1: c Effect.t) ->
84
+
match eff1 with
81
85
| Skipping_spaces (s,s1) -> Some (fun (k: (c,_) continuation) ->
82
-
(*Printf.printf "Skipping spaces \"%d %d\"\n%!" s s1;*)
86
+
Printf.printf "Skipping spaces \"%d %d\"\n" s s1;
83
87
84
88
let e = {first = s; last = s1; next = -1; score = -1} in
85
89
l := !l @ [e];
@@ -91,23 +95,30 @@ let effective text =
91
95
| e -> raise e
92
96
);
93
97
(* retc = fun _ -> failwith "Fatal error" *)
98
+
(* retc = (fun res -> Printf.printf "Computation returned %d: \n" (List.length !l)) *)
99
+
100
+
retc = (fun _ -> l)
94
101
95
-
retc = (fun res -> Printf.printf "Computation returned: \n")
96
102
}
97
103
98
104
99
105
type _ Effect.t += Plass_break : int -> unit Effect.t
100
106
101
107
let rec plassbreak indent idx idealwidth maxwidth =
102
-
let
103
-
lastrecord = List.nth !l idx in
108
+
(* Printf.printf "Size of list in plassbreak is %d\n " (List.length !gl); *)
109
+
110
+
if idx < (List.length !gl) then(
111
+
let jdx = idx + 1 in
112
+
let lastrecord = List.nth !gl idx in
113
+
Printf.printf "let record = List.nth !gl idx in - %d\n" idx;
104
114
let llen = ref (lastrecord.last - lastrecord.first) in
0 commit comments