Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:39 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 : Is this too silly for MMBasic or is it useful?

     Page 1 of 2    
Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 06:17pm 08 Mar 2023
Copy link to clipboard 
Print this post

Building strings that need non-printing characters or double quotes requires use of the chr$ function and string addition and is somewhat clunky.

C uses the backslash character to do this

e.g.
char string[]="\"quoted string\"";

and there are variants of this like
\nnn where nnn is the number to be inserted e.g. \034 for a quote

In MMbasic we can't use the backslash as it is used in filesystem pathnames but the

| character (ascii 124) is unused in MMbasic syntax and very unlikely to be used in text strings

I've been playing with this




It can also be used in data statements





Thoughts - do I keep this in for the next beta?

Edited 2023-03-09 04:24 by matherp
 
toml_12953
Guru

Joined: 13/02/2015
Location: United States
Posts: 442
Posted: 06:30pm 08 Mar 2023
Copy link to clipboard 
Print this post

  matherp said  

Thoughts - do I keep this in for the next beta?


As long as you put it in CMM2 BASIC as well, why not?
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 06:31pm 08 Mar 2023
Copy link to clipboard 
Print this post

  Quote  As long as you put it in CMM2 BASIC as well, why not?


Can't | is already used internally in CMM2 and MMB4W
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7937
Posted: 06:36pm 08 Mar 2023
Copy link to clipboard 
Print this post

It's interesting - and a good question!
It's not BASIC, but then neither are BITBANG or TILE. :)
Very useful that it works in DATA statements, I suppose...
Mick

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

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 06:44pm 08 Mar 2023
Copy link to clipboard 
Print this post

My 2c,

I'd use \ and require everyone to either escape them \\ in paths or use UNIX path separators as God intended .

Failing that I wouldn't implement anything that can't also be done on the CMM2 and MMB4W - I certainly wouldn't use it - I wonder if the | issue could be worked around, it's just used in the "hidden" comments at the end of each line of code in the program memory isn't it ?

