on 492ae2f help sign in
57 lines 1.1 kB history raw
1### `++mat`
3Length-encode
5Produces a cell whose tail `q` is atom `a` with a bit representation of
6its length prepended to it (as the least significant bits). The head `p`
7is the length of `q` in bits.
9Accepts
10-------
12`a` is an atom.
14Produces
15--------
17A cell of two atoms, `p` and `q`.
19Source
20------
22 ++ mat :: length-encode
23 ~/ %mat
24 |= a/@
25 ^- {p/@ q/@}
26 ?: =(0 a)
27 [1 1]
28 =+ b=(met 0 a)
29 =+ c=(met 0 b)
30 :- (add (add c c) b)
31 (cat 0 (bex c) (mix (end 0 (dec c) b) (lsh 0 (dec c) a)))
32 ::
35Examples
36--------
38 ~zod/try=> (mat 0xaaa)
39 [p=20 q=699.024]
40 ~zod/try=> (met 0 q:(mat 0xaaa))
41 20
42 ~zod/try=> `@ub`q:(mat 0xaaa)
43 0b1010.1010.1010.1001.0000
44 ~zod/try=> =a =-(~&(- -) `@ub`0xaaa)
45 0b1010.1010.1010
46 ~zod/try=> =b =-(~&(- -) `@ub`(xeb a))
47 0b1100
48 ~zod/try=> =b =-(~&(- -) `@ub`(met 0 a))
49 0b1100
50 ~zod/try=> =c =-(~&(- -) (xeb b))
51 4
52 ~zod/try=> [`@ub`a `@ub`(end 0 (dec c) b) `@ub`(bex c)]
53 [0b1010.1010.1010 0b100 0b1.0000]
57***