For example, if we want to print a truth table for a boolean function, right now the only options are:
Just use a list comprehension like [(p,q,f(p,q)) | p in [false, true], q in [false, true]] but this is not formatted nicely and hard to interpret.
Use examples/truthtable.disco which returns a nicely formatted truth table as a string, intended to be used with :print, but it's kind of magical and doesn't generalize well.
A simple idea would be just the ability to print lists in table format. Then at least the list comprehension would be formatted more nicely.
More generally we could have a special command for taking a function and printing a formatted table of its input and output values, either an exhaustive table in the case of finite inputs, or truncated in the case of infinite.
So perhaps there could be a special command :table that works in a type-directed way. When given a list expression, it prints a formatted table with one row per list element (and possibly with multiple columns depending on the type of the elements, e.g. lists or tuples). When given a function expression, it prints a table of inputs and outputs.
For example, if we want to print a truth table for a boolean function, right now the only options are:
[(p,q,f(p,q)) | p in [false, true], q in [false, true]]
but this is not formatted nicely and hard to interpret.examples/truthtable.disco
which returns a nicely formatted truth table as a string, intended to be used with:print
, but it's kind of magical and doesn't generalize well.A simple idea would be just the ability to print lists in table format. Then at least the list comprehension would be formatted more nicely.
More generally we could have a special command for taking a function and printing a formatted table of its input and output values, either an exhaustive table in the case of finite inputs, or truncated in the case of infinite.
So perhaps there could be a special command
:table
that works in a type-directed way. When given a list expression, it prints a formatted table with one row per list element (and possibly with multiple columns depending on the type of the elements, e.g. lists or tuples). When given a function expression, it prints a table of inputs and outputs.Related: #86 , #63 .