forked from drspro/metta-wam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nm_test.metta
executable file
·46 lines (36 loc) · 1.13 KB
/
nm_test.metta
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
!(import! &self numme)
!(extend-py! numme)
; bind a bunch of numpy objects to tokens for convenience
!(bind! &x (np.vector 1 2 3))
!(bind! &y (np.array (3 2 3)))
!(bind! &m (np.array ((6 1) (7 2) (8 3))))
!(bind! &mt (np.array ((1 0 0) (0 1 0))))
; FIXME: no exception?
!(np.vector 1 "S")
; !(np.array (1 (1 2))) ; exception because of bad shape
; wrapping into a function should work
; also works automatically with python numbers
; (no need to turn 1 into np.array)
(= (np-add-1 $x) (np.add $x 1))
!(np-add-1 (np-add-1 &x)) ; [3 4 5] ; not a pattern
; could work with untyped np objects,
; although with some problems (the resulting type would be Number),
; but doesn't work, because + expects Number
; !(+ &x &y)
!(== (np.add &y &x) (np.add &x &y)) ; True
!(== &x &y) ; False
!(== &x (np.vector 1 2)) ; False
! (np.add &m (np.vector 1 2)) ; ((7 3) (8 4) (9 5))
! (np.matmul &mt &m) ; ((6 1) (7 2))
! (np.add &m $x) ; will be turned into pattern
! (case (np.array (((1 1) (2 2) (3 3)) ((2 3) (3 4) (4 5))))
(
(($a $b $c) $b)
(($x ($y1 $y2 $y3)) (np.add $x $y2))
)
)
! (case (np.vector 1 2 3)
(
(&x "X")
)
)