curry.backends.py.graph.copy module

Code to copy Curry expressions.

class curry.backends.py.graph.copy.GraphCopier(skipper=None)[source]

Bases: object

Deep-copies an expression. The skipper can be used to remove nodes. This can be used to remove forward nodes and set guards from values.

The traversal keeps its own stack, so a deep graph such as a long list cannot exhaust the Python stack. The copy of a node is created, and recorded in the memo, before its successors are copied. So a node reached by several paths is copied once, the copy keeps the sharing, and a cycle in the graph becomes a cycle in the copy.

class curry.backends.py.graph.copy.Skipper(skipfwd=False, skipgrds=None)[source]

Bases: object

Indicates which nodes to skip. If a node should be skipped, the __call__ method should return its replacement.

curry.backends.py.graph.copy.copygraph(expr, memo=None, **kwds)[source]

Copies a Curry expression with the option to remove certain nodes.

Parameters:
  • expr – An instance of graph.Node or a built-in type such as int, str, or float.

  • memo – A dictionary that maps the ID of a node to its copy. See GraphCopier.

  • skipfwd – Indicates whether to skip FWD nodes.

  • skipgrds – A container of set identifer indicating which set guards to skip.

Returns:

A deep copy of expr.

curry.backends.py.graph.copy.copynode(expr, mapf=None)[source]

Makes a shallow copy of a Curry expression.

Parameters:
  • expr – The expression to copy. Can be an instance of graph.Node or a built-in type such as int, str, or float.

  • mapf – An optional map function. If supplied, this function will be applied to the successors.

Returns:

A shallow copy of expr.