-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathutil.go
45 lines (40 loc) · 1.08 KB
/
util.go
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
// Copyright 2014 SteelSeries ApS. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// This package implements a basic LISP interpretor for embedding in a go program for scripting.
// This file implements some utilities.
package golisp
func ArrayToList(sexprs []*Data) *Data {
head := Cons(nil, EmptyCons())
lastCell := head
for _, element := range sexprs {
if element == nil {
element = EmptyCons()
}
newCell := Cons(element, nil)
ConsValue(lastCell).Cdr = newCell
lastCell = newCell
}
return Cdr(head)
}
func ArrayToListWithTail(sexprs []*Data, tail *Data) *Data {
head := Cons(nil, EmptyCons())
lastCell := head
for _, element := range sexprs {
if element == nil {
element = EmptyCons()
}
newCell := Cons(element, nil)
ConsValue(lastCell).Cdr = newCell
lastCell = newCell
}
ConsValue(lastCell).Cdr = tail
return Cdr(head)
}
func ToArray(list *Data) []*Data {
result := make([]*Data, 0)
for c := list; NotNilP(c); c = Cdr(c) {
result = append(result, Car(c))
}
return result
}