Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Does the element of the slice have to be a structure #482

Closed Answered by antonmedv
lirui001 asked this question in Q&A
Discussion options

In my code,i want to use any check slice data,but my slice is about []string,i don't kown how to get element about slice in my expression.

In your example:
type Tweet struct {
Len int
}

type Env struct {
Tweets []Tweet
}

func main() {
code := all(Tweets, {.Len <= 240})

program, err := expr.Compile(code, expr.Env(Env{}))
if err != nil {
	panic(err)
}
env := Env{
	Tweets: []Tweet{{42}, {98}, {69}},
}
output, err := expr.Run(program, env)
if err != nil {
	panic(err)
}
fmt.Println(output)

}

In my example:
type Env struct {
Tweets []int
}

func main() {
code := all(Tweets, {.<= 240})

program, err := expr.Compile(code, expr.Env(Env{}))
if err != nil {
	panic(err)
}
env := Env{
	Tweets: []int{42, 98, 69},
}
output, err := expr.Run(program, env)
if err != nil {
	panic(err)
}
fmt.Println(output)

}

the code compile error:Error compiling expression: expected name

You must be logged in to vote

Replies: 1 comment

Comment options

Use #

You must be logged in to vote
0 replies
Answer selected by antonmedv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /