on 492ae2f help sign in
52 lines 1.1 kB history raw
1### `++rub`
3Length-decode
5The inverse of `++mat`. Accepts a cell of index `a` and a bitstring `b`
6and produces the cell whose tail `q` is the decoded atom at index `a`
7and whose head is the length of the encoded atom `q`, by which the
8offset `a` is advanced. Only used internally as a helper cue.
10Accepts
11-------
13`a` is an atom.
15`b` is a bitstring as an atom.
17Produces
18--------
20A cell of two atoms, `p` and `q`.
22Source
23------
25 ++ rub :: length-decode
26 ~/ %rub
27 |= {a/@ b/@}
28 ^- {p/@ q/@}
29 =+ ^= c
30 =+ [c=0 m=(met 0 b)]
31 |- ?< (gth c m)
32 ?. =(0 (cut 0 [(add a c) 1] b))
33 c
34 $(c +(c))
35 ?: =(0 c)
36 [1 0]
37 =+ d=(add a +(c))
38 =+ e=(add (bex (dec c)) (cut 0 [d (dec c)] b))
39 [(add (add c c) e) (cut 0 [(add d (dec c)) e] b)]
42Examples
43--------
45 ~zod/try=> `@ub`(jam 0xaaa)
46 0b1.0101.0101.0101.0010.0000
47 ~zod/try=> (rub 1 0b1.0101.0101.0101.0010.0000)
48 [p=20 q=2.730]
49 ~zod/try=> `@ux`q:(rub 1 0b1.0101.0101.0101.0010.0000)
50 0xaaa
52***