Alternatively what about using the back-tick `, @ or requiring character codes to be within curly-brackets { } ?

I also find it difficult to believe there isn't already a BASIC dialect that supports something equivalent that could be copied ... though BASIC is one of the hardest things to google about :-(

EDIT: If the interest is limited the double-quote then VB6 would escape it with another double-quote, e.g.
Dim str As String = "This is a string with ""quotes"" in it"


Best wishes,

Tom
Edited 2023-03-09 04:52 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2442
Posted: 06:54pm 08 Mar 2023
Copy link to clipboard 
Print this post

hi peter,
   how would you distinguish between:
a$=chr$(2)+"345"
and
a$=chr$(23)+"45"

you really need both a 'starting' and an 'ending' marker, which as it happens chr$( and ) already provide for, at an overhead of just one byte each (chr$( being a token).


cheers,
rob   :-)
Edited 2023-03-09 04:55 by robert.rozee
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 06:57pm 08 Mar 2023
Copy link to clipboard 
Print this post

  Quote  how would you distinguish between:
a$=chr$(2)+"345"
and
a$=chr$(23)+"45"

Already covered in the first image

chr$ can't be used in DATA statements. Also, concatenating strings will be much slower (factor of 3 in simple test)

  Quote  > timer=0:for i=1 to 1000: s$="|34Hello World|34":next:print timer
13.684
> timer=0:for i=1 to 1000: s$=chr$(34)+"Hello World"+chr$(34):next:print timer
40.375

Edited 2023-03-09 05:01 by matherp
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 07:02pm 08 Mar 2023
Copy link to clipboard 
Print this post

  matherp said  chr$ can't be used in DATA statements.


How about:

OPTION DATA SANE


Which disables the "unusual" behaviour of the DATA statement so that it can properly support expressions ?

Best wishes,

Tom
Edited 2023-03-09 05:04 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 07:02pm 08 Mar 2023
Copy link to clipboard 
Print this post

  thwill said  My 2c, [...]
Failing that I wouldn't implement anything that can't also be done on the CMM2 and MMB4W - I certainly wouldn't use it - [...]

I see it that way too!
causality ≠ correlation ≠ coincidence
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7937
Posted: 07:22pm 08 Mar 2023
Copy link to clipboard 
Print this post

"OPTION DATA SANE"
You spoilsport.....   ;)

I'm coming round to the idea that it's probably better to keep compatibility. Most other things have either alternatives or work-arounds. This is pretty basic functionality.
Mick

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

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 07:40pm 08 Mar 2023
Copy link to clipboard 
Print this post

Think I've found a way of using backslash which means it could be implemented in all versions. Does that change things?
Edited 2023-03-09 05:40 by matherp
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 07:46pm 08 Mar 2023
Copy link to clipboard 
Print this post

  matherp said  Think I've found a way of using backslash which means it could be implemented in all versions. Does that change things?


In that case I think it is useful . Do you want to float how you can use backslash so that the hive-mind can see if you are digging a trap ?

Last year I was considering something similar for MMB4L but in the end abandoned the idea because it wasn't useful if only MMB4L supported it.

Best wishes,

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

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 07:56pm 08 Mar 2023
Copy link to clipboard 
Print this post

In the current code relating to file I/O there are lots of places where I allow slash or backslash but I always eventually convert them to slash.

All I've done is replace getCstring with getFstring for anything file related. The two are identical except that getFstring converts backslash to slash before anything else

I've tested it briefly and all works OK and Microsoft doesn't care if I use all forward slash and linux will be happy

Think I might impose backslash nnn with three digits. That way no termination is ever needed
Edited 2023-03-09 05:58 by matherp
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7937
Posted: 08:30pm 08 Mar 2023
Copy link to clipboard 
Print this post

That sounds like a good way. The backslash idea is much better.
Mick

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

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 08:30pm 08 Mar 2023
Copy link to clipboard 
Print this post

I MMEdit I use aa escape sequence similar to C

Procedure.s macroexpand(txt.s)
 Protected expanded.s, wasSlash.l, nM.l, ch.s, chs.s
 wasSlash=0
 nM=1
 Repeat
   ch=Mid(txt,nM,1)
   If wasSlash=1
     wasSlash=0
     Select  ch
       Case "c","C"
         ch=Chr(3)
       Case "b", "B"
         ch=Chr(8)
       Case "t", "T"
         ch=Chr(9)
       Case "n", "N"
         ch=Chr(10)
       Case "v", "V"
         ch=Chr(11)
       Case "f", "F"
         ch=Chr(12)
       Case "r", "R"
         ch=Chr(13)
       Case "e", "E"
         ch=Chr(27)
       Case "x", "X"
         chs=Mid(txt,nM+1,2)
         ch=Chr(Val("$"+chs))
         nM=nM+2
         ; case "d", "D"
         ; chs$=mid$(macroCode$,n+1,3)
         ; ch$=chr$(val(chs$))
         ; n=n+3
       Case "0","1","2","3","4","5","6","7","8","9"
         chs=Mid(txt,nM,3)
         ch=Chr(Val(chs))
         nM=nM+2
       Case "\"
         ;
       Case "q","Q"
         ch = Chr(34)
       Case "d"; date
         ch=FormatDate("%dd/%mm/%yyyy", Date())
       Case "h" ; time
         ch=FormatDate("%hh:%ii:%ss", Date())
       Case "D" ; UTC date
         ch = UTCdate()
       Case "H" ; UTC time
         ch = UTCtime()
       Default
         ;
     EndSelect
   Else
     If ch="\"
       wasSlash=1
       ch=""
     EndIf
   EndIf
   nM=nM+1
   expanded = expanded + ch
 Until nM > Len(txt)
 ProcedureReturn expanded
EndProcedure


I also chose to require 3 digits if using \nnn

PureBasic has an interesting method or determining if the string requires escaping.
If the string is preceded by tilde character, the string has escape characters, otherwise, treat as is.
a$ =  "Hello world"  ; standard string
 b$ = ~"Escape\nMe !" ; string with escape sequences


Jim
VK7JH
MMedit
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 09:22pm 08 Mar 2023
Copy link to clipboard 
Print this post

One thing that originally attracted me to MMBasic in the first place was its portability.

some way to have "escaped data" (maybe even the cpp exposed) would be nice but I can't help feeling consistency should be paramount. That said, the PicoMite has already gone its own way on a lot of things, so who cares.
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 09:38pm 08 Mar 2023
Copy link to clipboard 
Print this post

  TassyJim said  PureBasic has an interesting method or determining if the string requires escaping.


I like that a lot, the programmer has to clearly "opt in" and at first glance you wouldn't need any special cases.

Best wishes,

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

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1642
Posted: 10:03pm 08 Mar 2023
Copy link to clipboard 
Print this post

For me, one of the attractions of MMBasic is that it is largely compatible with other BASICs (despite Stan's problems). I see that it's faster and more compact but:

MMBasic ain't broke...

Bill

Edit: And it won't be implemented in ALL versions of MMBasic.
Edited 2023-03-09 08:08 by Turbo46
Keep safe. Live long and prosper.
 
toml_12953
Guru

Joined: 13/02/2015
Location: United States
Posts: 442
Posted: 10:23pm 08 Mar 2023
Copy link to clipboard 
Print this post

  matherp said  In the current code relating to file I/O there are lots of places where I allow slash or backslash but I always eventually convert them to slash.

All I've done is replace getCstring with getFstring for anything file related. The two are identical except that getFstring converts backslash to slash before anything else

I've tested it briefly and all works OK and Microsoft doesn't care if I use all forward slash and linux will be happy

Think I might impose backslash nnn with three digits. That way no termination is ever needed


Since the backslash (\) is used on the CMM2 for integer division, is there a conflict there? If not, then by all means use it!

I'd still like to use \n and such however.
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1114
Posted: 11:09pm 08 Mar 2023
Copy link to clipboard 
Print this post

  toml_12953 said  
  matherp said  ......
I've tested it briefly and all works OK and Microsoft doesn't care if I use all forward slash and linux will be happy

Think I might impose backslash nnn with three digits. That way no termination is ever needed


Since the backslash (\) is used on the CMM2 for integer division, is there a conflict there? If not, then by all means use it!

I'd still like to use \n and such however.


Peter, I like the idea and assuming it would only be applicable inside any quoted string, I don't see that it would conflict with integer division.

I do feel however that it needs to be common across ALL versions of MMBasic - there is already some divergence which complicates conversion between different 'mite platforms (other than the obvious hardware differences).
Doug.
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
     Page 1 of 2    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025