Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 21:23 26 Nov 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 : Can you (would you) += in MMBasic

     Page 2 of 4    
Author Message
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 06:40am 27 Dec 2018
Copy link to clipboard 
Print this post

Also time to read up about SUBs and FUNCTIONS.
To expand on the earlier example to allow for increments other than one.

  Quote   x = 5
PRINT x
FOR n = 1 TO 10
INC x

PRINT x
NEXT n

FOR n = 1 TO 10
INC x,
5

PRINT x
NEXT n

SUB INC k, d
LOCAL delta
IF d = 0 THEN delta = 1 ELSE delta = d
k = k + delta
END SUB


Once-upon-a-time we only had single precision floating point numbers and life was easy.
We now have integers as well so my example is not very good. There really needs to be two SUBs. INCf and INCi.
The more advanced MMBasic gets, the more disciplined the programmers have to be. A good thing but not as much fun.

I've already had one migraine today so that's enough for me for now.

Jim

VK7JH
MMedit   MMBasic Help
 
karjo238
Regular Member

Joined: 12/10/2018
Location: New Zealand
Posts: 54
Posted: 06:52am 27 Dec 2018
Copy link to clipboard 
Print this post

  TassyJim said   Also time to read up about SUBs and FUNCTIONS.
To expand on the earlier example to allow for increments other than one.

  Quote   x = 5
PRINT x
FOR n = 1 TO 10
INC x

PRINT x
NEXT n

FOR n = 1 TO 10
INC x,
5

PRINT x
NEXT n

SUB INC k, d
LOCAL delta
IF d = 0 THEN delta = 1 ELSE delta = d
k = k + delta
END SUB


Once-upon-a-time we only had single precision floating point numbers and life was easy.
We now have integers as well so my example is not very good. There really needs to be two SUBs. INCf and INCi.
The more advanced MMBasic gets, the more disciplined the programmers have to be. A good thing but not as much fun.

I've already had one migraine today so that's enough for me for now.

Jim



Jim -

That works for me! As I said, it's very much a personal thing, but that code will do exactly what I need and will be used forthwith. Please, go hither and relieve your migrane with my sincerest thanks. It's wonderful to reach out and receive assistance when it is asked for.

Joseph
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 05:02am 28 Dec 2018
Copy link to clipboard 
Print this post

  TassyJim said  The more advanced MMBasic gets, the more disciplined the programmers have to be. A good thing but not as much fun.


Yep, that's another result of the trends I was outlining above. COBOL just wouldn't let you write undisciplined code. Geoff's OPTION EXPLICIT enforces pre-dimensioning variables. dBase let you write all kinds of junk into your code without complaining.

There are a few things I wish Geoff would change about MMBasic but it would require branching from the "normal" BASIC.

I think that arguments passed to procedures (subs or functions) should always be delimited, but not with "()" pairs, rather with "[]" pairs. This would avoid the possibility of confusing arrays with procedures.

In a for next construction it is optional to specify the variable after the next
for i=1 to 10:for j=1 to 10:'do something:next j,i

thus tying a next to a specific for.

I think that it should be optional (and recommended) to include the name of a procedure after the end procedure statement.
sub XYZ
'do something
end sub XYZ

thus tying a procedure close to a specific opening statement.

Minor points but ...........

Paul in NY
 
flip
Senior Member

Joined: 18/07/2016
Location: Australia
Posts: 114
Posted: 11:54am 28 Dec 2018
Copy link to clipboard 
Print this post

...also for consistency (and maybe if it gives faster execution) do it for string variables...

a$ += " append a bit"

But totally up to Geoff.

Just my 2c, but If they give no performance benefit, I prefer putting these sort of personal preferences into a pre-processor, it is simple to do, and pre-processors have many other side benefits for end-users, and can prevent fragmentation of the core design.

Again, just my 2c...I'm sure many valid views can be expressed on it...

