moodymudskipper / flow

View and Browse Code Using Flow Diagrams
https://moodymudskipper.github.io/flow/
Other
395 stars 26 forks source link

`next` and `break` #20

Open moodymudskipper opened 4 years ago

moodymudskipper commented 4 years ago

These are considered regular instructions.

I think supporting them completely might make the charts too complicated (we might have many next statements!), but ignoring them completely is not completely satisfying either.

Something like this might work.

# http://www.nomnoml.com/
[a]->[<transceiver>42:
next]
[42:
next] - [b]

[c] -> [<receiver>break]

image

They can be brighter blue for next and brighter yellow for break, as we already use bright red and green, and light versions of all these colors.

moodymudskipper commented 4 years ago

edges would be easy to add though (I think), could be made optional.

moodymudskipper commented 4 years ago

done

moodymudskipper commented 3 years ago

I really don't like how these look, and the current flow_run doesn't like them.

I think the statement "supporting them completely might make the charts too complicated (we might have many next statements!)" is not a good argument. The chart will be fine with 2 or 3 next statements, and these edges should be drawn. Basically it just extends a branch from "if" to the end node,.

Step 1 : disable current support of break and next Step 2 : implement new behavior AND make sure to make flow_run compatible

break and next that make sense should always be at the end of a yes or no branch of if, but maybe we should look at edge cases who don't make sense.

moodymudskipper commented 3 years ago

Recall() is also a special call, I wonder if it should have an edge to go back on top. I'm afraid that it could get messy if there are many calls to Recall(), but I suppose it's quite rare to have more than 1 and extremely rare to have more than 2.

Actually it's quite rare to have even 1!

find_functions <- function(
  nm, 
  packages = c("base", "methods", "utils", "grDevices", "graphics", "stats")) {
  find_functions0 <- function(funs, env) {
    if(!length(funs)) return(character(0))
    res <- sapply(funs,
      function(x) {
        f <- get(x, env)
        if(!is.function(f)) return(FALSE)
        nm %in% all.names(body(f))
      })
    # print(res)
    # browser()
    names(res[res])
  }
  funs <- list()
  for (pkg in packages) {
    funs[[pkg]] <- list()
    env <- asNamespace(pkg)
    exp_candidates <- getNamespaceExports(pkg)
    res <- find_functions0(exp_candidates, env)
    if(length(res))
      funs[[pkg]][["exported"]] <- paste0(pkg, "::", res)
    unexp_candidates <- setdiff(ls(env), exp_candidates)
    # message(print(length(unexp_candidates)))
    # print(length(unexp_candidates))
    res <- find_functions0(unexp_candidates, env)
    if(length(res))
    funs[[pkg]][["unexported"]] <- 
      paste0(pkg, ":::", res)
  }
  funs
}

find_functions("Recall")
#> $base
#> $base$exported
#> [1] "base::Recall"
#> 
#> 
#> $methods
#> $methods$exported
#>  [1] "methods::makeMethodsList"       "methods::showMethods"          
#>  [3] "methods::MethodAddCoerce"       "methods::setOldClass"          
#>  [5] "methods::linearizeMlist"        "methods::listFromMlist"        
#>  [7] "methods::balanceMethodsList"    "methods::.TraceWithMethods"    
#>  [9] "methods::insertMethod"          "methods::validObject"          
#> [11] "methods::cacheGenericsMetaData" "methods::superClassDepth"      
#> [13] "methods::MethodsListSelect"     "methods::getGroup"             
#> [15] "methods::getGroupMembers"      
#> 
#> $methods$unexported
#> [1] "methods:::insertMethodInEmptyList"
#> 
#> 
#> $utils
#> list()
#> 
#> $grDevices
#> list()
#> 
#> $graphics
#> $graphics$unexported
#> [1] "graphics:::mosaicplot.default"
#> 
#> 
#> $stats
#> $stats$exported
#> [1] "stats::embed"  "stats::kernel"
#> 
#> $stats$unexported
#> [1] "stats:::cophenetic.dendrogram"     "stats:::predict.smooth.spline.fit"
#> [3] "stats:::window.default"

Created on 2020-08-28 by the reprex package (v0.3.0)