Skip to content

Can't use bigint as count for repeat #55

Closed as not planned
Closed as not planned

Description

@jfhamlin

Actual

user=> (repeat 2N 1)
argument 0: cannot coerce *lang.BigInt to int64

Expected

user=> (repeat 2N 1)
(1 1)

Activity

  1. mateodif commented on Nov 13, 2023

    @mateodif
    Contributor

    I've been looking into this issue.

    Here's what I got so far:
    The coercion of values happens in coerceGoValue, in apply.go.

    • There are a couple special cases (for Slice and Func) and a default case that should handle the rest.
    • We don't seem to handle pointers, which is the case for this particular issue (*lang.BigInt). This can be easily fixed by checking for reflect.Ptr in the default case.
    • BigInt, BigDecimal, etc are wrappers of their native types i.e. big.Int, big.Decimal respectively.
      • This causes the Convert function of reflect to not be able to know how to convert the type to, for example, int64.
      • These wrapper types have internal methods for converting to types such as Int64(), String(), etc.

    A way of going around this issue would be to use something like MethodByName and check for methods with the same name as the targetType. This is a bit ugly, and we have the issue that MethodByName is case sensitive, although that could be easily fixed by getting the native type as a string and doing .Title() to it or with a helper function.

    I have a working solution based on these points, but I recognize that it's an ugly hack. Let me know your thoughts.

  2. jfhamlin commented on Nov 14, 2023

    @jfhamlin
    ContributorAuthor

    Thanks for taking a look! I'm afk right now so I may be mistaken on some of this, but I think the ideal solve here is a dedicated Go implementation of Repeat for BigInt that supports the arbitrarily large count that it implies. When in doubt, refer to clojure's source for this: both core.clj and the core Java classes.

  3. jfhamlin commented on Nov 14, 2023

    @jfhamlin
    ContributorAuthor

    Looks like my memory on this was dodgy re Clojure's support for Repeat, and you're probably on the right track here!

  4. moved this to Backlog in The Boardon Aug 2, 2025
  5. moved this from Backlog to Done in The Boardon Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions