about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-03-18 21:22:18 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-03-18 21:22:18 -0700
commitaed89b8d355915303ba9424ac01be458becc1f77 (patch)
tree30838ac582da6ce8ce13008ecc44e51c0062b2f1
parentc21cefa8881fbcdbff3206a223cbf58f0e07e5fd (diff)
downloadteliva-aed89b8d355915303ba9424ac01be458becc1f77.tar.gz
graphviz: draft notion of nodes in 'focus'
Now the REPL isn't about deciding what to calculate, but just what nodes
to calculate it for.
-rw-r--r--anagrams.tlv13
-rw-r--r--break.tlv13
-rw-r--r--gemini.tlv13
-rw-r--r--graphviz.tlv135
-rw-r--r--life.tlv13
-rw-r--r--lisp.tlv28
-rw-r--r--template.tlv13
-rw-r--r--toot-toot.tlv13
-rw-r--r--zet.tlv13
9 files changed, 230 insertions, 24 deletions
diff --git a/anagrams.tlv b/anagrams.tlv
index a1fde54..1045332 100644
--- a/anagrams.tlv
+++ b/anagrams.tlv
@@ -135,8 +135,19 @@
     >end
 - __teliva_timestamp: original
   filter:
+    >function filter(h, f)
+    >  result = {}
+    >  for k, v in pairs(h) do
+    >    if f(k, v) then
+    >      result[k] = v
+    >    end
+    >  end
+    >  return result
+    >end
+- __teliva_timestamp: original
+  ifilter:
     >-- only for arrays
-    >function filter(l, f)
+    >function ifilter(l, f)
     >  result = {}
     >  for _, x in ipairs(l) do
     >    if f(x) then
diff --git a/break.tlv b/break.tlv
index 92fbeb7..55f0e92 100644
--- a/break.tlv
+++ b/break.tlv
@@ -165,8 +165,19 @@
     >end
 - __teliva_timestamp: original
   filter:
+    >function filter(h, f)
+    >  result = {}
+    >  for k, v in pairs(h) do
+    >    if f(k, v) then
+    >      result[k] = v
+    >    end
+    >  end
+    >  return result
+    >end
+- __teliva_timestamp: original
+  ifilter:
     >-- only for arrays
-    >function filter(l, f)
+    >function ifilter(l, f)
     >  result = {}
     >  for _, x in ipairs(l) do
     >    if f(x) then
diff --git a/gemini.tlv b/gemini.tlv
index dfcd373..f6e0b8b 100644
--- a/gemini.tlv
+++ b/gemini.tlv
@@ -102,8 +102,19 @@
     >end
 - __teliva_timestamp: original
   filter:
+    >function filter(h, f)
+    >  result = {}
+    >  for k, v in pairs(h) do
+    >    if f(k, v) then
+    >      result[k] = v
+    >    end
+    >  end
+    >  return result
+    >end
+- __teliva_timestamp: original
+  ifilter:
     >-- only for arrays
-    >function filter(l, f)
+    >function ifilter(l, f)
     >  result = {}
     >  for _, x in ipairs(l) do
     >    if f(x) then
diff --git a/graphviz.tlv b/graphviz.tlv
index 9a5a776..e2ea160 100644
--- a/graphviz.tlv
+++ b/graphviz.tlv
@@ -165,8 +165,19 @@
     >end
 - __teliva_timestamp: original
   filter:
+    >function filter(h, f)
+    >  result = {}
+    >  for k, v in pairs(h) do
+    >    if f(k, v) then
+    >      result[k] = v
+    >    end
+    >  end
+    >  return result
+    >end
+- __teliva_timestamp: original
+  ifilter:
     >-- only for arrays
-    >function filter(l, f)
+    >function ifilter(l, f)
     >  result = {}
     >  for _, x in ipairs(l) do
     >    if f(x) then
@@ -867,3 +878,125 @@
     >    parse_graph(tokens, graph)
     >  end
     >end
