-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalue.go
More file actions
66 lines (58 loc) · 1.15 KB
/
value.go
File metadata and controls
66 lines (58 loc) · 1.15 KB
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
//
// Copyright (c) 2022-2025 Markku Rossi
//
// All rights reserved.
//
package scheme
import (
"fmt"
"github.com/markkurossi/scheme/types"
)
var (
_ Value = &Number{}
_ Value = &BigInt{}
_ Value = &BigFloat{}
_ Value = Int(0)
_ Value = Float(0.0)
_ Value = &Bytevector{}
_ Value = &Frame{}
_ Value = &Symbol{}
_ Value = &Lambda{}
_ Value = &PlainPair{}
_ Value = &Port{}
_ Value = &EOFObject{}
_ Value = &Vector{}
_ Value = Boolean(true)
_ Value = Character('@')
_ Value = String("string")
_ Value = &Error{}
)
// Value implements a Scheme value.
type Value interface {
Scheme() string
Eq(o Value) bool
Equal(o Value) bool
Type() *types.Type
Unbox() (Value, *types.Type)
}
// ToString returns a display representation of the value.
func ToString(v Value) string {
if v == nil {
return "'()"
}
return fmt.Sprintf("%v", v)
}
// ToScheme returns a Scheme representation of the value.
func ToScheme(v Value) string {
if v == nil {
return "'()"
}
return v.Scheme()
}
// Unbox returns the value and its type from the boxed value v.
func Unbox(v Value) (Value, *types.Type) {
if v == nil {
return v, types.Nil
}
return v.Unbox()
}