File misc_util.icn |
General purpose routines contributed by various people. This is one of several files contributing to the util package.
Author: Steve Wampler (sbw@tapestry.tucson.az.us)
This file is in the public domain.
This file is part of the util package.
Source code.Details |
Procedures: |
breadthwalk(root, getChildren)
root | node of graph to start walk at
|
getChildren |
the nodes in sequence that are reachable from the root |
Breadth-first walk of a connected graph (nodes are visited exactly once). Note that the graph can be a tree.
The second argument should be a function that, when given a node, generates the links from that node. If omitted, it defaults to:
procedure defaultGenChildren(node) suspend !\node[2] endfunction that generates a node's children
n | starting distance from this call
|
ce |
the stacktrace from current call back to first
in the co-expression |
Compute the current stack trace. Starting at level n above the current procedure. Here, n defaults to 0, which will include this procedure in the stack trace. ce defaults to ¤t. This only works with newer versions of Unicon!
co-expr to trace stack in [¤t]A | - structure to copy |
a deep copy of any structure, including cyclic ones |
deepcopy(A) produces a full copy of the structure A. All structures are handled, including all dags and cycylic graphs.
node | graph node to produce children from |
child nodes of node |
Given node represented by an indexable structure where the 2nd element is a list of links from that node, generate those links. Used as default in breadthwalk() and depthwalk().
depthwalk(root, getChildren, visited)
root | node of graph to start walk at
|
getChildren | function that generates a node's children
|
visited |
the nodes in sequence that are reachable from the root |
Depth-first walk of a connected graph (nodes are visited exactly once). Note that the graph can be a tree.
The second argument should be a function that, when given a node, generates the links from that node. If omitted, it defaults to:
procedure defaultGenChildren(node) suspend !\node[2] end
The third argument is used internally and should not be given by the user.
ignore, used internally.A PDCO that produces only the even results from its argument. <[/p> First argument must be a co-expression.
c | instance of a class |
s | name of field to produce from c |
field named s |
Returns the field named s from the class instance c. The field is not dereferenced and thus can be assigned to.
c | instance of a class |
s | name of method to produce from c |
method named s |
Returns the method named s of the class instance c. The method is not dereferenced and thus can be assigned to. Methods of superclasses may be accessed by making s a period delimited list, for example getMethod(foo, "A.b") returns the method b of the superclass of type A that foo inherits from.
the intial seed |
Initialize the random number seed to a 'random' value, so a different random sequence is generated on each run of the program. Meant to be called once, in procedure main(). . Unicon now initializes the seed by default, so this is largely moot.
a copy of the inverted table tbl |
Invert a table (will lose data unless tbl is a 1-1 mapping).
Table to invertn | (first coexpression in L) produce every
nth result |
sq | (second coexpression in L) sequence to
produce results from |
every nth result from sq |
A PDCO that wraps a result sequence sq and produces every nth result. n defaults to 1.
first arg is n, second is sq.A PDCO that produces only the odd results from its argument. <[/p> First argument must be a co-expression
all permutations of the elements in list L |
List to permute
n | (first coexpression in L) produce results
after first n results |
sq | (second coexpression in L) sequence to
produce results from |
all results after the first n from sq |
A PDCO that wraps a result sequence sq and produces all results after the first n results. n defaults to 0.
first arg is n, second is sq. the time in milliseconds to execute its argument. |
A PDCO that can be used to time expressions. (Only accurate to the millisecond level.)
Examples:
write(" [",time { writes("fib(",n,") = ",fib(n)) }, "ms]" ) write(" [", time { {every 1 to limit do { f := fib(n) } writes("fib(",n,") = ",f, " run ",limit," times.") } # Note extra braces for compound expression! } , "ms]")First arg is expression to time
L | - arbitrary number of co-expressions |
results from all the co-expressions in L by
interleaving |
A PDCO that interleaves results from its arguments. For example, the following code produces a (very fast) 'spinner':
every writes(weave{!|"-\\|/", !|"\b"})Expressions whose results are to be woven together