utils: Add dotit.

This commit is contained in:
Sergiu Ivanov 2022-02-03 00:09:11 +01:00
parent ebd960de53
commit b2f3306731
2 changed files with 16 additions and 8 deletions

View file

@ -1,6 +1,8 @@
#lang scribble/manual #lang scribble/manual
@(require scribble/example racket/sandbox @(require scribble/example racket/sandbox
(for-label typed/racket/base graph (submod "../utils.rkt" typed))) (for-label typed/racket/base graph
(submod "../utils.rkt" typed)
(only-in typed/graph Graph)))
@title[#:tag "utils"]{dds/utils: Various Utilities} @title[#:tag "utils"]{dds/utils: Various Utilities}
@ -217,6 +219,14 @@ produces from tables.
]} ]}
@section{Additional graph utilities} @section{Additional graph utilities}
@defproc[(dotit [graph Graph]) Void]{
Typeset the graph via graphviz and display it.
@examples[#:eval utils-evaluator
(require typed/graph)
(dotit (weighted-graph/directed '((1 a b) (2 b c))))
]}
@section{Pretty printing} @section{Pretty printing}

View file

@ -20,7 +20,7 @@
eval-with eval1-with auto-hash-ref/explicit auto-hash-ref/: eval-with eval1-with auto-hash-ref/explicit auto-hash-ref/:
extract-symbols any->string stringify-variable-mapping string->any extract-symbols any->string stringify-variable-mapping string->any
handle-org-booleans map-sexp read-org-sexp unorg unstringify-pairs handle-org-booleans map-sexp read-org-sexp unorg unstringify-pairs
read-org-variable-mapping unorgv) read-org-variable-mapping unorgv dotit)
(define-type Variable Symbol) (define-type Variable Symbol)
(define-type (VariableMapping A) (Immutable-HashTable Variable A)) (define-type (VariableMapping A) (Immutable-HashTable Variable A))
@ -249,20 +249,21 @@
(check-equal? (hash-ref m1 'b) '(or b (not a))) (check-equal? (hash-ref m1 'b) '(or b (not a)))
(check-equal? (hash-ref m2 'b) '(or b (not a))) (check-equal? (hash-ref m2 'b) '(or b (not a)))
(check-equal? (hash-ref m3 'b) '(or b (not a))))) (check-equal? (hash-ref m3 'b) '(or b (not a)))))
(define dotit (compose display graphviz))
) )
(require 'typed) (require 'typed)
(provide eval-with eval1-with auto-hash-ref/explicit auto-hash-ref/: (provide eval-with eval1-with auto-hash-ref/explicit auto-hash-ref/:
extract-symbols any->string stringify-variable-mapping string->any extract-symbols any->string stringify-variable-mapping string->any
map-sexp read-org-sexp unorg unstringify-pairs map-sexp read-org-sexp unorg unstringify-pairs
read-org-variable-mapping unorgv) read-org-variable-mapping unorgv dotit)
;;; Untyped section. ;;; Untyped section.
(provide (provide
;; Functions ;; Functions
(contract-out [dotit (-> graph? void?)] (contract-out [read-symbol-list (-> string? (listof symbol?))]
[read-symbol-list (-> string? (listof symbol?))]
[drop-first-last (-> string? string?)] [drop-first-last (-> string? string?)]
[list-sets->list-strings (-> (listof (set/c any/c)) (listof string?))] [list-sets->list-strings (-> (listof (set/c any/c)) (listof string?))]
[pretty-print-set-sets (-> (set/c (set/c symbol?) #:kind 'dont-care) string?)] [pretty-print-set-sets (-> (set/c (set/c symbol?) #:kind 'dont-care) string?)]
@ -309,9 +310,6 @@
(or/c (list/c key-contract val-contract) (or/c (list/c key-contract val-contract)
(cons/c key-contract val-contract))) (cons/c key-contract val-contract)))
;;; Typeset the graph via graphviz and display it.
(define dotit (compose display graphviz))
;;; Reads a list of symbols from a string. ;;; Reads a list of symbols from a string.
(define (read-symbol-list str) (define (read-symbol-list str)
(string->any (string-append "(" str ")"))) (string->any (string-append "(" str ")")))