Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ STDLIB := $(STDLIB_ORIGINALS:scripts/rewrite-core/originals/%=%)
STDLIB_ORIGINALS := $(addprefix scripts/rewrite-core/originals/,$(STDLIB))
STDLIB_TARGETS := $(addprefix pkg/stdlib/glojure/,$(STDLIB:.clj=.glj))

TEST_FILES := $(shell find ./test -name '*.glj')
TEST_FILES := $(shell find ./test -name '*.glj' | sort)
TEST_TARGETS := $(addsuffix .test,$(TEST_FILES))

GOPLATFORMS := darwin_arm64 darwin_amd64 linux_arm64 linux_amd64 windows_amd64 windows_arm js_wasm
Expand Down Expand Up @@ -60,3 +60,10 @@ $(TEST_TARGETS): gocmd

.PHONY: test
test: vet $(TEST_TARGETS)

.PHONY: format
format:
@if go fmt ./... | grep -q .; then \
echo "Files were formatted. Please commit the changes."; \
exit 1; \
fi
2 changes: 0 additions & 2 deletions internal/deps/pull.go
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
package deps


8 changes: 4 additions & 4 deletions internal/persistent/vector/vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ type Vector interface {

// Iterator is an iterator over vector elements. It can be used like this:
//
// for it := v.Iterator(); it.HasElem(); it.Next() {
// elem := it.Elem()
// // do something with elem...
// }
// for it := v.Iterator(); it.HasElem(); it.Next() {
// elem := it.Elem()
// // do something with elem...
// }
type Iterator interface {
// Elem returns the element at the current position.
Elem() interface{}
Expand Down
2 changes: 2 additions & 0 deletions pkg/gen/gljimports/gljimports_darwin_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -3466,6 +3466,7 @@ func RegisterImports(_register func(string, interface{})) {
_register("github.com/glojurelang/glojure/pkg/lang.ChunkedCons", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.ChunkedCons)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.*ChunkedCons", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.ChunkedCons)(nil)))
_register("github.com/glojurelang/glojure/pkg/lang.CloneThreadBindingFrame", github_com_glojurelang_glojure_pkg_lang.CloneThreadBindingFrame)
_register("github.com/glojurelang/glojure/pkg/lang.Compare", github_com_glojurelang_glojure_pkg_lang.Compare)
_register("github.com/glojurelang/glojure/pkg/lang.Comparer", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.Comparer)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.ConcatStrings", github_com_glojurelang_glojure_pkg_lang.ConcatStrings)
_register("github.com/glojurelang/glojure/pkg/lang.Conj", github_com_glojurelang_glojure_pkg_lang.Conj)
Expand Down Expand Up @@ -3888,6 +3889,7 @@ func RegisterImports(_register func(string, interface{})) {
_register("github.com/glojurelang/glojure/pkg/lang.SliceSeq", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.SliceSeq)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.*SliceSeq", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.SliceSeq)(nil)))
_register("github.com/glojurelang/glojure/pkg/lang.SliceSet", github_com_glojurelang_glojure_pkg_lang.SliceSet)
_register("github.com/glojurelang/glojure/pkg/lang.SortSlice", github_com_glojurelang_glojure_pkg_lang.SortSlice)
_register("github.com/glojurelang/glojure/pkg/lang.StackFrame", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.StackFrame)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.*StackFrame", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.StackFrame)(nil)))
_register("github.com/glojurelang/glojure/pkg/lang.Stacker", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.Stacker)(nil)).Elem())
Expand Down
2 changes: 2 additions & 0 deletions pkg/gen/gljimports/gljimports_darwin_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -3466,6 +3466,7 @@ func RegisterImports(_register func(string, interface{})) {
_register("github.com/glojurelang/glojure/pkg/lang.ChunkedCons", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.ChunkedCons)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.*ChunkedCons", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.ChunkedCons)(nil)))
_register("github.com/glojurelang/glojure/pkg/lang.CloneThreadBindingFrame", github_com_glojurelang_glojure_pkg_lang.CloneThreadBindingFrame)
_register("github.com/glojurelang/glojure/pkg/lang.Compare", github_com_glojurelang_glojure_pkg_lang.Compare)
_register("github.com/glojurelang/glojure/pkg/lang.Comparer", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.Comparer)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.ConcatStrings", github_com_glojurelang_glojure_pkg_lang.ConcatStrings)
_register("github.com/glojurelang/glojure/pkg/lang.Conj", github_com_glojurelang_glojure_pkg_lang.Conj)
Expand Down Expand Up @@ -3888,6 +3889,7 @@ func RegisterImports(_register func(string, interface{})) {
_register("github.com/glojurelang/glojure/pkg/lang.SliceSeq", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.SliceSeq)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.*SliceSeq", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.SliceSeq)(nil)))
_register("github.com/glojurelang/glojure/pkg/lang.SliceSet", github_com_glojurelang_glojure_pkg_lang.SliceSet)
_register("github.com/glojurelang/glojure/pkg/lang.SortSlice", github_com_glojurelang_glojure_pkg_lang.SortSlice)
_register("github.com/glojurelang/glojure/pkg/lang.StackFrame", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.StackFrame)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.*StackFrame", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.StackFrame)(nil)))
_register("github.com/glojurelang/glojure/pkg/lang.Stacker", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.Stacker)(nil)).Elem())
Expand Down
2 changes: 2 additions & 0 deletions pkg/gen/gljimports/gljimports_js_wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3466,6 +3466,7 @@ func RegisterImports(_register func(string, interface{})) {
_register("github.com/glojurelang/glojure/pkg/lang.ChunkedCons", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.ChunkedCons)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.*ChunkedCons", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.ChunkedCons)(nil)))
_register("github.com/glojurelang/glojure/pkg/lang.CloneThreadBindingFrame", github_com_glojurelang_glojure_pkg_lang.CloneThreadBindingFrame)
_register("github.com/glojurelang/glojure/pkg/lang.Compare", github_com_glojurelang_glojure_pkg_lang.Compare)
_register("github.com/glojurelang/glojure/pkg/lang.Comparer", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.Comparer)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.ConcatStrings", github_com_glojurelang_glojure_pkg_lang.ConcatStrings)
_register("github.com/glojurelang/glojure/pkg/lang.Conj", github_com_glojurelang_glojure_pkg_lang.Conj)
Expand Down Expand Up @@ -3888,6 +3889,7 @@ func RegisterImports(_register func(string, interface{})) {
_register("github.com/glojurelang/glojure/pkg/lang.SliceSeq", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.SliceSeq)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.*SliceSeq", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.SliceSeq)(nil)))
_register("github.com/glojurelang/glojure/pkg/lang.SliceSet", github_com_glojurelang_glojure_pkg_lang.SliceSet)
_register("github.com/glojurelang/glojure/pkg/lang.SortSlice", github_com_glojurelang_glojure_pkg_lang.SortSlice)
_register("github.com/glojurelang/glojure/pkg/lang.StackFrame", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.StackFrame)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.*StackFrame", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.StackFrame)(nil)))
_register("github.com/glojurelang/glojure/pkg/lang.Stacker", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.Stacker)(nil)).Elem())
Expand Down
2 changes: 2 additions & 0 deletions pkg/gen/gljimports/gljimports_linux_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -3466,6 +3466,7 @@ func RegisterImports(_register func(string, interface{})) {
_register("github.com/glojurelang/glojure/pkg/lang.ChunkedCons", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.ChunkedCons)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.*ChunkedCons", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.ChunkedCons)(nil)))
_register("github.com/glojurelang/glojure/pkg/lang.CloneThreadBindingFrame", github_com_glojurelang_glojure_pkg_lang.CloneThreadBindingFrame)
_register("github.com/glojurelang/glojure/pkg/lang.Compare", github_com_glojurelang_glojure_pkg_lang.Compare)
_register("github.com/glojurelang/glojure/pkg/lang.Comparer", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.Comparer)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.ConcatStrings", github_com_glojurelang_glojure_pkg_lang.ConcatStrings)
_register("github.com/glojurelang/glojure/pkg/lang.Conj", github_com_glojurelang_glojure_pkg_lang.Conj)
Expand Down Expand Up @@ -3888,6 +3889,7 @@ func RegisterImports(_register func(string, interface{})) {
_register("github.com/glojurelang/glojure/pkg/lang.SliceSeq", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.SliceSeq)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.*SliceSeq", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.SliceSeq)(nil)))
_register("github.com/glojurelang/glojure/pkg/lang.SliceSet", github_com_glojurelang_glojure_pkg_lang.SliceSet)
_register("github.com/glojurelang/glojure/pkg/lang.SortSlice", github_com_glojurelang_glojure_pkg_lang.SortSlice)
_register("github.com/glojurelang/glojure/pkg/lang.StackFrame", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.StackFrame)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.*StackFrame", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.StackFrame)(nil)))
_register("github.com/glojurelang/glojure/pkg/lang.Stacker", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.Stacker)(nil)).Elem())
Expand Down
2 changes: 2 additions & 0 deletions pkg/gen/gljimports/gljimports_linux_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -3466,6 +3466,7 @@ func RegisterImports(_register func(string, interface{})) {
_register("github.com/glojurelang/glojure/pkg/lang.ChunkedCons", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.ChunkedCons)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.*ChunkedCons", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.ChunkedCons)(nil)))
_register("github.com/glojurelang/glojure/pkg/lang.CloneThreadBindingFrame", github_com_glojurelang_glojure_pkg_lang.CloneThreadBindingFrame)
_register("github.com/glojurelang/glojure/pkg/lang.Compare", github_com_glojurelang_glojure_pkg_lang.Compare)
_register("github.com/glojurelang/glojure/pkg/lang.Comparer", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.Comparer)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.ConcatStrings", github_com_glojurelang_glojure_pkg_lang.ConcatStrings)
_register("github.com/glojurelang/glojure/pkg/lang.Conj", github_com_glojurelang_glojure_pkg_lang.Conj)
Expand Down Expand Up @@ -3888,6 +3889,7 @@ func RegisterImports(_register func(string, interface{})) {
_register("github.com/glojurelang/glojure/pkg/lang.SliceSeq", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.SliceSeq)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.*SliceSeq", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.SliceSeq)(nil)))
_register("github.com/glojurelang/glojure/pkg/lang.SliceSet", github_com_glojurelang_glojure_pkg_lang.SliceSet)
_register("github.com/glojurelang/glojure/pkg/lang.SortSlice", github_com_glojurelang_glojure_pkg_lang.SortSlice)
_register("github.com/glojurelang/glojure/pkg/lang.StackFrame", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.StackFrame)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.*StackFrame", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.StackFrame)(nil)))
_register("github.com/glojurelang/glojure/pkg/lang.Stacker", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.Stacker)(nil)).Elem())
Expand Down
2 changes: 2 additions & 0 deletions pkg/gen/gljimports/gljimports_windows_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -3466,6 +3466,7 @@ func RegisterImports(_register func(string, interface{})) {
_register("github.com/glojurelang/glojure/pkg/lang.ChunkedCons", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.ChunkedCons)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.*ChunkedCons", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.ChunkedCons)(nil)))
_register("github.com/glojurelang/glojure/pkg/lang.CloneThreadBindingFrame", github_com_glojurelang_glojure_pkg_lang.CloneThreadBindingFrame)
_register("github.com/glojurelang/glojure/pkg/lang.Compare", github_com_glojurelang_glojure_pkg_lang.Compare)
_register("github.com/glojurelang/glojure/pkg/lang.Comparer", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.Comparer)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.ConcatStrings", github_com_glojurelang_glojure_pkg_lang.ConcatStrings)
_register("github.com/glojurelang/glojure/pkg/lang.Conj", github_com_glojurelang_glojure_pkg_lang.Conj)
Expand Down Expand Up @@ -3888,6 +3889,7 @@ func RegisterImports(_register func(string, interface{})) {
_register("github.com/glojurelang/glojure/pkg/lang.SliceSeq", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.SliceSeq)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.*SliceSeq", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.SliceSeq)(nil)))
_register("github.com/glojurelang/glojure/pkg/lang.SliceSet", github_com_glojurelang_glojure_pkg_lang.SliceSet)
_register("github.com/glojurelang/glojure/pkg/lang.SortSlice", github_com_glojurelang_glojure_pkg_lang.SortSlice)
_register("github.com/glojurelang/glojure/pkg/lang.StackFrame", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.StackFrame)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.*StackFrame", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.StackFrame)(nil)))
_register("github.com/glojurelang/glojure/pkg/lang.Stacker", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.Stacker)(nil)).Elem())
Expand Down
2 changes: 2 additions & 0 deletions pkg/gen/gljimports/gljimports_windows_arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3466,6 +3466,7 @@ func RegisterImports(_register func(string, interface{})) {
_register("github.com/glojurelang/glojure/pkg/lang.ChunkedCons", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.ChunkedCons)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.*ChunkedCons", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.ChunkedCons)(nil)))
_register("github.com/glojurelang/glojure/pkg/lang.CloneThreadBindingFrame", github_com_glojurelang_glojure_pkg_lang.CloneThreadBindingFrame)
_register("github.com/glojurelang/glojure/pkg/lang.Compare", github_com_glojurelang_glojure_pkg_lang.Compare)
_register("github.com/glojurelang/glojure/pkg/lang.Comparer", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.Comparer)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.ConcatStrings", github_com_glojurelang_glojure_pkg_lang.ConcatStrings)
_register("github.com/glojurelang/glojure/pkg/lang.Conj", github_com_glojurelang_glojure_pkg_lang.Conj)
Expand Down Expand Up @@ -3888,6 +3889,7 @@ func RegisterImports(_register func(string, interface{})) {
_register("github.com/glojurelang/glojure/pkg/lang.SliceSeq", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.SliceSeq)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.*SliceSeq", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.SliceSeq)(nil)))
_register("github.com/glojurelang/glojure/pkg/lang.SliceSet", github_com_glojurelang_glojure_pkg_lang.SliceSet)
_register("github.com/glojurelang/glojure/pkg/lang.SortSlice", github_com_glojurelang_glojure_pkg_lang.SortSlice)
_register("github.com/glojurelang/glojure/pkg/lang.StackFrame", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.StackFrame)(nil)).Elem())
_register("github.com/glojurelang/glojure/pkg/lang.*StackFrame", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.StackFrame)(nil)))
_register("github.com/glojurelang/glojure/pkg/lang.Stacker", reflect.TypeOf((*github_com_glojurelang_glojure_pkg_lang.Stacker)(nil)).Elem())
Expand Down
1 change: 1 addition & 0 deletions pkg/lang/apersistentvector.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type (
IPersistentVector
IHashEq
Reversible
Comparer
}

