Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 04:31 17 Apr 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 : Splitting Long Lines - the unquoted backslash ()?

     Page 1 of 2    
Author Message
MustardMan

Senior Member

Joined: 30/08/2019
Location: Australia
Posts: 175
Posted: 03:58am 23 Sep 2020
Copy link to clipboard 
Print this post

Hi,

In C (and some other languages) there is the ability to split long lines into multiple shorter lines and have them interpreted as a single line. Oftentimes a "\" is used.

In all my years of programming I have only used this once, but sometimes it would be nice to be able to do this. In particular when I want to use OPTION EXPLICIT with MMbasic, where everything has to have its' type declared, defining a function with multiple and many parameters becomes nasty.

I had this problem not too long ago, and I eventually resorted to using global variables in addition to passing parameters. I ended up with the following, which worked fine, but I really hated having to declare and use global variables for such an operation, and it made calling a function unnecessarily convoluted (assign global parameters and then call my function with extra parameters anyway)

FUNCTION BinaryInput(Title AS STRING, OldValue AS STRING, Choice1 AS STRING, Choice2 AS STRING) AS STRING


As might be noted all my parameters are strings (in this instance) but I could not find a way to declare them all with one 'AS STRING' statement. And besides, I really wanted non-string parameters mixed in.

The purpose of the function was to draw a keypad on-screen and ask the user to select between two choices (C1, C2), displaying what the current selection was (OldValue). I also wanted to pass in parameters such as where to draw the keypad, what colours to assign the strings (eg: a unusual choice might be yellow or red, and a usual choice might be green), and other things too.


Is there a 'line extension' character in MMbasic?

Cheers,

Edit: After posting I've noticed my title did not turn out. Between the brackets there was once a backslash character...
Edited 2020-09-23 14:00 by MustardMan
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5875
Posted: 04:08am 23 Sep 2020
Copy link to clipboard 
Print this post

  [ said  QUOTE=MustardMan

Is there a 'line extension' character in MMbasic?

Cheers,

No there is not.

For strings just use the $ identifier then you don't need the AS STRING.
Same for integers and floats.

Jim
VK7JH
MMedit   MMBasic Help
 
djwildstar
Newbie

Joined: 29/07/2020
Location: United States
Posts: 24
Posted: 11:21am 23 Sep 2020
Copy link to clipboard 
Print this post

@MustardMan -- In MMBasic 5, you can declare multiple arguments of the same base type by using a comma-separated list (e.g, "a, b, c, d AS FLOAT").  You can also pass an array to a function without specifying the dimensions of the array in the function definition.  The following code should help:

REM Test function declaration syntax
OPTION EXPLICIT
OPTION DEFAULT NONE
OPTION BASE 1

DIM Title$ AS STRING = "Menu Title"
DIM OldValue$ AS STRING = "First Option"
DIM Choices$(4) AS STRING = ("First Option","Second Option","Third Option","Fourth Option")
DIM Result$ AS STRING = ""

LET Result$ = TestFunc$(Title$, OldValue$, Choices$())

PRINT "RESULT=";Result$
END

FUNCTION TestFunc$(t$,o$,c$() AS STRING) AS STRING
 PRINT t$;" [";o$;"]"
 LOCAL I% AS INTEGER
 FOR I% = 1 TO BOUND(c$())
   PRINT "  ";I%;"=";c$(I%)
 NEXT I%
 INPUT "Choice:",I%
 LET TestFunc$ = c$(I%)
END FUNCTION
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8563
Posted: 11:33am 23 Sep 2020
Copy link to clipboard 
Print this post

  Quote   MMBasic 5, you can declare multiple arguments of the same base type by using a comma-separated list (e.g, "a, b, c, d AS FLOAT").  

Incorrect I'm afraid. The as clause only applies to the single variable. You example only works because the variables are explicitly typed

try
? fred("a","b","c")
end
function fred(a,b,c as string)
a="hello"
fred=1.0
end function


The simplest way round this is too always use explicitly typed variables $, %, or !
Edited 2020-09-23 21:34 by matherp
 
djwildstar
Newbie

Joined: 29/07/2020
Location: United States
Posts: 24
Posted: 11:59am 23 Sep 2020
Copy link to clipboard 
Print this post

@matherp -- Thanks for the correction!  I'm in the habit of using the sigils ($,%,!) more-or-less automatically.
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2285
Posted: 01:26pm 23 Sep 2020
Copy link to clipboard 
Print this post

it looks like the only printable character not used for something in mmbasic is the pipe, "|". having a completely unique continuation character seems to help with the simplicity of any approach.


TECHNICALLY, could "|" be used at the end of a line to indicate that the following line in the editor is a continuation, with the total possible 'program line' length then becoming around 250 characters?

for this to work:

1. the interpreter would need to handle "|" in the same way as a space character, ie pretty much ignore it whenever encountered outside of a string constant.

2. saving from the editor (or using autosave) would need to interpret "|" as meaning 'code "|" into program stream, then skip to next editor line (ignoring cr-lf), and continue tokenizing into the program stream without encoding any new 'start of line' preamble.

3. loading the editor would require interpreting "|" as 'add a "|" followed by a line break into the edit buffer, and then continue decoding tokens.


i'm not saying that continuation lines are a good idea or not, but am curious about the practicality of the mechanism. i'd be interested to hear geoff's views. it would yield source code that may not be compatible with some other basic interpreters, while not limiting the basic code that mmbasic could run verbatim. a bit like the "<<" and ">>" operators, that are most useful.


cheers,
rob   :-)
Edited 2020-09-23 23:29 by robert.rozee
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8563
Posted: 01:34pm 23 Sep 2020
Copy link to clipboard 
Print this post