Regards PhilEdited by flip 2018-12-29
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3150
Posted: 03:48pm 28 Dec 2018
Copy link to clipboard 
Print this post

  Paul_L said  I think that arguments passed to procedures (subs or functions) should always be delimited, but not with "()" pairs, rather with "[]" pairs. This would avoid the possibility of confusing arrays with procedures.

Idiosyncratic, for sure, based on my programming experience. And it would break a lot of perfectly good code.

  Paul_L said  I think that it should be optional (and recommended) to include the name of a procedure after the end procedure statement.
sub XYZ
'do something
end sub XYZ

thus tying a procedure close to a specific opening statement.

If optional, it could without breaking things identify some (I think rare) conditions where one subroutine was unintentionally inserted within another, but if intended to be informational and not syntax-constricting, "END SUB ' XYZ" would work (and I frequently use that with long SUBs).

PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 04:21pm 28 Dec 2018
Copy link to clipboard 
Print this post

  lizby said  
  Paul_L said  I think that arguments passed to procedures (subs or functions) should always be delimited, but not with "()" pairs, rather with "[]" pairs. This would avoid the possibility of confusing arrays with procedures.

Idiosyncratic, for sure, based on my programming experience. And it would break a lot of perfectly good code.
Yep, idiosyncratic for sure, that's me, and I'm too old to change now. Xbase has always been agnostic ... if lets you use [], {}, <>, or () pairs interchangeably. It also doesn't care if you use " ", ' ', [ ], ( ), or { } to delimit literal strings, which makes it easy to stick a <"> or <'> into a literal string, like A$={This string's kind of "bumfuzziling" and confusing me.}.

  lizby said  
  Paul_L said  I think that it should be optional (and recommended) to include the name of a procedure after the end procedure statement.
sub XYZ
'do something
end sub XYZ

thus tying a procedure close to a specific opening statement.

If optional, it could without breaking things identify some (I think rare) conditions where one subroutine was unintentionally inserted within another, but if intended to be informational and not syntax-constricting, "END SUB ' XYZ" would work (and I frequently use that with long SUBs).
I try to do exactly that with every sub.
sub XYZ 'this sub does something
'do something
end sub 'XYS 'this sub does something
But, if I forget to stick in the first <'> after the end sub it breaks MMBasic.

Paul in NY
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3150
Posted: 05:41pm 28 Dec 2018
Copy link to clipboard 
Print this post

>breaks MMBasic

Seems extreme to say that the programmer's omission of a single quote ("'") "breaks" mmbasic, when what it actually does is produce a syntax error, just as most comments would if the comment indicator symbol were omitted.

Edited by lizby 2018-12-30
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
karjo238
Regular Member

Joined: 12/10/2018
Location: New Zealand
Posts: 54
Posted: 03:38am 03 Jan 2019
Copy link to clipboard 
Print this post

I'll ask this question here, as this is related to some of the answers already posted in this thread.

I have created the simple code:


DIM A(6) = (0,1,2,3,4,5,6)
print a(3)


This returns 0, when I would have thought it would have returned 2.

I'm doing something badly wrong, I'm sure, but what?

Answers on a ticking timebomb please...

Joseph.
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1611
Posted: 03:45am 03 Jan 2019
Copy link to clipboard 
Print this post

I was just playing with the latest beta version. Tested it and it printed 3 for me.

Bill

Edit:

list
Dim A(6) = (0,1,2,3,4,5,6)
Print a(3)
> run
3
>
Edited by Turbo46 2019-01-04
Keep safe. Live long and prosper.
 
karjo238
Regular Member

Joined: 12/10/2018
Location: New Zealand
Posts: 54
Posted: 03:59am 03 Jan 2019
Copy link to clipboard 
Print this post

After I posted, I wondered if I had an older version or some such. My MMBasic is 4.0402, and the MMBasic manual version 4.5 does not mention this capability, but the DOS MMBasic (version 5.05) manual mentions this feature.

Soooooo, I'll have to do some rejigging to update my Maximite because it's running off the USB as a power source, and I really should get a 9V power supply.

It's all good, as I have been meaning to do this anyways. This just gives me an extra reason to get about doing it.

Many thanks,

Joseph.
 
spock57
Newbie

Joined: 24/09/2017
Location: United Kingdom
Posts: 4
Posted: 10:13pm 25 Jan 2019
Copy link to clipboard 
Print this post

I'm new to the forum in as much I'm a regular reader but usually keep my gob shut! Some forty years ago when I was young and all the extremities moved as they should, I remember a mantra that went something like the "operating system should be transparent to the user" ,oh what a great Idea!
In the last ten years or so I was nearly guilty of murder every time some IT bod would say the system expects me to do it this way, it's the technophobes worst nightmare the user serves the system, it's not very humane what did we gain?
So whats this got to do with MM basic, well the attraction of basic back then and now was the relative ease of use, improvement is all well and good but when you start with a Ford escort for the shopping and improve it until It's a Jaguar Ok it's faster but will it take a kiddy seat? The way I see it if you don't need massive performance and just want to get something done no fuss use Basic ,if you are cleaver enough to shoot holes in the validity of using basic you are probably better off using C or some other language that is quick efficient and probably a nightmare to use unless you have the right sort of aptitude. Please please keep it simple I'm a lousy programmer Basic is nice and text based I have great difficulty in spotting the difference between <> {[ }] () and these symbols to are name but a few I will never live long enough to understand C, tiny basic is probably good enough for me the MM basic reminds me of my old Tandy model 1 (sigh). That's me done I will not rant on any more.
Ps apologies in advance if I'v posted incorrectly!
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 10:45pm 25 Jan 2019
Copy link to clipboard 
Print this post

Well..... :)

Even in C, C#, C++, Java and javascript I mostly use a = a + 1
It is just five characters (without whitespace) and a += 1 is four characters.
Just saving 1 character is not worth it. and for my personal taste the first style is preferred.

However there are situations where there can be 'expensive' evaluations like
MyArray[J+1][K+1] = MyArray[J+1][K+1] + 1

The interpreter then has to evaluate the same expression twice, resulting in about twice as long execution time.

Often those more expensive expressions are used in loops, therefore using the += is more efficient. If you want to squeeze out the most performance then that can be a reason to use it. With compiled languages it does not matter as it will be optimized anyway.

Microblocks. Build with logic.
 
memberx
Newbie

Joined: 20/04/2012
Location: Australia
Posts: 24
Posted: 11:56pm 25 Jan 2019
Copy link to clipboard 
Print this post

Amazing, old dinasaurs, either because of incompetence, laziness , or whatever, want to stop progress. Computers, electronics, programming is evolving technology and is not for everyone. If it's too hard go and find something else.


 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3150
Posted: 12:48am 26 Jan 2019
Copy link to clipboard 
Print this post

  memberx said   Amazing, old dinasaurs...

Judgmental much? What's amazing is that you can lower yourself to follow a basic forum.
Edited by lizby 2019-01-27
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2817
Posted: 07:58am 26 Jan 2019
Copy link to clipboard 
Print this post

Been monitoring this thread with keen interest, and until now I have held back from posting as I wanted to see what other people's feedback was.

Having built, used, supplied, and demonstrated literally thousands of Micromites and Maximites over the last few years, my belief is rather straightforward:

MMBASIC code should 'look and feel' obvious to a non-systems person

I have demonstrated MMBASIC to a LOT of people, of various ages and skill-abilities. The amazing thing observed on EVERY occasion is that people 'get it' because of how easy it is to understand. And this is exactly what BASIC was designed to be.

Maths expressions learnt at an early age are easy to identify with within BASIC code and hence are totally meaningful.

Obviously new features require new commands, but the overall context should still be simple and obvious. 'Progress' is relevant and Geoff and Peter (and a few others here) have implemented things in a totally meaningful way; apart from, (dare I say it) << and >>.

