-
Notifications
You must be signed in to change notification settings - Fork 0
stdpp
Provides a capability to "pretty-print" FunL data structures so those are more readable.
Composite data structures (lists and maps) are formatted by using indentation to show nesting in easier (to read) way.
Formats value (1st arguments) as pretty-printed as returns it as string. There can be optionally 2nd argument given to specify string which is used for indentation (default is tab).
Note. if value contains only some of following data types then output string can be evaluated by eval:
- map
- list
- string
- int
- bool
- float
type: function
Format:
call(stdpp.form <value> (optional: indentation-string)) -> string
Similar to form but can be called also from procedure.
Also allows opaque values be inside value to be formatted.
type: procedure
Format:
call(stdpp.pform <value> (optional: indentation-string)) -> string
Formats given value to pretty-printed format and writes result to standard output.
Prints newline at the end.
Returns same value which was given as argument.
type: procedure
call(stdpp.pprint <value>) -> <value>
ns main
import stdpp
main = func()
v = map(
0.25 'quarter'
10 'ten'
list('some' 'key') list('some other map' map(1 2 3 4))
)
call(stdpp.form v)
end
endns
Output is:
'
map(
10
'ten'
list(
'some'
'key'
)
list(
'some other map'
map(
1
2
3
4
)
)
0.25
'quarter'
)'
ns main
import stdpp
main = proc()
import stdvar
v = list(
'some'
'text'
50
list(map('key-1' 'value-1' 'key-2' 'value-2' 'another-map' map(1 list('value'))))
func() 'dummy value' end
call(stdvar.new 'this is opaque value')
)
call(stdpp.pform v)
end
endns
Output is:
'
list(
'some'
'text'
50
list(
map(
'key-2'
'value-2'
'key-1'
'value-1'
'another-map'
map(
1
list(
'value'
)
)
)
)
func-value: file: ../pp_example2.fnl line: 14 pos: 7
opaque(var-ref('this is opaque value'))
)'
ns main
import stdpp
main = proc()
import stdvar
v = list(
list(map('key-1' 'value-1' 'key-2' 'value-2' 'another-map' map(1 list('value'))))
func() 'dummy value' end
call(stdvar.new 'this is opaque value')
)
call(stdpp.pprint v)
end
endns
Output is:
list(
list(
map(
'key-2'
'value-2'
'key-1'
'value-1'
'another-map'
map(
1
list(
'value'
)
)
)
)
func-value: file: ../pp_example3.fnl line: 11 pos: 7
opaque(var-ref('this is opaque value'))
)
list(list(map('key-2' : 'value-2', 'key-1' : 'value-1', 'another-map' : map(1 : list('value')))), func-value: file: .
./pp_example3.fnl line: 11 pos: 7, opaque(var-ref('this is opaque value')))
ns main
import stdpp
main = func()
v = map(
0.25 'quarter'
10 'ten'
list('some' 'key') list('some other map' map(1 2 3 4))
)
call(stdpp.form v '....')
end
endns
Output is:
'
map(
....10
....'ten'
....list(
........'some'
........'key'
....)
....list(
........'some other map'
........map(
............1
............2
............3
............4
........)
....)
....0.25
....'quarter'
)'