Skip to content

Commit

Permalink
Fix bug in notebook refresh.
Browse files Browse the repository at this point in the history
We have much more state thatn
  • Loading branch information
dougalm committed Jan 8, 2024
1 parent c5a06ca commit 8ef1fde
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 40 deletions.
16 changes: 5 additions & 11 deletions lib/sort.dx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ it's doing bubble / insertion sort with quadratic time cost.
However, if it breaks the list in half recursively, it'll be doing parallel mergesort.
Currently the Dex compiler will do the quadratic-time version.

def concat_table(leftin: a=>v, rightin: b=>v) -> (Either a b=>v) given (a|Ix, b|Ix, v) =
def concat_table(leftin: a=>v, rightin: b=>v) -> (Either a b=>v) given (a|Ix, b|Ix, v:Type) =
for idx. case idx of
Left i -> leftin[i]
Right i -> rightin[i]
Expand Down Expand Up @@ -50,22 +50,16 @@ def merge_sorted_lists(lx: List a, ly: List a) -> List a given (a|Ord) =
newsize = nx + ny
AsList _ $ unsafe_cast_table(to=Fin newsize, sorted)

# Warning: Has quadratic runtime cost for now.
def sort(xs: n=>a) -> n=>a given (n|Ix, a|Ord) =
# Warning: Has quadratic runtime cost for now.

xlists = for i:n. (AsList 1 [xs[i]])

# Merge sort monoid:
mempty = AsList 0 []
mcombine = merge_sorted_lists

xlists = each xs \x. to_list([x])
# reduce might someday recursively subdivide the problem.
AsList(_, r) = reduce mempty mcombine xlists
AsList(_, r) = reduce xlists mempty merge_sorted_lists
unsafe_cast_table(to=n, r)

def (+|)(i:n, delta:Nat) -> n given (n|Ix) =
i' = ordinal i + delta
from_ordinal $ select (i' >= size n) (size n -| 1) i'

def is_sorted(xs:n=>a) -> Bool given (a|Ord, n|Ix) =
all for i. xs[i] <= xs[i +| 1]
all for i:n. xs[i] <= xs[i +| 1]
36 changes: 8 additions & 28 deletions static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,39 +358,19 @@ function render(renderMode:RenderMode, jsonData:string) {
source.onmessage = function(event) {
const msg = JSON.parse(event.data);
if (msg == "start") {
body.innerHTML = ""
cells.clear()
return
resetState()
} else {
processUpdates(msg)
}};}
}
const katexOptions = {
delimiters: [
{left: "$$", right: "$$", display: true},
{left: "\\[", right: "\\]", display: true},
{left: "$", right: "$", display: false},
{left: "\\(", right: "\\)", display: false}
],
// Enable commands that load resources or change HTML attributes
// (e.g. hyperlinks): https://katex.org/docs/security.html.
trust: true
};

function renderLaTeX(root:Div) {
// // Render LaTeX equations in prose blocks via KaTeX, if available.
// // Skip rendering if KaTeX is unavailable.
// let renderMathInElement: any
// if (typeof renderMathInElement == 'undefined') {
// return;
// }
// // Render LaTeX equations in prose blocks via KaTeX.
// const proseBlocks = root.querySelectorAll(".prose-block");
// Array.from(proseBlocks).map((proseBlock) =>
// renderMathInElement(proseBlock, katexOptions)
// );
function resetState() {
body.innerHTML = ""
hoverInfoDiv.innerHTML = ""
minimap.innerHTML = ""
orderedCells.length = 0
curHighlights.length = 0
cells.clear()
}

// === hover system ===

const curHighlights : [Div, string][] = [] // HTML elements currently highlighted
Expand Down
3 changes: 2 additions & 1 deletion static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ body {

/* span highlighting */
.highlight-error {
text-decoration: red wavy underline;
text-decoration: red underline;
text-decoration-thickness: 5px;
text-decoration-skip-ink: none;}
.highlight-group { background-color: yellow; }
.highlight-scope { background-color: lightyellow; }
Expand Down

0 comments on commit 8ef1fde

Please sign in to comment.