Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to rewrite vector in component-wise for statement #32

Open
ghost opened this issue Feb 18, 2020 · 0 comments
Open

Support to rewrite vector in component-wise for statement #32

ghost opened this issue Feb 18, 2020 · 0 comments

Comments

@ghost
Copy link

ghost commented Feb 18, 2020

#I'm sorry for my bad English.

I want to rewrite vector or matrix in component-wise for statement, but now neo doesn't support that.

When we rewrite some component of a vector, now we can do that with the following code .

import neo
var
    vec = vector([1, 2, 3])


for i in 0..<vec.len:
    vec[i] = 0

echo vec #result in [0, 0, 0]

Of corse, this code is enough work.

However, the following code is more useful for our neo life.

import neo

iterator mitems[T](a: var Vector[T]): var T = 
    var 
        cnt = 0

    while cnt < a.len:
        yield a[cnt]
        cnt.inc

var
    vec = vector([1, 2, 3])


for elem in vec.mitems:
    elem = 0

echo vec #result in [0, 0, 0]

'mitems' is an iterator which is implemented for seq, array and etc..., but now it is not implemented for either vector or matrix.

I wish 'mitems' is implemented for vector and matrix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants