Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:36 01 Aug 2025 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 : CMM2: Line continuation character, SWAP

Author Message
bar1010
Senior Member

Joined: 10/08/2020
Location: United States
Posts: 197
Posted: 07:14pm 07 Jun 2021
Copy link to clipboard 
Print this post

FreeBASIC uses the underscore character for line continuation.
Do we have something similar to use in the editor?
If not, could we have this functionality added?

Also I have seen a SWAP command in QuickBASIC which swaps the values of two variables.
Could we have this functionality added?
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 07:30pm 07 Jun 2021
Copy link to clipboard 
Print this post

I will save Peter some time:

Line continuation: see http://www.thebackshed.com/Forum/ViewTopic.php?TID=12819

SWAP: probably not as the 128 tokens available for MMBasic commands has been reached on the CMM2 - it's an architectural limitation.

Best wishes,

Tom
Edited 2021-06-08 05:31 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 07:34pm 07 Jun 2021
Copy link to clipboard 
Print this post

Note that because parameters are pass by reference you could write SUBroutines to provide your own SWAP, you'd need one per type and unfortunately you'd have to pay a significant performance penalty over an inbuilt command.

Best wishes,

Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 07:36pm 07 Jun 2021
Copy link to clipboard 
Print this post

  thwill said  SWAP: probably not as the 128 tokens available for MMBasic commands has been reached on the CMM2 - it's an architectural limitation.

I think, that is correct.

But it's easy to make your own:
For example, you might define a subroutine to swap two values, as follows:
SUB Swap a, b
LOCAL t
t = a
a = b
b = t
END SUB
(CMM2 manual p27)

... or write a short CSUB

Regards
Michael
causality ≠ correlation ≠ coincidence
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 08:23pm 07 Jun 2021
Copy link to clipboard 
Print this post

it is likely you will only ever use SWAP in one or two places in any given program.

The overhead of a SUB makes for a very slow SWAP. If you are doing it in tight loops (e.g. in a sort function), better to do it inline for big increase in speed.

All things speed-wise are relative of course
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 504
Posted: 10:59pm 07 Jun 2021
Copy link to clipboard 
Print this post

There is a nice old challenge with the swap function. How can we do it without creating a third variable?  
Edited 2021-06-08 09:19 by LeoNicolas
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 06:06am 08 Jun 2021
Copy link to clipboard 
Print this post

Does it work with floating point, not to mention strings...

LOL

John
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7937
Posted: 06:40am 08 Jun 2021
Copy link to clipboard 
Print this post

Now there's a thought ...
Swap the variable pointers, not the variables.
Edited 2021-06-08 16:40 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Print this page


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

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025