Extend arrays with a remove functionality. #26
MaxTymchii
started this conversation in
Ideas
Replies: 6 comments 3 replies
-
This already exists, the "._remove" function:
I consider this a failure of the documentation :( apologies for not making
it more clear.
*compiler-intrinsics* Some compiler directives are included for working
with arrays and hash tables:
hashTable = { 1:"one", 2:"two", 3:3, "str":6 };
// ._count
print( hashTable._count ); // prints 4
// ._exists
hashTable._exists( 2 ); // returns 'true'
hashTable._exists( 20 ); // returns 'false
// ._remove
hashTable._exists( 2 ); // returns 'true'
hashTable._remove( 2 );
hashTable._exists( 2 ); // now false
…On Sat, Jun 8, 2024 at 4:11 AM Max ***@***.***> wrote:
Hi there,
As I can see wrench does not support such an important action as removing
some items from an array as hash-table for example.
I tried to set null for the corresponding item but null is 0 so it's not
what I want as a result.
Now, I create a new array without this item by copying all the elements,
but it's definitely how it should work :)
—
Reply to this email directly, view it on GitHub
<#26>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AALIKA6MZ4CIWSTYU7QNBELZGK4ETAVCNFSM6AAAAABI7ZKAKWVHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZWG44TGOJRGY>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
-
OH ... removing from arrays? well.. so you mean turning:
[ 0, 1, 2, 3 ]
into
[ 0, 2, 3 ]
by removing element 1?
I could have sworn I added that.. yeah oops..
it's part of the container lib that I stubbed out and never finished!!
array::count()
array::remove( array, where [,count] )
array::insert( array, where [,count] )
hash::exists( hash, key )
hash::remove( hash, key )
Guess it's time for me to finish it :P I'll make it part of my next update,
I'm halfway through the parser re-work, so declarations like this will work:
var a = { 1, 2, { 3.1, 3.2, 3.3 }, { 4:"four"} };
nested container declaration :)
If I'm lucky I'll have it done and unit-tested within a day or so!
…-Curt
On Sat, Jun 8, 2024 at 12:59 PM Max ***@***.***> wrote:
I know about a hash table and it works for me. I am talking now about an
array. after tiny test I have also a question for hash table actually too.
var hashTable = {:};
hashTable["mock"] = "value";
hashTable["mock2"] = "value2";
hashTable["mock3"] = "value3";
var array = {1, 2, 3, 4, 5};
hashTable._remove("mock");
array._remove(2);
println( "hashTable" );
for ( var v, var k : hashTable ) {
print(v);
println(k);
}
println( "array" );
for ( var v : array ) {
println(v);
}
Result:
hashTable
00
0value3
0value2
array
1
2
3
4
5
As you can see 2 value on array is available. Hashtable shows really
interesting behavior.
P.S.: I think I can try to help you with examples on your website if you
want.
Regards,
Max.
—
Reply to this email directly, view it on GitHub
<#26 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AALIKA3LWIGCG34NRCMYSS3ZGMZ7JAVCNFSM6AAAAABI7ZKAKWVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TOMJVGI4DQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
-
it would appear foreach key and value is broken! I will fix this
immediately and put in unit tests, also the array remove is not working
either.. :(
…On Sat, Jun 8, 2024 at 1:32 PM Curt Hartung ***@***.***> wrote:
OH ... removing from arrays? well.. so you mean turning:
[ 0, 1, 2, 3 ]
into
[ 0, 2, 3 ]
by removing element 1?
I could have sworn I added that.. yeah oops..
it's part of the container lib that I stubbed out and never finished!!
array::count()
array::remove( array, where [,count] )
array::insert( array, where [,count] )
hash::exists( hash, key )
hash::remove( hash, key )
Guess it's time for me to finish it :P I'll make it part of my next
update, I'm halfway through the parser re-work, so declarations like this
will work:
var a = { 1, 2, { 3.1, 3.2, 3.3 }, { 4:"four"} };
nested container declaration :)
If I'm lucky I'll have it done and unit-tested within a day or so!
-Curt
On Sat, Jun 8, 2024 at 12:59 PM Max ***@***.***> wrote:
> I know about a hash table and it works for me. I am talking now about an
> array. after tiny test I have also a question for hash table actually too.
>
> var hashTable = {:};
> hashTable["mock"] = "value";
> hashTable["mock2"] = "value2";
> hashTable["mock3"] = "value3";
>
> var array = {1, 2, 3, 4, 5};
>
>
> hashTable._remove("mock");
> array._remove(2);
>
>
> println( "hashTable" );
> for ( var v, var k : hashTable ) {
> print(v);
> println(k);
> }
>
> println( "array" );
> for ( var v : array ) {
> println(v);
> }
>
>
> Result:
>
> hashTable
> 00
> 0value3
> 0value2
> array
> 1
> 2
> 3
> 4
> 5
>
> As you can see 2 value on array is available. Hashtable shows really
> interesting behavior.
>
> P.S.: I think I can try to help you with examples on your website if you
> want.
>
> Regards,
> Max.
>
> —
> Reply to this email directly, view it on GitHub
> <#26 (reply in thread)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AALIKA3LWIGCG34NRCMYSS3ZGMZ7JAVCNFSM6AAAAABI7ZKAKWVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TOMJVGI4DQ>
> .
> You are receiving this because you commented.Message ID:
> ***@***.***>
>
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Okay should be fixed in the latest 5.0.1 push:
var hashTable = {:};
hashTable["mock"] = "value";
hashTable["mock2"] = "value2";
hashTable["mock3"] = "value3";
var array = {1, 2, 3, 4, 5};
hashTable._remove("mock");
array._remove(2);
println( "hashTable" );
for ( var v, var k : hashTable ) {
print(v);
println(k);
}
println( "array" );
for ( var v : array ) {
println(v);
}
Result:
hashTable
mock3value3
mock2value2
array
1
2
4
5
…On Sat, Jun 8, 2024 at 4:56 PM Curt Hartung ***@***.***> wrote:
it would appear foreach key and value is broken! I will fix this
immediately and put in unit tests, also the array remove is not working
either.. :(
On Sat, Jun 8, 2024 at 1:32 PM Curt Hartung ***@***.***>
wrote:
> OH ... removing from arrays? well.. so you mean turning:
> [ 0, 1, 2, 3 ]
> into
> [ 0, 2, 3 ]
> by removing element 1?
>
> I could have sworn I added that.. yeah oops..
>
> it's part of the container lib that I stubbed out and never finished!!
>
> array::count()
> array::remove( array, where [,count] )
> array::insert( array, where [,count] )
> hash::exists( hash, key )
> hash::remove( hash, key )
>
> Guess it's time for me to finish it :P I'll make it part of my next
> update, I'm halfway through the parser re-work, so declarations like this
> will work:
>
> var a = { 1, 2, { 3.1, 3.2, 3.3 }, { 4:"four"} };
>
> nested container declaration :)
>
> If I'm lucky I'll have it done and unit-tested within a day or so!
>
> -Curt
>
>
> On Sat, Jun 8, 2024 at 12:59 PM Max ***@***.***> wrote:
>
>> I know about a hash table and it works for me. I am talking now about an
>> array. after tiny test I have also a question for hash table actually too.
>>
>> var hashTable = {:};
>> hashTable["mock"] = "value";
>> hashTable["mock2"] = "value2";
>> hashTable["mock3"] = "value3";
>>
>> var array = {1, 2, 3, 4, 5};
>>
>>
>> hashTable._remove("mock");
>> array._remove(2);
>>
>>
>> println( "hashTable" );
>> for ( var v, var k : hashTable ) {
>> print(v);
>> println(k);
>> }
>>
>> println( "array" );
>> for ( var v : array ) {
>> println(v);
>> }
>>
>>
>> Result:
>>
>> hashTable
>> 00
>> 0value3
>> 0value2
>> array
>> 1
>> 2
>> 3
>> 4
>> 5
>>
>> As you can see 2 value on array is available. Hashtable shows really
>> interesting behavior.
>>
>> P.S.: I think I can try to help you with examples on your website if you
>> want.
>>
>> Regards,
>> Max.
>>
>> —
>> Reply to this email directly, view it on GitHub
>> <#26 (reply in thread)>,
>> or unsubscribe
>> <https://github.com/notifications/unsubscribe-auth/AALIKA3LWIGCG34NRCMYSS3ZGMZ7JAVCNFSM6AAAAABI7ZKAKWVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TOMJVGI4DQ>
>> .
>> You are receiving this because you commented.Message ID:
>> ***@***.***>
>>
>
|
Beta Was this translation helpful? Give feedback.
1 reply
-
Big-big thanks to you. Now everything works perfectly! |
Beta Was this translation helpful? Give feedback.
0 replies
-
thank you!
…On Wed, Oct 9, 2024 at 7:01 PM Ander ***@***.***> wrote:
Note to update an error in the documentation, in section foreach:
for( var k,v : somArray )
{
// same as above but k will take on the value 0, 1 and 2
}
(
https://home.workshopfriends.com/wrench/www/#:~:text=for(%20var%20k%2Cv%20%3A%20somArray%20)%0A%7B%0A%20%20%20//%20same%20as%20above%20but%20k%20will%20take%20on%20the%20value%200%2C%201%20and%202%0A%7D
)
I was struggling with this failing until I saw what you wrote above:
for ( var v, *var* k : hashTable ) {
print(v);
println(k);
}
—
Reply to this email directly, view it on GitHub
<#26 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AALIKAZX2KFASGRVWTIL7DDZ2WYU5AVCNFSM6AAAAABI7ZKAKWVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTAOBZG44DANA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
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
-
Hi there,
As I can see
wrench
does not support such an important action as removing some items from an array as hash-table for example.I tried to set
null
for the corresponding item butnull
is0
so it's not what I want as a result.Now, I create a new array without this item by copying all the elements, but it's definitely how it should work :)
Beta Was this translation helpful? Give feedback.
All reactions