Posted: 04:50pm 24 Apr 2025 Copy link to clipboard
twofingers Guru
I accidentally edited my answer.
Posted: 05:51pm 24 Apr 2025 Copy link to clipboard
Mixtel90 Guru
Bear in mind how big string arrays tend to get. They can use a lot of RAM. Adding two string arrays to make a third means finding space for all three. You would like some programming space left, wouldn't you? ;)
Posted: 06:03pm 24 Apr 2025 Copy link to clipboard
twofingers Guru
Hi Mick, it's not the job of Array ADD to combine two arrays into a third. It's analogous to
MATH ADD in(), num ,out()
This adds the value 'num' to every element of the matrix in() and puts the answer in out(). Works for arrays of any dimensionality of both integer and float and can convert between. Setting num to 0 is optimised and is a fast way of copying an entire array. in() and out() can be the same array.
Array ADD in$(), Str$, out$()
should add a string to each element of an array and store it in a new (or the old) array. Additionally, it would be a quick way to copy (STR$=""), delete (?), and fill (?) a string array. Regards Michael
Posted: 06:09pm 24 Apr 2025 Copy link to clipboard
matherp Guru
I've updated RC18 if you want to download
Improves error detection in MID$ command Improves error detection in INC command when using strings
Adds new command
ARRAY ADD in(), data, out()
Supports integers, floats AND strings
Posted: 06:30pm 24 Apr 2025 Copy link to clipboard
twofingers Guru
Peter, you scare me!
Thanks a lot!
Posted: 07:29pm 24 Apr 2025 Copy link to clipboard
electricat Senior Member
HDMI/USB/2350 RC17 @Peter,
Did not tested latest RC18 but as I found it in EDITOR it might be still here.Try this to replicate: Inside editor type in any text. But at least one underscore '_' must be used.
asadasfsd_asdasasf
Now move using left or right arrows but you must pass that underscore '_' and you`ll notice underscore just dissapears. With more underscores even more fun effect It`s only visual thing, does not saves F1. Restores on screen redraws etc.
Posted: 11:45am 25 Apr 2025 Copy link to clipboard
bfwolf Regular Member
Passing an array by reference to a subroutine works. This allows you to switch between arrays without having to copy the elements. Same for simple variables. This would eliminate the need for an "ALIAS":
Option Explicit
Sub AddArrVal(byref arr%() As integer) Local i As integer For i=1 To Bound(arr%()) arr%(i) = arr%(i) + 3 Next End Sub
Dim MyArr%(10) As integer Dim MyAr2%(10) As integer Dim i% As integer
For i=1 To Bound(MyArr%()) MyArr%(i) = i Next For i=1 To Bound(MyAr2%()) MyAr2%(i) = i + 2 Next AddArrVal(MyArr%()) AddArrVal(MyAr2%()) Print "Works as expected:" For i=1 To Bound(MyArr%()) Print MyArr%(i), Next Print For i=1 To Bound(MyAr2%()) Print MyAr2%(i), Next Print
Print "Fails as expected:" Dim MyA2%(10,10) As integer AddArrVal(MyA2%(1,))
End
Saved 596 bytes > run Works as expected: 4 5 6 7 8 9 10 11 12 13 6 7 8 9 10 11 12 13 14 15 Fails as expected: [34] AddArrVal(MyA2%(1,)) Error : Dimensions >
@Peter, Question: Wouldn't an array anyway have been passed implicitly "byref," so that the "byref" could be omitted? Of course, it's clearer and cleaner to enforce "byref" explicitly!
And to be clear: I don't expect that a multidimensional array, e.g. MyA2%(10,10), can be passed as a one-dimensional array (vector) by writing MyA2%(1,) (i.e., leaving the last index empty) - that was just an idea, because that's how it would work in C - but I expected it to be forbidden and generate an error message! But perhaps MMBasic already has a builtin solution for this? Edited 2025-04-25 21:49 by bfwolf
Posted: 01:36pm 25 Apr 2025 Copy link to clipboard
twofingers Guru
Regards Michael
Posted: 04:19pm 25 Apr 2025 Copy link to clipboard
bfwolf Regular Member
In addition to a mechanism for passing partial string arrays to subs.
For the avoidance of doubt - this will never happen
Regards Michael
Was that referring to my previous post?
Didn't you read my paragraph at the end?: It was pretty clear to me that it doesn't work, and I don't expect it to work (in the future) either! I also read Peter's post, which you quoted again, and I share his opinion. I tried it "just for fun" to see if it might work "accidentally."
But I figured out a workaround myself beforehand:
Option Explicit
Sub Add2nDimArrVal(byref arr%() As integer, byref ix%() As integer) Local i As integer, nD As Integer = 0, nDims As integer = 0 Local ptr As integer
i = 1 Do nD = Bound(arr%(), i) If nD <> 0 Then nDims = nDims + 1 : i = i + 1 EndIf Loop Until nD = 0
'Print nDims
For i=1 To Bound(arr%(), nDims) Select Case nDims Case 1 ptr = Peek(VARADDR arr%(i)) Case 2 ptr = Peek(VARADDR arr%(ix%(1), i)) Case 3 ptr = Peek(VARADDR arr%(ix%(1), ix%(2), i)) End Select ' Print ptr, Poke integer ptr, (Peek(integer ptr) + 3) Next Print End Sub
Dim i As integer, j As integer Const MyAD% = 2 ' nDims of MyA2% Dim MyA2%(10,10) As integer Dim MyAI%(MyAD%) As integer
Print "Works as hoped: :-D"
' Set index values of all dimensions before last dim: MyAI%(1) = 5 ' : MyAI%(MyAD%) = 0
For j=1 To Bound(MyA2%(),1) For i=1 To Bound(MyA2%(),MyAD%) If j = MyAI%(1) Then MyA2%(j, i) = i + 10 Else MyA2%(j, i) = 0 EndIf Next Next
Add2nDimArrVal(MyA2%(), MyAI%())
For i=1 To Bound(MyA2%(),MyAD%) Print MyA2%(MyAI%(1), i), Next Print
End
> run Works as hoped: :-D
14 15 16 17 18 19 20 21 22 23 >
Regards, bfwolf
Posted: 04:37pm 25 Apr 2025 Copy link to clipboard
twofingers Guru
Was that referring to my previous post? ...
I was just worried that Peter might get the impression that they wanted to push the topic further. I think Peter put a lot of effort into it.
I appreciate your research! I don't have the opportunity to test everything at the moment, but I'm glad that the topic is being approached from different perspectives.
Basically, IMHO, Vadim's question (see FileManager thread) was about partially passing partial string arrays to a sub-routine for example, to be able to sort them there.
There seems to be agreement that arrays can only be passed by reference, how else?
By the way, the first parameter passed to a subroutine is never optional, but the others are.
Best regards Michael
Posted: 05:03pm 25 Apr 2025 Copy link to clipboard
bfwolf Regular Member
I was just worried that Peter might get the impression that they wanted to push the topic further. I think Peter put a lot of effort into it.
Yes, I also know the big work, Peter is investing. And I think, one shouldn't blow up the language too much, if there is no "real need" for new language elements.
I appreciate your research! I don't have the opportunity to test everything at the moment, but I'm glad that the topic is being approached from different perspectives.
Basically, IMHO, Vadim's question (see FileManager thread) was about partially passing partial string arrays to a sub-routine for example, to be able to sort them there.
Thx! Vadim's question inspired me.. Perhaps I've found a soulution for his problem? And by playing with this, I found out, that with "ptr=Peek(VARADDR var)", "val=Peek(<TYPE> ptr)" and "Poke <TYPE> ptr, val" the C pointers can nearly completely substituted..
There seems to be agreement that arrays can only be passed by reference, how else?
Yes! And this should remain, as is. Passing big arrays by value(s) leads to ugly performance and stack overflow danger!
By the way, the first parameter passed to a subroutine is never optional, but the others are.
Thx again! Good hint! Didn't know it 'til now..
Regards, bfwolf Edited 2025-04-26 03:06 by bfwolf
Posted: 08:27am 26 Apr 2025 Copy link to clipboard
matherp Guru
I've just updated RC18 to include the new command
ARRAY SET data,array()
This works the same as MATH SET (see manual) but also now supports strings
e.g.
dim s$(9,9) length 20 array set "Whatever", s$() ? s$(8,8) array set "", s$() ? s$(8,8)
Together with ARRAY ADD, ARRAY SLICE, and ARRAY INSERT you now have fast commands for doing most likely bulk manipulations with strings. In all cases see the equivalent MATH commands in the manual for details Edited 2025-04-26 18:28 by matherp
Posted: 08:44am 26 Apr 2025 Copy link to clipboard
twofingers Guru
... Together with ARRAY ADD, ARRAY SLICE, and ARRAY INSERT you now have fast commands for doing most likely bulk manipulations with strings. ...
I am very happy! Thanks! Michael
Posted: 05:10pm 26 Apr 2025 Copy link to clipboard
toml_12953 Guru
Since updating to 6.00.xx, the Del function on my I2C keyboard no longer works. Shift-Del does go to the end of the line but Del by itself doesn't work.
Posted: 05:59pm 26 Apr 2025 Copy link to clipboard
matherp Guru
the Del function on my I2C keyboard no longer works.
Which I2C keyboard?
Posted: 07:06pm 26 Apr 2025 Copy link to clipboard
toml_12953 Guru
the Del function on my I2C keyboard no longer works.
Which I2C keyboard?
The one onboard the PicoCalc. Since Del worked in MMBasic v 5.xx and doesn't in 6.xx I was wondering if there was a change in keyboard handling.
Posted: 07:12pm 26 Apr 2025 Copy link to clipboard
matherp Guru
Nothing I can help with. The solderparty keyboard which is the supported version works perfectly on V6.00.02RC17 - just tested
Posted: 07:35pm 26 Apr 2025 Copy link to clipboard
homa Guru
I'm back from my short holiday. And I'm looking forward to testing again. If there are still so many great additions, will the textbuffer layer be added after all?
Posted: 01:15am 27 Apr 2025 Copy link to clipboard
toml_12953 Guru
Nothing I can help with. The solderparty keyboard which is the supported version works perfectly on V6.00.02RC17 - just tested
Thanks for checking, anyway. I finally figured out that a typical keyboard returns 0x7f for DEL but the PicoCalc returns 0xd4. It seems like the maker of PicoCalc patched the files to account for that but the people who are continuing the PicoCalc releases didn't
Posted: 11:19am 27 Apr 2025 Copy link to clipboard
thwill Guru
Hi Peter,
Not sure what has happened here, but I believe it is a regression:
> list "wtf.bas" Print de_format$("rtrue") Function de_format$(a$) Local p, s$ s$ = " " p = Len(a$) + 1 Print "'" a$ "'" Print "'" s$ "'" Print p Cat s$, Left$(a$, p - 1) de_format$ = s$ End Function
> run "wtf.bas" 'rtrue' ' ' 6 [10] Cat s$, Left$(a$, p - 1) Error : String too long
Best wishes,
Tom
Page 33 of 37
The Back Shed's forum code is written, and hosted, in Australia.