These << and >> expressions still require me to stop and think. A newcomer has no-chance - I have asked people in demonstrations and not one 'newbie' has been able to answer correctly. If you are a systems person then they sure will mean something obvious (and so probably will C programming!). By the way, I use multiply and divide to do my 'bit shifting'!

My opinion regarding: a += 1 is that it is not obvious to a 'newbie' in any way; and anything not obvious does not really belong in (MM)BASIC.

So progress is good, I have no 'laziness' in learning new things, but PLEASE let us preserve the simplicity, i.e. the look & feel, of MMBASIC code in the years to come.




For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
Frank N. Furter
Guru

Joined: 28/05/2012
Location: Germany
Posts: 830
Posted: 03:30pm 26 Jan 2019
Copy link to clipboard 
Print this post

The dinosaurs lived about 190 million years, man 300000 and is already about to extinguish himself - what is better?

I'd rather be a dinosaur with an interesting hobby!!!!

What did Spock say: Scotty, beam me up, there is no intelligent life on this planet!

I love BASIC because of its simplicity! For me it is also not a real advantage if I have to close my pants with a glowing pair of pliers!

+1 WhiteWizzard: MMBASIC code should 'look and feel' obvious to a non-systems person
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 06:42pm 26 Jan 2019
Copy link to clipboard 
Print this post

  memberx said   Amazing, old dinasaurs, either because of incompetence, laziness , or whatever, want to stop progress.


Hmmpff. Darn right I'm a dinosaur! I still think that Grace Hopper was right, a program language should enforce divisions .... namely Identification, Environment, Data, and Procedures. Every major bank in the world is running on programs which were coded 50 or more years ago and are still functioning perfectly, thanks mostly to the partitioning enforced by the COBOL divisions and the modularity of the procedures!

Progress for progress' sake is not progress ... it quickly becomes anarchy. Bill Gate's dream of non-modular programming is a case in point. He advocates divorcing a patterned sequence of events from programming. This results in a word processor where you can first mail a letter, then insert the letter in an envelope, then address the envelope, then print the letter, then .... well, you get the idea.

Real world tasks dictate the sequence of events that must occur before a task is completed. Real world programming enforces a similar sequence of events!

And .... I even like Reverse Polish Notation!

Paul in NY
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1611
Posted: 10:21pm 26 Jan 2019
Copy link to clipboard 
Print this post

Let's not forget that the Micromite (and Maximite to a large extent) are intended to be used as microcontrollers. There are many commands that have been implemented for this purpose: IR, PIN() PORT, PWM and so on.

For that reason I like the '>>' and '<<' expressions. When you are dealing with binary numbers '>>' and '<<' to shift bits are more intuitive to the programmer than '/' and '*'. I Expect they are faster as well.

Have a look into some the Maximite games programs. In many of them there is extensive use of the:

a = a + 1

type of construct. If:

INC a [,Number]

could be implemented along with it's mate, DEC, for use with INTEGERs and if they operated faster than the 'a = a + 1' method, then I believe they would be a useful addition to the language.

Bill
Keep safe. Live long and prosper.
 
Bill7300
Senior Member

Joined: 05/08/2014
Location: Australia
Posts: 158
Posted: 11:26am 27 Jan 2019
Copy link to clipboard 
Print this post

Absolutely nothing wrong with being a dinosaur - the trick is rather to avoid becoming a fossil!
Bill
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2075
Posted: 11:33am 27 Jan 2019
Copy link to clipboard 
Print this post

  Turbo46 said   I Expect they are faster as well.



Sadly not:

a=57
timer=0
for n=1 to 10000
a=a<<1
next
? timer

a=57
timer=0
for n=1 to 10000
a=a*2
next
? timer


> RUN
1081
967
>



bummer!
 
     Page 2 of 4    
Print this page
© JAQ Software 2024