+- __teliva_timestamp:
+    >Fri Mar 18 18:59:24 2022
+  num_nodes:
+    >function num_nodes(Graph)
+    >  local result = 0
+    >  for k, v in pairs(Graph) do
+    >    result = result+1
+    >  end
+    >  return result
+    >end
+- __teliva_timestamp:
+    >Fri Mar 18 19:00:19 2022
+  render_basic_stats:
+    >function render_basic_stats(window)
+    >  window:attrset(curses.A_BOLD)
+    >  window:mvaddstr(1, 1, 'sources: ')
+    >  window:attrset(curses.A_NORMAL)
+    >  local sources = sources(Graph)
+    >  for _, node in ipairs(sources) do
+    >    window:addstr(node)
+    >    window:addstr(' ')
+    >  end
+    >  window:attrset(curses.A_BOLD)
+    >  window:addstr('size: ')
+    >  window:attrset(curses.A_NORMAL)
+    >  window:addstr(tostring(num_nodes(Graph)))
+    >  window:addstr(' nodes')
+    >  window:mvaddstr(3, 0, '')
+    >  local lines, cols = window:getmaxyx()
+    >  for col=1,cols do
+    >    window:addstr('_')
+    >  end
+    >end
+- __teliva_timestamp:
+    >Fri Mar 18 19:01:49 2022
+  main:
+    >function main()
+    >  if #arg == 0 then
+    >    Window:clear()
+    >    print('restart this app with the name of a .dot file')
+    >    Window:refresh()
+    >    while true do Window:getch(); end
+    >  end
+    >  for _, filename in ipairs(arg) do
+    >    read_dot_file(filename, Graph)
+    >  end
+    >  Focus = sources(Graph)
+    >
+    >  while true do
+    >    render(Window)
+    >    update(Window)
+    >  end
+    >end
+- __teliva_timestamp:
+    >Fri Mar 18 19:09:56 2022
+  reachable:
+    >function reachable(graph, node)
+    >  local reached = {}
+    >  local todo = {node}
+    >  while #todo > 0 do
+    >    local curr = table.remove(todo)
+    >    if reached[curr] == nil then
+    >      reached[curr] = true
+    >      local targets = graph[curr]
+    >      if targets then
+    >        for target, _ in pairs(graph[curr]) do
+    >          table.insert(todo, target)
+    >        end
+    >      end
+    >    end
+    >  end
+    >  return reached
+    >end
+- __teliva_timestamp:
+    >Fri Mar 18 20:27:16 2022
+  bold:
+    >function bold(window, text)
+    >  window:attrset(curses.A_BOLD)
+    >  window:addstr(text)
+    >  window:attrset(curses.A_NORMAL)
+    >end
+- __teliva_timestamp:
+    >Fri Mar 18 20:30:39 2022
+  render_queries_on_focus:
+    >function render_queries_on_focus(window)
+    >  local deps = {}
+    >  local needed_by = {}
+    >  for _, node in ipairs(Focus) do
+    >    deps[node] = reachable(Graph, node)
+    >    for dep, _ in pairs(deps[node]) do
+    >      if needed_by[dep] == nil then
+    >        needed_by[dep] = {}
+    >      end
+    >      append(needed_by[dep], {node})
+    >    end
+    >  end
+    >  window:mvaddstr(10, 0, '')
+    >  bold(window, 'universal deps shared by everything in focus: ')
+    >  render_list(window, filter(needed_by, function(node, deps) return #deps == #Focus end))
+    >  for _, node in ipairs(Focus) do
+    >    local y, x = window:getyx()
+    >    window:mvaddstr(y+2, 0, '- '..node)
+    >    bold(window, ' #deps: ')
+    >    window:addstr(num_nodes(deps[node]))
+    >    bold(window, ' overlapping but not universal: ')
+    >    render_list(window, filter(deps[node], function(k, v) return #needed_by[k] > 1 and #needed_by[k] < #Focus end))
+    >    bold(window, ' unique: ')
+    >    render_list(window, filter(deps[node], function(k, v) return #needed_by[k] == 1 end))
+    >  end
+    >end
+- __teliva_timestamp:
+    >Fri Mar 18 20:32:18 2022
+  render_list:
+    >function render_list(window, h)
+    >  window:addstr('(')
+    >  window:addstr(num_nodes(h))
+    >  window:addstr(') ')
+    >  for node, _ in pairs(h) do
+    >    window:addstr(node)
+    >    window:addstr(' ')
+    >  end
+    >end
diff --git a/life.tlv b/life.tlv
index 7680093..146b56f 100644
--- a/life.tlv
+++ b/life.tlv
@@ -165,8 +165,19 @@
     >end
 - __teliva_timestamp: original
   filter:
+    >function filter(h, f)
+    >  result = {}
+    >  for k, v in pairs(h) do
+    >    if f(k, v) then
+    >      result[k] = v
+    >    end
+    >  end
+    >  return result
+    >end
+- __teliva_timestamp: original
+  ifilter:
     >-- only for arrays
-    >function filter(l, f)
+    >function ifilter(l, f)
     >  result = {}
     >  for _, x in ipairs(l) do
     >    if f(x) then
diff --git a/lisp.tlv b/lisp.tlv
index ccda0d9..47285df 100644
--- a/lisp.tlv
+++ b/lisp.tlv
@@ -81,21 +81,6 @@
     >  window:mvaddstr(oldy, oldx, '')
     >end
 - __teliva_timestamp: original
-  check_eq:
-    >function check_eq(x, expected, msg)
-    >  if x == expected then
-    >    Window:addch('.')
-    >  else
-    >    print('F - '..msg)
-    >    print('  expected '..tostring(expected)..' but got '..x)
-    >    teliva_num_test_failures = teliva_num_test_failures + 1
-    >    -- overlay first test failure on editors
-    >    if teliva_first_failure == nil then
-    >      teliva_first_failure = msg
-    >    end
-    >  end
-    >end
-- __teliva_timestamp: original
   map:
     >-- only for arrays
     >function map(l, f)
@@ -117,8 +102,19 @@
     >end
 - __teliva_timestamp: original
   filter:
+    >function filter(h, f)
+    >  result = {}
+    >  for k, v in pairs(h) do
+    >    if f(k, v) then
+    >      result[k] = v
+    >    end
+    >  end
+    >  return result
+    >end
+- __teliva_timestamp: original
+  ifilter:
     >-- only for arrays
-    >function filter(l, f)
+    >function ifilter(l, f)
     >  result = {}
     >  for _, x in ipairs(l) do
     >    if f(x) then
diff --git a/template.tlv b/template.tlv
index c335e31..bab9aa3 100644
--- a/template.tlv
+++ b/template.tlv
@@ -165,8 +165,19 @@
     >end
 - __teliva_timestamp: original
   filter:
+    >function filter(h, f)
+    >  result = {}
+    >  for k, v in pairs(h) do
+    >    if f(k, v) then
+    >      result[k] = v
+    >    end
+    >  end
+    >  return result
+    >end
+- __teliva_timestamp: original
+  ifilter:
     >-- only for arrays
-    >function filter(l, f)
+    >function ifilter(l, f)
     >  result = {}
     >  for _, x in ipairs(l) do
     >    if f(x) then
diff --git a/toot-toot.tlv b/toot-toot.tlv
index 5d90789..08fce32 100644
--- a/toot-toot.tlv
+++ b/toot-toot.tlv
@@ -150,8 +150,19 @@
     >end
 - __teliva_timestamp: original
   filter:
+    >function filter(h, f)
+    >  result = {}
+    >  for k, v in pairs(h) do
+    >    if f(k, v) then
+    >      result[k] = v
+    >    end
+    >  end
+    >  return result
+    >end
+- __teliva_timestamp: original
+  ifilter:
     >-- only for arrays
-    >function filter(l, f)
+    >function ifilter(l, f)
     >  result = {}
     >  for _, x in ipairs(l) do
     >    if f(x) then
diff --git a/zet.tlv b/zet.tlv
index 7248970..2d7387b 100644
--- a/zet.tlv
+++ b/zet.tlv
@@ -165,8 +165,19 @@
     >end
 - __teliva_timestamp: original
   filter:
+    >function filter(h, f)
+    >  result = {}
+    >  for k, v in pairs(h) do
+    >    if f(k, v) then
+    >      result[k] = v
+    >    end
+    >  end
+    >  return result
+    >end
+- __teliva_timestamp: original
+  ifilter:
     >-- only for arrays
-    >function filter(l, f)
+    >function ifilter(l, f)
     >  result = {}
     >  for _, x in ipairs(l) do
     >    if f(x) then