Macro list separated by plus

#1

Hopefully there’s some kind of escape sequence for this.

    pub fn dot(self, rhs: Self) -> f64 {
        $( self.$x * rhs.$x )++
    }
0 Likes

#2

Don’t believe so.

Split $x into a head and tail, then use $head $(+ $tail)*.

0 Likes

#3

Thanks, that’s a good idea, but it makes all the other uses of the list messier. :frowning:

Here’s what I’m doing right now:

        let mut dot = 0.0;
        $( dot += self.$x * rhs.$x; )+
        dot
0 Likes

#4

Combining the ideas, maybe 0.0 $(+ self.$x * rhs.$x)+ would do the trick.

1 Like