Code: Select all
debug←1 ⍝ (or 0) to turn it ON or OFF
<conditional on debug> ⎕←'Value x is',x
Code: Select all
debug←1 ⍝ (or 0) to turn it ON or OFF
<conditional on debug> ⎕←'Value x is',x
Code: Select all
mode Log msg
⍝ Log modes: (set LOGMODES to select messages to output)
⍝ D: Debug
⍝ E: Error
⍝ W: Warning
⍝ T: Transmit on WebSocket
⍝ R: Receive on WebSocket
⍝ C: Connect or Disconnect
⍝ U: Unsupported feature
→(mode∊LOGMODES)↓0
⎕←((⊃'hh:mm:ss.ffff'(1200⌶)1 ⎕DT'J'),' ',mode,':') msg
Code: Select all
LOGMODES←'D'
'D' Log 'Value x is',x
07:06:53.214 D: Value x is 42
Code: Select all
Note←{
⍝ ¨bool Note text¨
⍝ bool defaults to 1
⍝ - Use in guard of dfn (to left of colon)
⍺←1 ⋄ ⍺:0⊣⎕←⍵ ⋄ 0
}
MyFn←{
ok←⍵≡⍥,1
⎕←'Started MyFn'
ok Note'⍵ is 1': ⍝ Note displays if ok is 1
(~ok)Note'⍵ ERROR: ⍵ should be 1': ⍝ Note displays if ok is 0
⎕←'Ending MyFn'
}
MyFn 1
Started MyFn
⍵ is 1
Ending MyFn
MyFn 0
Started MyFn
⍵ ERROR: ⍵ should be 1
Ending MyFn
x←42 debug←0 ⍞←debug/'Value x is',x,⎕UCS 10 debug←1 ⍞←debug/'Value x is',x,⎕UCS 10If you do this often, then consider defining a helper function:
Val←{debug/'Value ',⍵,', is',(⍎⍵),⎕UCS 10} debug←0 ⍞←Val'x' debug←1 ⍞←Val'x' Value x, is 42Note how I leave out ⍞← from Val so it can be used identically in dfns and tradfns. If you want to include it, then you have to use a technique from Roger Hui's classic "assert" function (and use a trailing ":" in a dfn as per petermsiegel):
Val←{⍞←debug/'Value ',⍵,', is',(⍎⍵),⎕UCS 10 ⋄ _←0} ∇ foo x [1] Val'x' [2] ∇ debug←0 foo 42 debug←1 foo 42 Value x, is 42 goo←{ Val'x': 'done' } debug←0 foo 42 debug←1 foo 42 Value x, is 42