Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 10:39 29 Mar 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MMBasic: Setting Array Elements

Author Message
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1081
Posted: 05:26am 06 Mar 2021
Copy link to clipboard 
Print this post

The statement
DIM arry(2)=(16,17,21)
is valid.

Is there any reason why
arry()=(17,17,11)
couldn't also be valid, or is that just too perverse?
Visit Vegipete's *Mite Library for cool programs.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8516
Posted: 08:24am 06 Mar 2021
Copy link to clipboard 
Print this post

  Quote  or is that just too perverse?


Not perverse but not implemented and won't be
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3641
Posted: 10:31am 06 Mar 2021
Copy link to clipboard 
Print this post

  vegipete said  The statement
DIM arry(2)=(16,17,21)
is valid.

Is there any reason why
arry()=(17,17,11)
couldn't also be valid, or is that just too perverse?

Think what extra work would be required to recognise (parse) that :(

As it starts out, it looks like a function call to arry.  If it's not seen the name arry before it adds it to the internal data structures as a function.  Then it finds the "=" and ... yuck.

John
 
jirsoft

Guru

Joined: 18/09/2020
Location: Czech Republic
Posts: 532
Posted: 01:22pm 06 Mar 2021
Copy link to clipboard 
Print this post

  vegipete said  The statement
DIM arry(2)=(16,17,21)
is valid.

Is there any reason why
arry()=(17,17,11)
couldn't also be valid, or is that just too perverse?


I know, it's not exactly the same, but I have already used:
OPTION BASE 0
OPTION DEFAULT NONE
OPTION EXPLICIT

DIM INTEGER arry(2) = (16,17,21)
printA(arry())
setA(arry(), "17,17,11")
printA(arry())
END
SUB printA(q() AS INTEGER)
 LOCAL INTEGER i, b = BOUND(q())

 FOR i = 0 TO b
   ?q(i),
 NEXT i
 ?
END SUB

SUB setA(q() AS INTEGER, nq AS STRING)
 LOCAL STRING nv
 LOCAL INTEGER i

 FOR i = 0 TO BOUND(q())
   nv = FIELD$(nq, i+1, ",")
   IF nv <> "" THEN
     q(i) = VAL(nv)
   ELSE
     ERROR "Not enough values"
   ENDIF
 NEXT i
END SUB

Jiri
Napoleon Commander and SimplEd for CMM2 (GitHub),  CMM2.fun
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1081
Posted: 05:39pm 06 Mar 2021
Copy link to clipboard 
Print this post

  matherp said  Not perverse but not implemented and won't be

That's OK.

The following works as a straight forward enough substitute:
a = 16 : b = 17 : c = 18
dim arry(2)=(a,b,c)

<some time later...>

erase arry() : dim arry(2)=(c,b,a)
The only nuisance is that you can't erase a variable that hasn't previously been dimmed into existence.

In my case, I need to re-initialize starting values in the array, so I can use constant values, instead of variables:
dim arry(2)=(1,2,3)

.
Edited 2021-03-07 04:07 by vegipete
Visit Vegipete's *Mite Library for cool programs.
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024