-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathkeywordpkg.go
More file actions
51 lines (45 loc) · 1.23 KB
/
keywordpkg.go
File metadata and controls
51 lines (45 loc) · 1.23 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
// Copyright (c) 2022, Peter Ohler, All rights reserved.
package slip
import (
"strings"
)
// KeywordPkg is the KEYWORD package.
var (
keywordPkg *Package
KeywordPkg = Package{
Name: "keyword",
Nicknames: []string{},
Doc: "Home of keyword symbols.",
vars: map[string]*VarVal{},
lambdas: map[string]*Lambda{},
funcs: map[string]*FuncInfo{},
PreSet: keywordPreSet,
}
)
func init() {
KeywordPkg.Initialize(map[string]*VarVal{
":yes": {Val: Symbol(":yes"), Const: true, Export: true},
":no": {Val: Symbol(":no"), Const: true, Export: true},
"*keyword-package*": {Val: &KeywordPkg, Const: true, Export: true},
})
AddPackage(&KeywordPkg)
UserPkg.Use(&KeywordPkg)
keywordPkg = &KeywordPkg
}
func keywordPreSet(p *Package, name string, value Object) (string, Object) {
if len(name) == 0 {
PackagePanic(NewScope(), 0, keywordPkg, "An empty symbol is not a valid keyword.")
}
if name[0] != ':' {
name = ":" + name
}
name = strings.ToLower(name)
if vv, has := p.vars[name]; has {
if ObjectEqual(value, vv.Val) {
return name, value
}
PackagePanic(NewScope(), 0, keywordPkg, "%s is a constant and thus can't be set", name)
}
value = Symbol(name)
return name, value
}