blob: 0ae433481cce3ef584ca15cf54f218bc63483b7d (
plain)
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
|
(.require
[library
[lux (.except static)
["[0]" debug]
[control
["[0]" try (.only Try)]
["[0]" exception (.only exception:)]
[parser
["<[0]>" code]]]
[data
[text
["%" \\format]]]
[macro (.only with_symbols)
["[0]" syntax (.only syntax)]]
["[0]" type (.only)
["[0]" primitive (.only primitive)]]]])
(exception: .public (wrong_type [expected Type
actual Type])
(exception.report
"Expected" (%.type expected)
"Actual" (%.type actual)))
(primitive .public Dynamic
[Type Any]
(def abstraction
(-> [Type Any] Dynamic)
(|>> primitive.abstraction))
(def representation
(-> Dynamic [Type Any])
(|>> primitive.representation))
(def .public dynamic
(syntax (_ [value <code>.any])
(with_symbols [g!value]
(in (list (` (.let [(~ g!value) (~ value)]
((~! ..abstraction) [(.type_of (~ g!value)) (~ g!value)]))))))))
(def .public static
(syntax (_ [type <code>.any
value <code>.any])
(with_symbols [g!type g!value]
(in (list (` (.let [[(~ g!type) (~ g!value)] ((~! ..representation) (~ value))]
(.is ((~! try.Try) (~ type))
(.if (.at (~! type.equivalence) (~' =)
(.type_literal (~ type)) (~ g!type))
{try.#Success (.as (~ type) (~ g!value))}
((~! exception.except) ..wrong_type [(.type_literal (~ type)) (~ g!type)]))))))))))
(def .public (format value)
(-> Dynamic (Try Text))
(let [[type value] (primitive.representation value)]
(debug.representation type value)))
)
|