diff --git a/pkg/lang/bigdecimal.go b/pkg/lang/bigdecimal.go index 7a9521b..286de50 100644 --- a/pkg/lang/bigdecimal.go +++ b/pkg/lang/bigdecimal.go @@ -7,9 +7,17 @@ import ( "bitbucket.org/pcastools/hash" ) -// BigDec is an arbitrary-precision decimal number. It wraps and has -// the same semantics as big.Float. big.Float is not used directly -// because it is mutable, and the core BigDecimal should not be. +// BigDec is an arbitrary-precision floating point number. It wraps +// and has the same semantics as big.Float. big.Float is not used +// directly because it is mutable, and the core BigDecimal should not +// be. +// +// TODO: swap out with a *decimal* representation. The go standard +// library big.Float is a binary floating point representation, +// which means that some decimal fractions cannot be represented +// exactly. This can lead to unexpected results when doing +// arithmetic with decimal fractions. A decimal representation +// would avoid this problem. type BigDecimal struct { val *big.Float } @@ -107,7 +115,12 @@ func (n *BigDecimal) Quotient(other *BigDecimal) *BigDecimal { } func (n *BigDecimal) Remainder(other *BigDecimal) *BigDecimal { - panic("not implemented") + quotient := new(big.Float).Quo(n.val, other.val) + intQuotient, _ := quotient.Int(nil) + intQuotientFloat := new(big.Float).SetInt(intQuotient) + product := new(big.Float).Mul(intQuotientFloat, other.val) + remainder := new(big.Float).Sub(n.val, product) + return &BigDecimal{val: remainder} } func (n *BigDecimal) Cmp(other *BigDecimal) int { diff --git a/pkg/lang/equals_test.go b/pkg/lang/equals_test.go index d0042a5..ccb9bd6 100644 --- a/pkg/lang/equals_test.go +++ b/pkg/lang/equals_test.go @@ -20,6 +20,7 @@ func TestEquiv(t *testing.T) { {NewMap(1, 2).Seq(), NewVector(NewList(1, 2)), NewList(NewVector(1, 2))}, // empty lazy seqs are equal {NewLazySeq(func() interface{} { return nil }), NewLazySeq(func() interface{} { return nil })}, + {NewList(1, 2), NewLongRange(0, 3, 1).Next()}, } for _, els := range equivs { diff --git a/pkg/lang/interfaces.go b/pkg/lang/interfaces.go index fdd499b..8adcea2 100644 --- a/pkg/lang/interfaces.go +++ b/pkg/lang/interfaces.go @@ -486,12 +486,14 @@ func Count(coll any) int { return count } -func Keys(m Associative) ISeq { - return NewMapKeySeq(Seq(m)) +func Keys(x any) ISeq { + // TODO: optimize for map case + return NewMapKeySeq(Seq(x)) } -func Vals(m Associative) ISeq { - return NewMapValSeq(Seq(m)) +func Vals(x any) ISeq { + // TODO: optimize for map case + return NewMapValSeq(Seq(x)) } func Subvec(v IPersistentVector, start, end int) IPersistentVector { diff --git a/pkg/lang/iteration.go b/pkg/lang/iteration.go index 8cc3d41..ec434f9 100644 --- a/pkg/lang/iteration.go +++ b/pkg/lang/iteration.go @@ -23,8 +23,15 @@ func MustNth(x interface{}, i int) interface{} { func Nth(x interface{}, n int) (interface{}, bool) { switch x := x.(type) { + // Deprecate this case Nther: return x.Nth(n) + case Indexed: + val := x.NthDefault(n, notFound) + if val == notFound { + return nil, false + } + return val, true case ISeq: x = Seq(x) for i := 0; i <= n; i++ { @@ -61,156 +68,3 @@ func Nth(x interface{}, n int) (interface{}, bool) { return nil, false } - -// // NewIterator returns a lazy sequence of x, f(x), f(f(x)), .... -// func NewIterator(f func(interface{}) interface{}, x interface{}) ISeq { -// return iterator{f: f, x: x} -// } - -// type iterator struct { -// f func(interface{}) interface{} -// x interface{} -// } - -// func (i iterator) xxx_sequential() {} - -// func (i iterator) Seq() ISeq { -// return i -// } - -// func (i iterator) First() interface{} { -// return i.x -// } - -// func (i iterator) Next() ISeq { -// return NewIterator(i.f, i.f(i.x)) -// } - -// func (i iterator) More() ISeq { -// nxt := i.Next() -// if nxt == nil { -// return emptyList -// } -// return nxt -// } - -// // NewValueIterator returns a lazy sequence of the values of x. -// func NewVectorIterator(x IPersistentVector, start, step int) ISeq { -// if x.Count() == 0 { -// return emptyList -// } -// return vectorIterator{v: x, start: start, step: step} -// } - -// type vectorIterator struct { -// v IPersistentVector -// start int -// step int -// } - -// func (it vectorIterator) xxx_sequential() {} - -// func (it vectorIterator) Seq() ISeq { -// return it -// } - -// func (it vectorIterator) First() interface{} { -// return it.v.Nth(it.start) -// } - -// func (it vectorIterator) Next() ISeq { -// next := it.start + it.step -// if next >= it.v.Count() || next < 0 { -// return nil -// } -// return &vectorIterator{v: it.v, start: next, step: it.step} -// } - -// func (it vectorIterator) More() ISeq { -// nxt := it.Next() -// if nxt == nil { -// return emptyList -// } -// return nxt -// } - -// // NewConcatIterator returns a sequence concatenating the given -// // sequences. -// func NewConcatIterator(colls ...interface{}) ISeq { -// var it *concatIterator -// for i := len(colls) - 1; i >= 0; i-- { -// iseq := Seq(colls[i]) -// if iseq == nil { -// continue -// } -// it = &concatIterator{seq: iseq, next: it} -// } -// if it == nil { -// return emptyList -// } -// return it -// } - -// type concatIterator struct { -// seq ISeq -// next *concatIterator -// } - -// func (i *concatIterator) xxx_sequential() {} - -// func (i *concatIterator) Seq() ISeq { -// return i -// } - -// func (i *concatIterator) First() interface{} { -// return i.seq.First() -// } - -// func (i *concatIterator) Next() ISeq { -// i = &concatIterator{seq: i.seq.Next(), next: i.next} -// for i.seq == nil { -// i = i.next -// if i == nil { -// return nil -// } -// } -// return i -// } - -// func (i *concatIterator) More() ISeq { -// nxt := i.Next() -// if nxt == nil { -// return emptyList -// } -// return nxt -// } - -// //////////////////////////////////////////////////////////////////////////////// - -// func chunkIteratorSeq(iter *reflect.MapIter) ISeq { -// const chunkSize = 32 - -// return NewLazySeq(func() interface{} { -// chunk := make([]interface{}, 0, chunkSize) -// exhausted := false -// for n := 0; n < chunkSize; n++ { -// chunk = append(chunk, NewMapEntry(iter.Key().Interface(), iter.Value().Interface())) -// if !iter.Next() { -// exhausted = true -// break -// } -// } -// if exhausted { -// return NewChunkedCons(NewSliceChunk(chunk), nil) -// } -// return NewChunkedCons(NewSliceChunk(chunk), chunkIteratorSeq(iter)) -// }) -// } - -// func NewGoMapSeq(x interface{}) ISeq { -// rng := reflect.ValueOf(x).MapRange() -// if !rng.Next() { -// return nil -// } -// return chunkIteratorSeq(rng) -// } diff --git a/pkg/lang/keyword.go b/pkg/lang/keyword.go index c6e58a7..545fa97 100644 --- a/pkg/lang/keyword.go +++ b/pkg/lang/keyword.go @@ -43,13 +43,14 @@ func (k Keyword) value() string { return k.kw.Get().(string) } -func (k Keyword) Namespace() string { - // Return the namespace of the keyword, or the empty string if it - // doesn't have one. +func (k Keyword) Namespace() any { + // Return the namespace of the keyword, or nil if it doesn't have + // one. + // TODO: support both nil and empty string namespace as clojure does if i := strings.Index(k.value(), "/"); i != -1 { return k.value()[:i] } - return "" + return nil } func (k Keyword) Name() string { @@ -61,6 +62,10 @@ func (k Keyword) Name() string { return k.value() } +func (k Keyword) Sym() *Symbol { + return InternSymbol(k.Namespace(), k.Name()) +} + func (k Keyword) String() string { return ":" + k.value() } @@ -106,14 +111,14 @@ func (k Keyword) Compare(other any) int { if s == os { return 0 } - ns := k.Namespace() - if ns == "" { - if otherKw.Namespace() != "" { + ns, ok := k.Namespace().(string) + if !ok { + if otherKw.Namespace() != nil { return -1 } } else { - ons := otherKw.Namespace() - if ons == "" { + ons, ok := otherKw.Namespace().(string) + if !ok { return 1 } nsc := strings.Compare(ns, ons) diff --git a/pkg/lang/longrange.go b/pkg/lang/longrange.go index 442b384..b64cb48 100644 --- a/pkg/lang/longrange.go +++ b/pkg/lang/longrange.go @@ -104,7 +104,7 @@ func (r *LongRange) Next() ISeq { if next >= r.end { return nil } - return &LongRange{start: next, end: r.end, step: r.step} + return &LongRange{start: next, end: r.end, step: r.step, count: r.count - 1} } func (r *LongRange) More() ISeq { diff --git a/pkg/lang/numberops.go b/pkg/lang/numberops.go index 06d397f..d48862c 100644 --- a/pkg/lang/numberops.go +++ b/pkg/lang/numberops.go @@ -427,16 +427,20 @@ func (o ratioOps) Quotient(x, y any) any { return AsRatio(x).Quotient(AsRatio(y)) } func (o ratioOps) Remainder(x, y any) any { - xRat := AsRatio(x) - yRat := AsRatio(y) + xRat := AsRatio(x).val + yRat := AsRatio(y).val - q := new(big.Int) - q.Mul(xRat.val.Num(), yRat.val.Denom()) + // BigInteger q = rx.numerator.multiply(ry.denominator).divide( + // rx.denominator.multiply(ry.numerator)); + // Number ret = Numbers.minus(x, Numbers.multiply(q, y)); + // return ret - qd := new(big.Int) - qd.Mul(xRat.val.Denom(), yRat.val.Num()) + // result should be a BigInt + qn := new(big.Int).Mul(xRat.Num(), yRat.Denom()) + qd := new(big.Int).Mul(xRat.Denom(), yRat.Num()) + rem := new(big.Int) + q, rem := qn.QuoRem(qn, qd, rem) - q.Div(q, qd) return Sub(x, Multiply(q, y)) } func (o ratioOps) LT(x, y any) bool { diff --git a/pkg/lang/numbers.go b/pkg/lang/numbers.go index 5991a7a..1400a91 100644 --- a/pkg/lang/numbers.go +++ b/pkg/lang/numbers.go @@ -98,6 +98,26 @@ func (nm *NumberMethods) Remainder(x, y any) any { return Ops(x).Combine(yops).Remainder(x, y) } +func (nm *NumberMethods) Rationalize(x any) any { + switch x := x.(type) { + case float32: + return nm.Rationalize(NewBigDecimalFromFloat64(float64(x))) + case float64: + return nm.Rationalize(NewBigDecimalFromFloat64(x)) + case *BigDecimal: + bx := x.val + rat, _ := bx.Rat(nil) + if rat.IsInt() { + return NewBigIntFromGoBigInt(rat.Num()) + } + return &Ratio{val: rat} + } + if !IsNumber(x) { + panic(fmt.Errorf("cannot rationalize %T", x)) + } + return x +} + func (nm *NumberMethods) And(x, y any) any { return bitOpsCast(x) & bitOpsCast(y) } diff --git a/pkg/lang/persistentarraymap.go b/pkg/lang/persistentarraymap.go index 25b87c5..bf1cad4 100644 --- a/pkg/lang/persistentarraymap.go +++ b/pkg/lang/persistentarraymap.go @@ -490,7 +490,7 @@ func (s *MapSeq) Drop(n int) Sequential { //////////////////////////////////////////////////////////////////////////////// func NewMapKeySeq(s ISeq) ISeq { - if s == nil { + if IsNil(s) { return nil } return &MapKeySeq{s: s} @@ -566,7 +566,7 @@ func (s *MapKeySeq) HashEq() uint32 { //////////////////////////////////////////////////////////////////////////////// func NewMapValSeq(s ISeq) ISeq { - if s == nil { + if IsNil(s) { return nil } return &MapValSeq{s: s} diff --git a/pkg/lang/ratio.go b/pkg/lang/ratio.go index d388403..2b0d334 100644 --- a/pkg/lang/ratio.go +++ b/pkg/lang/ratio.go @@ -37,7 +37,9 @@ func (r *Ratio) Denominator() *big.Int { } func (r *Ratio) BigIntegerValue() *big.Int { - return new(big.Int).Div(r.val.Num(), r.val.Denom()) + var tmp big.Int + res, _ := new(big.Int).QuoRem(r.val.Num(), r.val.Denom(), &tmp) + return res } func (r *Ratio) String() string { diff --git a/pkg/lang/stringseq.go b/pkg/lang/stringseq.go index fd1ff68..8a419e1 100644 --- a/pkg/lang/stringseq.go +++ b/pkg/lang/stringseq.go @@ -21,11 +21,15 @@ func NewStringSeq(s string, i int) *StringSeq { if len(s) == 0 { return nil } - return &StringSeq{str: []rune(s), i: i} + runes := []rune(s) + if i >= len(runes) { + return nil + } + return &StringSeq{str: runes, i: i} } func newStringSeq(s []rune, i int) *StringSeq { - if len(s) == 0 { + if len(s) == 0 || i >= len(s) { return nil } return &StringSeq{str: s, i: i} diff --git a/pkg/lang/symbol.go b/pkg/lang/symbol.go index c0b2a9c..514d7fe 100644 --- a/pkg/lang/symbol.go +++ b/pkg/lang/symbol.go @@ -14,6 +14,8 @@ type Symbol struct { var ( symbolRegex = regexp.MustCompile(`^(?:[^0-9/].*/)?(?:/|[^0-9/][^/]*)$`) + + _ IFn = (*Symbol)(nil) ) // NewSymbol creates a new symbol. @@ -34,7 +36,7 @@ func NewSymbol(s string) *Symbol { } } -func InternSymbol(ns, name interface{}) *Symbol { +func InternSymbol(ns, name any) *Symbol { if ns == nil { return NewSymbol(name.(string)) } @@ -127,7 +129,7 @@ func (s *Symbol) String() string { return s.ns + "/" + s.name } -func (s *Symbol) Equals(v interface{}) bool { +func (s *Symbol) Equals(v any) bool { if s == v { return true } @@ -145,7 +147,7 @@ func (s *Symbol) Meta() IPersistentMap { return s.meta } -func (s *Symbol) WithMeta(meta IPersistentMap) interface{} { +func (s *Symbol) WithMeta(meta IPersistentMap) any { if s.meta == meta { return s } @@ -160,3 +162,18 @@ func (s *Symbol) Hash() uint32 { h.Write([]byte(s.ns + "/" + s.name)) return h.Sum32() ^ symbolHashMask } + +func (s *Symbol) Invoke(args ...any) any { + switch len(args) { + case 1: + return Get(args[0], s) + case 2: + return GetDefault(args[0], s, args[1]) + default: + panic(NewIllegalArgumentError("symbol invoke expects 1 or 2 arguments")) + } +} + +func (s *Symbol) ApplyTo(args ISeq) any { + return s.Invoke(seqToSlice(args)...) +} diff --git a/pkg/reader/reader.go b/pkg/reader/reader.go index d1d1630..2e6b142 100644 --- a/pkg/reader/reader.go +++ b/pkg/reader/reader.go @@ -1008,7 +1008,7 @@ func (r *Reader) readNamespacedMap() (interface{}, error) { val := kv.(*lang.MapEntry).Val() keyKW, ok := key.(lang.Keyword) - if !ok || keyKW.Namespace() != "" { + if !ok || !lang.IsNil(keyKW.Namespace()) { newKeyVals = append(newKeyVals, key, val) continue } @@ -1138,6 +1138,10 @@ func (r *Reader) readNumber(numStr string) (interface{}, error) { if denomBig.ToBigInteger().Cmp(big.NewInt(0)) == 0 { return nil, r.error("divide by zero") } + // if num is 0, return 0 + if numBig.ToBigInteger().Cmp(big.NewInt(0)) == 0 { + return int64(0), nil + } return lang.NewRatioBigInt(numBig, denomBig), nil } diff --git a/pkg/stdlib/clojure/core.glj b/pkg/stdlib/clojure/core.glj index b46409f..4250275 100644 --- a/pkg/stdlib/clojure/core.glj +++ b/pkg/stdlib/clojure/core.glj @@ -4133,7 +4133,7 @@ name." {:added "1.0" :static true} - [sym] (clojure.lang.Namespace/findOrCreate sym)) + [sym] (github.com:glojurelang:glojure:pkg:lang.FindOrCreateNamespace sym)) (defn remove-ns "Removes the namespace named by the symbol. Use with caution. @@ -6308,11 +6308,11 @@ fails, attempts to require sym's namespace and retries." {:added "1.0" :static true} ([ns ^github.com:glojurelang:glojure:pkg:lang.*Symbol name] - (let [v (clojure.lang.Var/intern (the-ns ns) name)] + (let [v (.Intern (the-ns ns) name)] (when (meta name) (.setMeta v (meta name))) v)) ([ns name val] - (let [v (clojure.lang.Var/intern (the-ns ns) name val)] + (let [v (github.com:glojurelang:glojure:pkg:lang.InternVar (the-ns ns) name val true)] (when (meta name) (.setMeta v (meta name))) v))) diff --git a/pkg/stdlib/clojure/core/loader.go b/pkg/stdlib/clojure/core/loader.go index ac7e21a..9bfbf99 100644 --- a/pkg/stdlib/clojure/core/loader.go +++ b/pkg/stdlib/clojure/core/loader.go @@ -3136,7 +3136,7 @@ func LoadNS() { // *loaded-libs* { tmp0 := sym__STAR_loaded_DASH_libs_STAR_.WithMeta(lang.NewMap(kw_dynamic, true, kw_file, "clojure/core.glj", kw_line, int(5809), kw_column, int(10), kw_end_DASH_line, int(5812), kw_end_DASH_column, int(15), kw_ns, lang.FindOrCreateNamespace(sym_clojure_DOT_core))).(*lang.Symbol) - tmp1 := lang.NewRef(lang.CreatePersistentTreeSet(lang.NewSliceSeq([]any{sym_clojure_DOT_core_DOT_protocols, sym_clojure_DOT_string, sym_glojure_DOT_go_DOT_io, sym_user}))) + tmp1 := lang.NewRef(lang.CreatePersistentTreeSet(lang.NewSliceSeq([]any{sym_clojure_DOT_string, sym_user, sym_clojure_DOT_core_DOT_protocols, sym_glojure_DOT_go_DOT_io}))) var_clojure_DOT_core__STAR_loaded_DASH_libs_STAR_ = ns.InternWithValue(tmp0, tmp1, true) if tmp0.Meta() != nil { var_clojure_DOT_core__STAR_loaded_DASH_libs_STAR_.SetMeta(tmp0.Meta().(lang.IPersistentMap)) @@ -3993,7 +3993,7 @@ func LoadNS() { checkArity(args, 1) v2 := args[0] _ = v2 - tmp3 := lang.Apply(nil, []any{v2}) + tmp3 := lang.Apply(lang.FindOrCreateNamespace, []any{v2}) return tmp3 }) tmp1 = tmp1.WithMeta(lang.NewMap(kw_rettag, nil)).(lang.FnFunc) @@ -10862,7 +10862,7 @@ func LoadNS() { v2 = tmp1 _ = v2 } - tmp0 := sym_get.WithMeta(lang.NewMap(kw_arglists, lang.NewList(lang.NewVector(sym_map, sym_key), lang.NewVector(sym_map, sym_key, sym_not_DASH_found)), kw_inline, tmp1, kw_doc, "Returns the value mapped to key, not-found or nil if key not present\n in associative collection, set, string, array, or ILookup instance.", kw_file, "clojure/core.glj", kw_inline_DASH_arities, lang.CreatePersistentTreeSet(lang.NewSliceSeq([]any{int64(2), int64(3)})), kw_added, "1.0", kw_ns, lang.FindOrCreateNamespace(sym_clojure_DOT_core), kw_end_DASH_column, int(9), kw_column, int(7), kw_line, int(1488), kw_end_DASH_line, int(1488))).(*lang.Symbol) + tmp0 := sym_get.WithMeta(lang.NewMap(kw_arglists, lang.NewList(lang.NewVector(sym_map, sym_key), lang.NewVector(sym_map, sym_key, sym_not_DASH_found)), kw_inline, tmp1, kw_doc, "Returns the value mapped to key, not-found or nil if key not present\n in associative collection, set, string, array, or ILookup instance.", kw_file, "clojure/core.glj", kw_inline_DASH_arities, lang.CreatePersistentTreeSet(lang.NewSliceSeq([]any{int64(3), int64(2)})), kw_added, "1.0", kw_ns, lang.FindOrCreateNamespace(sym_clojure_DOT_core), kw_end_DASH_column, int(9), kw_column, int(7), kw_line, int(1488), kw_end_DASH_line, int(1488))).(*lang.Symbol) var tmp2 lang.FnFunc tmp2 = lang.NewFnFunc(func(args ...any) any { switch len(args) { @@ -11493,25 +11493,29 @@ func LoadNS() { // let binding "v" tmp5 := checkDerefVar(var_clojure_DOT_core_the_DASH_ns) tmp6 := lang.Apply(tmp5, []any{v2}) - tmp7 := lang.Apply(nil, []any{tmp6, v3}) - var v8 any = tmp7 - _ = v8 - var tmp9 any - tmp10 := checkDerefVar(var_clojure_DOT_core_meta) - tmp11 := lang.Apply(tmp10, []any{v3}) - if lang.IsTruthy(tmp11) { - tmp12 := checkDerefVar(var_clojure_DOT_core_meta) - tmp13 := lang.Apply(tmp12, []any{v3}) - tmp14, _ := lang.FieldOrMethod(v8, "setMeta") - if reflect.TypeOf(tmp14).Kind() != reflect.Func { + tmp7, _ := lang.FieldOrMethod(tmp6, "Intern") + if reflect.TypeOf(tmp7).Kind() != reflect.Func { + panic(lang.NewIllegalArgumentError(fmt.Sprintf("Intern is not a function"))) + } + tmp8 := lang.Apply(tmp7, []any{v3}) + var v9 any = tmp8 + _ = v9 + var tmp10 any + tmp11 := checkDerefVar(var_clojure_DOT_core_meta) + tmp12 := lang.Apply(tmp11, []any{v3}) + if lang.IsTruthy(tmp12) { + tmp13 := checkDerefVar(var_clojure_DOT_core_meta) + tmp14 := lang.Apply(tmp13, []any{v3}) + tmp15, _ := lang.FieldOrMethod(v9, "setMeta") + if reflect.TypeOf(tmp15).Kind() != reflect.Func { panic(lang.NewIllegalArgumentError(fmt.Sprintf("setMeta is not a function"))) } - tmp15 := lang.Apply(tmp14, []any{tmp13}) - tmp9 = tmp15 + tmp16 := lang.Apply(tmp15, []any{tmp14}) + tmp10 = tmp16 } else { } - _ = tmp9 - tmp4 = v8 + _ = tmp10 + tmp4 = v9 } // end let return tmp4 case 3: @@ -11526,7 +11530,7 @@ func LoadNS() { // let binding "v" tmp6 := checkDerefVar(var_clojure_DOT_core_the_DASH_ns) tmp7 := lang.Apply(tmp6, []any{v2}) - tmp8 := lang.Apply(nil, []any{tmp7, v3, v4}) + tmp8 := lang.Apply(lang.InternVar, []any{tmp7, v3, v4, true}) var v9 any = tmp8 _ = v9 var tmp10 any @@ -12698,7 +12702,7 @@ func LoadNS() { v2 = tmp1 _ = v2 } - tmp0 := sym_nth.WithMeta(lang.NewMap(kw_arglists, lang.NewList(lang.NewVector(sym_coll, sym_index), lang.NewVector(sym_coll, sym_index, sym_not_DASH_found)), kw_inline, tmp1, kw_doc, "Returns the value at the index. get returns nil if index out of\n bounds, nth throws an exception unless not-found is supplied. nth\n also works for strings, Java arrays, regex Matchers and Lists, and,\n in O(n) time, for sequences.", kw_file, "clojure/core.glj", kw_inline_DASH_arities, lang.CreatePersistentTreeSet(lang.NewSliceSeq([]any{int64(2), int64(3)})), kw_added, "1.0", kw_ns, lang.FindOrCreateNamespace(sym_clojure_DOT_core), kw_end_DASH_column, int(9), kw_column, int(7), kw_line, int(884), kw_end_DASH_line, int(884))).(*lang.Symbol) + tmp0 := sym_nth.WithMeta(lang.NewMap(kw_arglists, lang.NewList(lang.NewVector(sym_coll, sym_index), lang.NewVector(sym_coll, sym_index, sym_not_DASH_found)), kw_inline, tmp1, kw_doc, "Returns the value at the index. get returns nil if index out of\n bounds, nth throws an exception unless not-found is supplied. nth\n also works for strings, Java arrays, regex Matchers and Lists, and,\n in O(n) time, for sequences.", kw_file, "clojure/core.glj", kw_inline_DASH_arities, lang.CreatePersistentTreeSet(lang.NewSliceSeq([]any{int64(3), int64(2)})), kw_added, "1.0", kw_ns, lang.FindOrCreateNamespace(sym_clojure_DOT_core), kw_end_DASH_column, int(9), kw_column, int(7), kw_line, int(884), kw_end_DASH_line, int(884))).(*lang.Symbol) var tmp2 lang.FnFunc tmp2 = lang.NewFnFunc(func(args ...any) any { switch len(args) { @@ -32660,8 +32664,8 @@ func LoadNS() { var v8 any = tmp7 _ = v8 var tmp9 any - tmp10 := checkDerefVar(var_clojure_DOT_core__LT_) - tmp11 := checkDerefVar(var_clojure_DOT_core__LT__EQ_) + tmp10 := checkDerefVar(var_clojure_DOT_core__LT__EQ_) + tmp11 := checkDerefVar(var_clojure_DOT_core__LT_) tmp12 := lang.CreatePersistentTreeSet(lang.NewSliceSeq([]any{tmp10, tmp11})) tmp13 := lang.NewMap(kw_file, "clojure/core.glj", kw_line, int(5150), kw_column, int(11), kw_end_DASH_line, int(5150), kw_end_DASH_column, int(17)) tmp14, err := lang.WithMeta(tmp12, tmp13.(lang.IPersistentMap)) @@ -53465,7 +53469,7 @@ func LoadNS() { var tmp19 any { // let // let binding "supported" - tmp20 := lang.CreatePersistentTreeSet(lang.NewSliceSeq([]any{kw_as, kw_reload, kw_reload_DASH_all, kw_require, kw_use, kw_verbose, kw_refer, kw_as_DASH_alias})) + tmp20 := lang.CreatePersistentTreeSet(lang.NewSliceSeq([]any{kw_use, kw_refer, kw_verbose, kw_require, kw_reload_DASH_all, kw_reload, kw_as_DASH_alias, kw_as})) tmp21 := lang.NewMap(kw_file, "clojure/core.glj", kw_line, int(5951), kw_column, int(21), kw_end_DASH_line, int(5951), kw_end_DASH_column, int(86)) tmp22, err := lang.WithMeta(tmp20, tmp21.(lang.IPersistentMap)) if err != nil { @@ -55433,10 +55437,10 @@ func LoadNS() { tmp51 := reflect.TypeOf((*lang.IPersistentCollection)(nil)).Elem() tmp1.PreferMethod(tmp50, tmp51) tmp52 := reflect.TypeOf((*lang.IRecord)(nil)).Elem() - tmp53 := reflect.TypeOf((*lang.IPersistentMap)(nil)).Elem() + tmp53 := reflect.TypeOf((*lang.IPersistentCollection)(nil)).Elem() tmp1.PreferMethod(tmp52, tmp53) tmp54 := reflect.TypeOf((*lang.IRecord)(nil)).Elem() - tmp55 := reflect.TypeOf((*lang.IPersistentCollection)(nil)).Elem() + tmp55 := reflect.TypeOf((*lang.IPersistentMap)(nil)).Elem() tmp1.PreferMethod(tmp54, tmp55) var_clojure_DOT_core_print_DASH_dup = ns.InternWithValue(tmp0, tmp1, true) if tmp0.Meta() != nil { diff --git a/scripts/rewrite-core/rewrite.clj b/scripts/rewrite-core/rewrite.clj index 73cb055..a683b34 100644 --- a/scripts/rewrite-core/rewrite.clj +++ b/scripts/rewrite-core/rewrite.clj @@ -158,6 +158,12 @@ (instance? go/uint32 x) (instance? go/uint16 x) (instance? go/uint8 x)) + + ;; intern + '(clojure.lang.Var/intern (the-ns ns) name) '(.Intern (the-ns ns) name) + '(clojure.lang.Var/intern (the-ns ns) name val) '(github.com:glojurelang:glojure:pkg:lang.InternVar (the-ns ns) name val true) + ;; create-ns + 'clojure.lang.Namespace/findOrCreate 'github.com:glojurelang:glojure:pkg:lang.FindOrCreateNamespace }) (defn create-simple-replacements