The CMM2 editor can handle lines up to 240 characters as it implements left/right scrolling. Going beyond that  would be an MMBasic rewrite. | is used internally in the CMM2.
 
MustardMan

Senior Member

Joined: 30/08/2019
Location: Australia
Posts: 175
Posted: 11:52pm 23 Sep 2020
Copy link to clipboard 
Print this post

I am probably being a little too precious as I like using 'AS type' rather than the $!% symbols.

I do very much like the OPTION EXPLICIT and I am almost religious about using it. Silly example, but saving you from stupid things like Var1, Varl and VarI (in some fonts, 1 and l look exactly the same, and same with l and I). It brings variable handing more into line with what compilers do.

I suppose another thing is the differentiation between a line length of 250 characters, and a "tokenised" line length of 250 bytes - which could expand out to a lot more than 250 characters!
Which brings another question: when I either LOAD or XMODEM RECEIVE a program, where is the tokenising happening? I would imagine the full line is tokenised after the CR/LF when manually editing, but is this the case all the time?

Like I said, I've only needed to use the 'line extension' character once or twice in my time, so to me it is not really a big deal. Might be a nice enhancement to MMedit (which I must say I use almost exclusively now days) to make the 'source' more readable, and that would mean no 'non compatible' MMbasic issues (MMedit already has a lot of 'non standard' things in it, which I still have to get around to making use of, such as #REPLACE and ''INCLUDE).

And thanks for the tip about arrays. BOUND is not in the 'MicroMite user manual' and typing in PRINT BOUND(a$()) [after declaring a$] returns an error. Dang! Is it a CMM2 thing only?

Cheers,
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 12:02am 24 Sep 2020
Copy link to clipboard 
Print this post

MMBasic (and BASIC in general) is very much line orientated.  In part this is because you can have every line numbered and, in the early BASICs, this was mandatory.

I will have a look at using a line continuation character but I doubt that it can be done without a big rewrite of the MMBasic core - and something like that inevitably introduces new bugs and unwanted side effects.

Geoff
Geoff Graham - http://geoffg.net
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5875
Posted: 04:18am 24 Sep 2020
Copy link to clipboard 
Print this post

If I do add line continuation to MMEdit, something I have considered, it will follow the QuickBasic method:

  Quote  1.2.3  BASIC Line Length

   If you enter your programs using QuickBASIC's built-in editor, you are
   limited to lines of 256 characters. The QuickBASIC editor does not
   recognize the underscore character (_) as a line continuation.

   If you use your own editor, you may use an underscore as the last
   character to create a program line, like the following, that extends
   across more than one physical line:

   IF (TestChar$ = " " OR TestChar$ = ".") AND _
   LineNumber < 23 AND NOT EOF(FileNumber) THEN

   When QuickBASIC loads your program, the underscores are removed and the
   continued lines are joined to form a single line. The line-length limit is
   relaxed in this case. Underscores cannot be used to continue DATA or REM
   statements.


In MMEdit, you will have to end a line with space then underscore.
MMEdit will reassemble the lines before uploading with either XMODEM or AUTOSAVE.

The one big difference is you are still restricted to 255 characters for a reassembled line.


Jim
VK7JH
MMedit   MMBasic Help
 
MustardMan

