<vector> #2400
forthnutter
started this conversation in
General
<vector>
#2400
Replies: 2 comments 4 replies
-
You have to think about it as of capacity, not element count. If you want vector to contain prefilled elements, use something like n <array> >vector.
…-------- Original Message --------
On Dec 17, 2020, 13:13, Joseph Moschini wrote:
I notice something strange about word, the description is "Creates a new vector that can hold n elements before resizing".
I feed it 8 elements eg. 8 the result is always V{ } an empty vector. I would expect to get back a vector with 8 elements all zero.
It looks like the definition is always zeroing the size of the vector tuple when using boa word
: ( n -- vector ) 0 0 vector boa ; inline
would it have been better to
: ( n -- vector ) 0 >vector ; inline
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, [view it on GitHub](#2400), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AABJIT7NYWOU7UA2TK7BX7TSVHYWTANCNFSM4U7RYNTQ).
|
Beta Was this translation helpful? Give feedback.
4 replies
-
On github you have to quote with backticks : `<vector>`
It's pretty standard to create empty containers with an initial capacity,
for example in java
https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html#ArrayList-int-
So I don't think we should change anything here.
Le jeu. 17 déc. 2020 à 13:34, Joseph Moschini <notifications@github.com> a
écrit :
… sorry some don't come out way you write them on this page.
Yes I could just write 8 0 <array> >vector so what is the purpose of
<vector> if it is not intended to be initialized with a number of
elements.
If I wanted an empty vector I could just do V{ } clone .
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2400 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAVY6D335YG3AP27EJHQVTSVH3EHANCNFSM4U7RYNTQ>
.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I notice something strange about
<vector>
word, the description is "Creates a new vector that can hold n elements before resizing".I feed it 8 elements eg. 8 the result is always V{ } an empty vector. I would expect to get back a vector with 8 elements all zero.
It looks like the definition is always zeroing the size of the vector tuple when using boa word
: <vector> ( n -- vector ) 0 <array> 0 vector boa ; inline
would it have been better to
: <vector> ( n -- vector ) 0 <array> >vector ; inline
Beta Was this translation helpful? Give feedback.
All reactions