-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbg.ijs
91 lines (78 loc) · 3.11 KB
/
dbg.ijs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
NB. Debug
NB.
NB. dbg Conj. to force verb to show debug info
NB.
NB. Copyright 2010,2011,2013,2017,2018,2020,2021,2023,2024,
NB. 2025 Igor Zhuravlov
NB.
NB. This file is part of mt
NB.
NB. mt is free software: you can redistribute it and/or
NB. modify it under the terms of the GNU Lesser General
NB. Public License as published by the Free Software
NB. Foundation, either version 3 of the License, or (at your
NB. option) any later version.
NB.
NB. mt is distributed in the hope that it will be useful, but
NB. WITHOUT ANY WARRANTY; without even the implied warranty
NB. of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
NB. See the GNU Lesser General Public License for more
NB. details.
NB.
NB. You should have received a copy of the GNU Lesser General
NB. Public License along with mt. If not, see
NB. <http://www.gnu.org/licenses/>.
NB. =========================================================
NB. Configuration
coclass 'mt'
NB. =========================================================
NB. Local definitions
NB. get shape
dbgshape=: $`($ (; <) $L:0)@.(0 < L.)
NB. failure handler
dbgfailed=: 1 : '(dbsig@dberr [ echo@(m ; ''FAILED'' ; coname))@'''''
NB. success handlers
dbgsucceed1=: 1 : '[ echo@(m ; ''SUCCEED'' ; coname@'''' , ''result'' ; dbgshape_mt_ )'
dbgsucceed2=: 1 : '[ echo@(m ; ''SUCCEED'' ; coname@'''' , ''result'' ; dbgshape_mt_ ; <@":)' NB. use (":) to avoid nonce error in (;) when result is sparsed
NB. argument(s) handlers
dbgarg1=: 2 : '] [ echo@(n ; ''MONAD''"_ : (''DYAD''"_) ; m ; coname@'''' , (''y'' ; dbgshape_mt_ ) : ((''x'' ; ''y'') ,@,. ,:& dbgshape_mt_ ))'
dbgarg2=: 2 : '] [ echo@(n ; ''MONAD''"_ : (''DYAD''"_) ; m ; coname@'''' , (''y'' ; dbgshape_mt_ ; <@":) : ((''x'' ; ''y'') ,@,. ,:&(dbgshape_mt_ ; <@":)))' NB. use (":) to avoid nonce error in (;) when result is sparsed
NB. ---------------------------------------------------------
NB. dbg1
NB. dbg2
NB.
NB. Description:
NB. Conj.s to equip verb by debug output
NB.
NB. Syntax:
NB. vdbg1=. v dbg1 title
NB. vdbg2=. v dbg2 title
NB. where
NB. title - any string to name v
NB. v - verb to switch to debug mode
NB. vdbg1 - being verb v equipped by output of its rank
NB. and valency, input's and output's shapes
NB. vdbg2 - the same output as by vdbg1 plus input's and
NB. output's values
dbg1=: 2 : '(n dbgsucceed1_mt_)@u^:(1:`((u b. 0) dbgarg1_mt_ n)) :: (n dbgfailed_mt_)'
dbg2=: 2 : '(n dbgsucceed2_mt_)@u^:(1:`((u b. 0) dbgarg2_mt_ n)) :: (n dbgfailed_mt_)'
NB. =========================================================
NB. Interface
NB. ---------------------------------------------------------
NB. dbg
NB.
NB. Description:
NB. Conj. to force verb to show debug info with verbosity
NB. defined by noun DEBUG which is defined in mt.ijs
NB.
NB. Syntax:
NB. vdbg=. v dbg title
NB. where
NB. title - any string to name v
NB. v - verb to switch to debug mode
NB. vdbg - being verb v equipped by output of debug info
NB.
NB. Application:
NB. - to debug verb '+/' in verb (+/ .*) try:
NB. C=. A ((+/ dbg_mt_ '+/') .*) B
dbg=: 2 : 'u`(u dbg1_mt_ n)`(u dbg2_mt_ n)@.(] 3 : ''DEBUG_mt_'')'