apvSeq struct {
Expand Down
7 changes: 7 additions & 0 deletions pkg/lang/keyword.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,10 @@ func (k Keyword) ApplyTo(args ISeq) interface{} {
func (k Keyword) Hash() uint32 {
return k.hash
}

func (k Keyword) Compare(other any) int {
if otherKw, ok := other.(Keyword); ok {
return strings.Compare(k.String(), otherKw.String())
}
panic(NewIllegalArgumentError(fmt.Sprintf("Cannot compare Keyword with %T", other)))
}
28 changes: 28 additions & 0 deletions pkg/lang/mapentry.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package lang

import "fmt"

// MapEntry represents a key-value pair in a map.
type MapEntry struct {
hasheq uint32
Expand Down Expand Up @@ -118,3 +120,29 @@ func (me *MapEntry) ValAt(key any) any {
func (me *MapEntry) ValAtDefault(key, notFound any) any {
return apersistentVectorValAtDefault(me, key, notFound)
}

func (me *MapEntry) Compare(other any) int {
otherVec, ok := other.(IPersistentVector)
if !ok {
panic(NewIllegalArgumentError(fmt.Sprintf("Cannot compare MapEntry with %T", other)))
}

myCount := me.Count()
otherCount := otherVec.Count()

// Compare lengths first
if myCount < otherCount {
return -1
} else if myCount > otherCount {
return 1
}

// Compare element by element
for i := 0; i < myCount; i++ {
cmp := Compare(me.Nth(i), otherVec.Nth(i))
if cmp != 0 {
return cmp
}
}
return 0
}
10 changes: 10 additions & 0 deletions pkg/lang/numbers.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ func (nm *NumberMethods) Equiv(x, y any) bool {
return Ops(x).Combine(Ops(y)).Equiv(x, y)
}

func (nm *NumberMethods) Compare(x, y any) int {
ops := Ops(x).Combine(Ops(y))
if ops.LT(x, y) {
return -1
} else if ops.LT(y, x) {
return 1
}
return 0
}

func (nm *NumberMethods) Floats(x any) []float32 {
return x.([]float32)
}
Expand Down
58 changes: 56 additions & 2 deletions pkg/lang/slices.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,68 @@ func SliceSet(slc any, idx int, val any) {
}

func ToSlice(x any) []any {
// Handle nil - Clojure returns empty array for nil
if IsNil(x) {
return nil
return []any{}
}

// Handle []any - return as-is
if slice, ok := x.([]any); ok {
return slice
}

// Handle IPersistentVector
if vec, ok := x.(IPersistentVector); ok {
count := vec.Count()
res := make([]any, count)
for i := 0; i < count; i++ {
res[i] = vec.Nth(i)
}
return res
}

// Handle IPersistentMap - convert to array of MapEntry objects
if m, ok := x.(IPersistentMap); ok {
seq := m.Seq()
res := make([]any, 0, m.Count())
for seq != nil {
res = append(res, seq.First()) // Each element is a MapEntry
seq = seq.Next()
}
return res
}

// Handle Set - convert to array of values
if s, ok := x.(*Set); ok {
seq := s.Seq()
res := make([]any, 0, s.Count())
for seq != nil {
res = append(res, seq.First())
seq = seq.Next()
}
return res
}

// Handle string - convert to character array
if s, ok := x.(string); ok {
runes := []rune(s) // Important: use runes for proper Unicode handling
res := make([]any, len(runes))
for i, ch := range runes {
res[i] = NewChar(ch) // Convert each rune to Char
}
return res
}

// Handle ISeq
if s, ok := x.(ISeq); ok {
res := make([]interface{}, 0, Count(x))
for s := Seq(s); s != nil; s = s.Next() {
res = append(res, s.First())
}
return res
}

// Handle reflection-based slice/array
xVal := reflect.ValueOf(x)
if xVal.Kind() == reflect.Slice || xVal.Kind() == reflect.Array {
res := make([]interface{}, xVal.Len())
Expand All @@ -29,5 +81,7 @@ func ToSlice(x any) []any {
}
return res
}
panic(fmt.Errorf("ToSlice not supported on type: %T", x))

// Error with Clojure-style message
panic(NewIllegalArgumentError(fmt.Sprintf("Unable to convert: %T to Object[]", x)))
}
Loading