-
Notifications
You must be signed in to change notification settings - Fork 0
stdpr
Provides support for printing values for debug purposes so that value is also returned as return value.
Returns function which can be used for debug printing.
Argument (bool) defines whether returned function is actually printing anything or not:
Argument (bool) | Returned function |
---|---|
true | prints debug print |
false | does not print anything |
Format:
call(stdpr.get-pr <bool>) -> <function>
Function returned is following kind:
func(<string-to-be-printed> <value>) -> <value>
Arguments are:
- string to be printed (function prints first this string)
- value to be printed and returned from function
Even if function is such that it does not print anything value given as 2nd argument is returned from function as return value.
Note. printing to console is actually side-effect but it can be disabled by running FunL interpreter with -noprint option (as print operator is meant to be used only for debug purposes).
Is similar to get-pr but applies pretty-printing (stdpp) formatting to value before printing it.
Format:
call(stdpr.get-pp-pr <bool>) -> <function>
Example of usage: It's useful to define first own printing function(s) for example at module top level:
debpr.fnl:
ns main
import stdpr
# set debug print functions
debug = call(stdpr.get-pr true)
debugpp = call(stdpr.get-pp-pr true)
myfunc = func()
some-value = call(debug 'debug: ' list('here' 'is' 'some' 'value'))
call(debugpp 'debug pretty-printed: ' some-value)
end
main = func()
call(myfunc)
end
endns
Run it:
./funla debpr.fnl
Output is:
debug: list('here', 'is', 'some', 'value')
debug pretty-printed:
list(
'here'
'is'
'some'
'value'
)
list('here', 'is', 'some', 'value')