You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[]interface{} from map cannot be used as []string #789
I've had to write this instead which is a bit wild... what am I doing wrong?
func ToStringSlice(input []interface{}) ([]string, error) {
out := make([]string, len(input))
for i, val := range input {
str, ok := val.(string)
if !ok {
return nil, fmt.Errorf("element at index %d is not a string", i)
}
out[i] = str
}
return out, nil
}
func MustStringSlice(v interface{}) ([]string, error) {
raw, ok := v.([]interface{})
if !ok {
return nil, fmt.Errorf("expected []interface{}, got %T", v)
}
return ToStringSlice(raw)
}
This is very strange function. Please, explain what are your trying to do?
I have (and my hundreds of users) been using this as a hacked up language for writing small programs using embedded structs for the last 4 years. Sort, Action, and similar were layered on-top as seperate programs but that's not needed anymore with the latest developments.
The only thing that is actually missing is discrete functions within expr and this should be complete enough to move a lot of logic into the language. There's still a decent amount of odd bugs with the various representations of functions (map[string]any vs struct) but it's getting leagues better.
I know it's not the intention of the library, but I'm fairly confident this is close to being turing complete if development continues over the next couple years.
I want to ship a binary that doesn't change. Then I can ship configuration files as updates. Keeping this logic in the language allows for users to modify or remove pieces they don't want, and is far more reachable for an average user.
Activity
antonmedv commentedon May 15, 2025
Hi,
Yes, the map and filter builtin always return type is
[]any. This is by design. This makes those functions behave in an understandable way.An example:
What type of the returned expression should be?
Some versions ago, Expr would try to do some type checks and try to "inherit" type of predicate in map & filter. But this lead to a lot of confusion.
You're doing things right. Design your custom function to take
[]any. Cast to a proper type inside.KyleSanderson commentedon May 15, 2025
In that case, because it's untyped for some reason(?) which is illegal in a number of languages... it should be any. If both were clearly ints... int.
For what it's worth, this decision is workable with AI, but feels is absolutely ridiculous.
antonmedv commentedon May 16, 2025
This is very strange function. Please, explain what are your trying to do?
KyleSanderson commentedon May 17, 2025
I have (and my hundreds of users) been using this as a hacked up language for writing small programs using embedded structs for the last 4 years. Sort, Action, and similar were layered on-top as seperate programs but that's not needed anymore with the latest developments.
The only thing that is actually missing is discrete functions within expr and this should be complete enough to move a lot of logic into the language. There's still a decent amount of odd bugs with the various representations of functions (map[string]any vs struct) but it's getting leagues better.
I know it's not the intention of the library, but I'm fairly confident this is close to being turing complete if development continues over the next couple years.
antonmedv commentedon May 17, 2025
I see. But why do you need functions inside expr?
KyleSanderson commentedon May 17, 2025
I want to ship a binary that doesn't change. Then I can ship configuration files as updates. Keeping this logic in the language allows for users to modify or remove pieces they don't want, and is far more reachable for an average user.
antonmedv commentedon Sep 18, 2025
I'm converting this to discussion, as I not complete anderstend what features/or bugs should be added.
Let's discuss this and figure out the missing parts.