Senior Member

Joined: 30/08/2019
Location: Australia
Posts: 175
Posted: 07:11am 24 Sep 2020
Copy link to clipboard 
Print this post

250/255 characters, even non-tokenised, is actually quite a lot of characters! I imagine more than what nearly any line of code without comments would be (barring some of those esoteric code challenges).

Although you can create a much longer line in any decent text editor, seeing all those 255 characters in one go (without horizontal scrolling) would be pretty unusual too. The only motivation behind line splitting would be to make code easier to read.

Having started with a trash-80, I remember going into it in great depth. When a program was CSAVEd or CLOADed what was stored on tape was the tokenised program, not the plain text. I believe trash-80 disks were the same.
It was possible to create longer than normal lines when editing an existing line (not entering a fresh line) as the system would keep the tokenised form in memory and expand it on-screen to edit.

I have not gone into such details with MMbasic - does it store its' files tokenised, and under what circumstances? eg: tokenised on on an SD card, but plain text when using the console port?

Cheers,

EDIT: @TassyJim
Your suggested use of 'space underscore' sounds like a good idea. I don't think being restricted to 255/250 characters is a problem, as I mention above. Line continuation is something that mostly helps the programmer by making code easier to read.
Edited 2020-09-24 17:18 by MustardMan
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 12:52am 25 Sep 2020
Copy link to clipboard 
Print this post

There was an alternate operating system available for the Trash 80 called "Dos Plus" produced by Micro Systems Software. It's BASIC interpreter, which required line numbers, used the <down arrow> as a line continuation character and it treated the <tab> character as white space. When you stuck a <down arrow> into a code line it would display the following character at the left end of the following screen line.

You could write a line which would display like this:
120
       print
       @ 20,40
       using "###,###.##    "
       a;
       b;
       c
130


By typing this:


120<dn><tab>print<dn><tab>@ 20,40<dn><tab>using "###,###.##    "<dn><tab>a;<dn><tab>b;<dn><tab>c<enter>130<enter>


This enabled really pretty listings for a line numbered BASIC and it didn't need a special line continuation character which would be visible in the listing.

Does MMBasic, in its present incarnation, treat the <down arrow> and the <tab> character as white space?

Paul in NY
Edited 2020-09-25 10:54 by Paul_L
 
MustardMan

Senior Member

Joined: 30/08/2019
Location: Australia
Posts: 175
Posted: 03:28am 25 Sep 2020
Copy link to clipboard 
Print this post

That is really neat (especially visually)!

I never even knew "Dos Plus" existed, but the budget constraints of a teenager didn't let me see much anyway. I think one of the few pieces of software we had that didn't come with a piece of hardware (eg: TRS-DOS with the floppy drives) was the Microsoft Editor Assembler.
Oh, how I now regret giving that company a head start into the bloatware infested world we now have!

Cheers,
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 12:02am 27 Sep 2020
Copy link to clipboard 
Print this post

Micro Systems Software was located on Oak Circle in Boca Raton. I think Mark Lautenschlager wrote most of the DosPlus code after he quit IBM. DosPlus was an incredibly complete OS. One of its amazing facilities permitted you to JOIN output devices or to SUBSTITUTE output devices. You could join a printer to the monitor, a disk drive to the monitor, or you could SUBSTITUTE a printer for the monitor or a disk drive for the monitor. The entire OS, including the BASIC interpreter took up about 19 KB of the maximum 64 KB memory space of the TRS80. It must have been hand assembled in machine code to be that compact! It fit on a single 5.25 inch single density floppy. I seem to remember buying it for about $89 or so.

Paul in NY
 
elk1984

Senior Member

Joined: 11/07/2020
Location: United Kingdom
Posts: 227
Posted: 03:18pm 27 Sep 2020
Copy link to clipboard 
Print this post

  TassyJim said  If I do add line continuation to MMEdit, something I have considered, it will follow the QuickBasic method:

  Quote  1.2.3  BASIC Line Length

   If you enter your programs using QuickBASIC's built-in editor, you are
   limited to lines of 256 characters. The QuickBASIC editor does not
   recognize the underscore character (_) as a line continuation.

   If you use your own editor, you may use an underscore as the last
   character to create a program line, like the following, that extends
   across more than one physical line:

   IF (TestChar$ = " " OR TestChar$ = ".") AND _
   LineNumber < 23 AND NOT EOF(FileNumber) THEN

   When QuickBASIC loads your program, the underscores are removed and the
   continued lines are joined to form a single line. The line-length limit is
   relaxed in this case. Underscores cannot be used to continue DATA or REM
   statements.


In MMEdit, you will have to end a line with space then underscore.
MMEdit will reassemble the lines before uploading with either XMODEM or AUTOSAVE.

The one big difference is you are still restricted to 255 characters for a reassembled line.


Jim


I could live with that restriction - for me it's far more readable to be able to break a statement across lines especially when there's in-line conversions happening.

I know it's making work for someone else to do, but if you are tempted to add, please take this as a massive up vote.
 
MustardMan

Senior Member

Joined: 30/08/2019
Location: Australia
Posts: 175
Posted: 11:16am 24 Apr 2021
Copy link to clipboard 
Print this post

I came across this issue again today, and had to go with an ugly line that disappeared off the edge of the editor window (MMedit that is, not the built in editor), and was wondering if there had been any progress, or any other thoughts?

Something I have used only rarely is starting a variable name with an underscore (eg"_x=1"), which is valid syntax. I suppose the 'joining logic' could look for "_<CR>" or "_<LF>" to decide if we were looking at a 'line extension' directive...

And yes, like elk1984, I would be happy with a 255 character limit - to my knowledge 255 is the limit with most BASICs anyway... not too sure about the MikroBasic compiler though...

Cheers,
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5695
Posted: 01:25pm 24 Apr 2021
Copy link to clipboard 
Print this post

mmmm... TRS-80. I spent many a happy hour with mine. It's still in the shed, but I don't think I'd risk switching it on now. Not without a good clean and overhaul anyway!

Just my 2-penn'orth...
I'm not happy with long line lengths anyway. IMHO it makes for better program legibility if the lines are obviously separate (although the DOS+ system was nice. I think the LDOS disk BASIC would do that too). After all, we aren't restricted by line numbers now so there's no real need to group statements within a line. Usually, by judicious use of functions & subs, you can shrink lines down very efficiently. On top of all that, long lines are difficult to edit in future if you need to add extra code.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 05:56pm 24 Apr 2021
Copy link to clipboard 
Print this post

  Paul_L said  There was an alternate operating system available for the Trash 80 called "Dos Plus" produced by Micro Systems Software. It's BASIC interpreter, which required line numbers, used the <down arrow> as a line continuation character and it treated the <tab> character as white space. When you stuck a <down arrow> into a code line it would display the following character at the left end of the following screen line.

You could write a line which would display like this:
120
       print
       @ 20,40
       using "###,###.##    "
       a;
       b;
       c
130


By typing this:


120<dn><tab>print<dn><tab>@ 20,40<dn><tab>using "###,###.##    "<dn><tab>a;<dn><tab>b;<dn><tab>c<enter>130<enter>


This enabled really pretty listings for a line numbered BASIC and it didn't need a special line continuation character which would be visible in the listing.

Does MMBasic, in its present incarnation, treat the <down arrow> and the <tab> character as white space?

Paul in NY


I just noticed that nobody who knows the nitty gritty about how MMBasic parses code lines ever answered my key question from 2 1/2 years ago .... Does MMBasic, in its present various incarnations, treat the <down arrow> and the <tab> character as white space?

Paul in NY
Edited 2021-04-25 03:57 by Paul_L
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1082
Posted: 06:46pm 24 Apr 2021
Copy link to clipboard 
Print this post

  Paul_L said  Does MMBasic, in its present various incarnations, treat the <down arrow> and the <tab> character as white space?

Maybe not a useful answer, but I just jammed some linefeed and tab characters into a CMM2 BASIC program to test. Program ran fine.
After an EDIT/SAVE cycle, I re-examined the source file:
<LF> characters (ascii code $0A) had been converted to <CR><LF>
<TAB> characters (ascii code $09) had been converted to <SPACE><SPACE>
Visit Vegipete's *Mite Library for cool programs.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8563
Posted: 09:42pm 24 Apr 2021
Copy link to clipboard 
Print this post

  Quote  Does MMBasic, in its present various incarnations, treat the <down arrow> and the <tab> character as white space?


Not sure the point of the question. Tab is converted to spaces. Arrow keys generate escape sequences which when received by a program are converted to values > 127 but values > 127 can not be part of a file or program and are only used by things like input$

Certainly as far as the CMM2 is concerned continuation lines are NEVER going to happen. The in-built editor supports lines up to 240 chars and that is a fixed limit.
 
     Page 1 of 2    
Print this page
© JAQ Software 2024