Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 00:46 03 May 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 : CMM2: V5.05.06RC19: Scotty more power

     Page 2 of 4    
Author Message
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3848
Posted: 03:55pm 15 Nov 2020
Copy link to clipboard 
Print this post

Here you go:

With RC19:
Colour Maximite 2
MMBasic Version 5.05.06RC19
Copyright 2011-2020 Geoff Graham
Copyright 2016-2020 Peter Mather

> list "new_bug.bas"
Option Explicit On
Option Default None

test_exists()
End

Sub test_exists()
 Local f$ = Mm.Info$(Current)
 Print fil.exists%(f$)
 Print fil.exists%(fil.get_parent$(f$) + "/" + fil.get_name$(f$))
End Sub

Function fil.exists%(f$)
'  On Error Skip
 fil.exists% = LCase$(Dir$(f$, ALL)) = LCase$(fil.get_name$(f$))
End Function

' Gets the name of file/directory 'f$' minus any path information.
Function fil.get_name$(f$)
 Local i%

 For i% = Len(f$) To 1 Step -1
   If InStr("/\", Mid$(f$, i%, 1)) > 0 Then Exit For
 Next i%

 fil.get_name$ = Mid$(f$, i% + 1)
End Function

' Gets the parent directory of 'f$', or the empty string if it does not have one.
Function fil.get_parent$(f$)
 Local i%

 For i% = Len(f$) To 1 Step -1
   If InStr("/\", Mid$(f$, i%, 1)) > 0 Then Exit For
 Next i%

 If i% > 0 Then fil.get_parent$ = Left$(f$, i% - 1)
End Function

> run "new_bug.bas"
1
Error in line 15: FIL.EXISTS is not declared


And with RC15:

> Colour Maximite 2
MMBasic Version 5.05.06RC15
Copyright 2011-2020 Geoff Graham
Copyright 2016-2020 Peter Mather

> run "new_bug.bas"
1
1


Please note you can't use Mm.Info(FileSize f$) as a general mechanism for determining the existence of a file/directory because it returns -1 for both existing directories and non-existent files.

Best wishes,

Tom
Edited 2020-11-16 01:56 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8592
Posted: 05:32pm 15 Nov 2020
Copy link to clipboard 
Print this post

Sorry but I'm not prepared to look at it while you use constructs like

fil.exists% = LCase$(Dir$(f$, ALL)) = LCase$(fil.get_name$(f$))


This is not valid MMBasic syntax

If it happened to work in the past that was a complete fluke and the only bug was that it should have give an error then
Edited 2020-11-16 03:33 by matherp
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3848
Posted: 06:09pm 15 Nov 2020
Copy link to clipboard 
Print this post

  matherp said  Sorry but I'm not prepared to look at it while you use constructs like

fil.exists% = LCase$(Dir$(f$, ALL)) = LCase$(fil.get_name$(f$))


This is not valid MMBasic syntax

If it happened to work in the past that was a complete fluke and the only bug was that it should have give an error then


You've tried to sell me this before and I'm still not buying

Are you trying to tell me that it is invalid to set a variable equal to the result of an expression ... that sounds bananas, as well as being incorrect.

The following 3 formulations for the test all produce the same error:

With brackets:
fil.exists% = (LCase$(Dir$(f$, ALL)) = LCase$(fil.get_name$(f$)))


With NOT and <>:
fil.exists% = Not (LCase$(Dir$(f$, ALL)) <> LCase$(fil.get_name$(f$)))


With IF:
If LCase$(Dir$(f$, ALL)) = LCase$(fil.get_name$(f$)) Then
   fil.exists% = 1
Else
   fil.exists% = 0
EndIf


Best wishes,

Tom
Edited 2020-11-16 04:11 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3848
Posted: 06:25pm 15 Nov 2020
Copy link to clipboard 
Print this post

If '=' is really not intended to behave like the other dyadic logical operators then this exception needs to be documented in big/bold letters in the manual.

Generally accepted BASIC syntax for assignment is:
LET var = expr

"Evaluates the expression and assigns the value to the variable. The LET keyword is optional."

Since:
a = b

is a valid expression that evaluates to 1 (or for some BASICs -1) if 'a' equals 'b' and 0 if not then:
LET var = a = b

should be valid syntax, and given LET is optional so should:
var = a = b


Which despite your protests to the contrary does in general appear to be how MMBasic behaves, IMO this bug has nothing to do with that.

Sorry,

Tom
Edited 2020-11-16 04:27 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8592
Posted: 06:37pm 15 Nov 2020
Copy link to clipboard 
Print this post

Coukld take some time to find and fix - workround is

local s$=fil.get_parent$(f$) + "/" + fil.get_name$(f$)
print fil.exists%(s$)
 
William Leue
Guru

Joined: 03/07/2020
Location: United States
Posts: 383
Posted: 06:42pm 15 Nov 2020
Copy link to clipboard 
Print this post

Of course, in C and its derivatives like C++, the single-equals operator is transitive and does chain in exactly this way, and this is an explicitly legal usage.

I have to confess that I have never seen assignment chaining in any BASIC and I am surprised it works here. I wonder if this is an inadvertent side effect and might be dependent on some specific implementation detail that could be changed any time. I have never seen a formal language definition for any BASIC including MMBASIC, so it makes me wonder.

-Bill
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3848
Posted: 06:43pm 15 Nov 2020
Copy link to clipboard 
Print this post

  matherp said  Coukld take some time to find and fix - workround is

local s$=fil.get_parent$(f$) + "/" + fil.get_name$(f$)
print fil.exists%(s$)


Thanks Peter.

I'd appreciate it if you could shake out the validity or not of var = a = b with Geoff.

Does anyone have access to other "Microsoft BASIC" (not VB) "standard" BASICs to see whether it is widely accepted or not ?

Kind regards,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
William Leue
Guru

Joined: 03/07/2020
Location: United States
Posts: 383
Posted: 06:45pm 15 Nov 2020
Copy link to clipboard 
Print this post

Here is a link to a formal BNF language syntax definition for Dartmouth BASIC. It of course does not tell us anything about MMBasic.

https://watermark.silverchair.com/15-1-37.pdf?token=AQECAHi208BE49Ooan9kkhW_Ercy7Dm3ZL_9Cf3qfKAc485ysgAAAqUwggKhBgkqhkiG9w0BBwagggKSMIICjgIBADCCAocGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMDQvxDHIB-0DwSNELAgEQgIICWLRfcQv7L16kQwbrznaR_DTsm4T3yAvS8SA37s4CZAm55Y7IiADGJI_wJCRE4bET17t0SR5VMPmZxaWKp9HvkeNy4UAq2gwpNz9Zol9tKsBY0OS0_09-ZDYPQ6v2Au7yuGBIl7CF3jwJZG4gf-o5PcnGXyJdO9iKbTg3SjMjpaQExraB0Rp3YydZ9BqHmgqH-_J1yMK24lvvBRvGSv_n8i_WoifkgkmEYaK-jMMJql8PVGi-kwi1cygeOgtuWmRcYWK9VZA-YuTgTdIfICe_hcaOOFHd_8tBVbFnYhdYf3qKQm3g8N-pJnwoRkQHRWBo9u66GxBiL4JZ65iGU1U2CKbaWk1ayVGJpsFobtgRsHRLmbYTnSkLC1qhbqn5CVTWvtLsofc2tPWDO6eI9bUIYYj9Mxf5nBm1VNyzsV5NVCvdEs1DfaQpPFB0Du-D4QXkNI1siA_jvyt7HrI-8BDbUNBkOkx6InaeG1KUe5mhTSEb6WypTeCk_caZRTjtuDZBPjr5u3Vk8wsRJPRLw0_HdWS_vMfPrHhruWP6z7iRMHQmZjuRlHJ0ZOsGs1rVYGLHM9t0LHcfLGFewG1077FvkILFM591UCeBMn3FeVaz8aU-LYhb5VJut79ZJ9KdgVZrcARaYpOwsQrJtvz0x3VMlNRDAiJCZiiLLjUpfhwxbOCF1I1yOuLepWd2QtzKy9tHRaD57fY9_OkGq-fa5ufmq_1xQufJMXpzjnnw4kDJ6sHlPbyrEz6-1TwN2-OY-n2oUdjBUl-qJbfgS5ZlP3S_n2VbQuUwrMlbFg
 
CircuitGizmos

Guru

Joined: 08/09/2011
Location: United States
Posts: 1421
Posted: 06:46pm 15 Nov 2020
Copy link to clipboard 
Print this post

  thwill said  
I'd appreciate it if you could shake out the validity or not of var = a = b with Geoff.


Does:

var = (a = b)

change things?
Micromites and Maximites! - Beginning Maximite
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3848
Posted: 06:57pm 15 Nov 2020
Copy link to clipboard 
Print this post

  William Leue said  I have never seen a formal language definition for any BASIC including MMBASIC, so it makes me wonder.


I don't believe it to be syntactically ambiguous so I would be surprised if it is not allowed.

A quick check shows it to be valid syntax for BBC BASIC, C64 BASIC and Sinclair (ZX-81) BASIC. Note that in the first two cases the value of true is -1 whilst for Sinclair, like MMBasic it is 1.

Feeling confident,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3848
Posted: 07:00pm 15 Nov 2020
Copy link to clipboard 
Print this post

  CircuitGizmos said  Does:

var = (a = b)

change things?


Nope, as indicated in my earlier post this has the same behaviour with regards this bug, I believe is unrelated to this issue of syntax since it is reproducible using an IF THEN ELSE ENDIF formulation.

I'm going to go out on a limb here and say that MMMBasic is supposed to, and in fact does support var = a = b, I've been using it enough, and that for once Peter might be mistaken.

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

Joined: 11/12/2012
Location: United Kingdom
Posts: 8592
Posted: 07:00pm 15 Nov 2020
Copy link to clipboard 
Print this post

  Quote  I don't believe it to be syntactically ambiguous


But it is ambiguous

What does
c=7;
a = b= c;
do in C?
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3848
Posted: 07:07pm 15 Nov 2020
Copy link to clipboard 
Print this post

  William Leue said  I have to confess that I have never seen assignment chaining in any BASIC and I am surprised it works here.


Hang on Bill, this is not "assignment chaining", the equivalent "C" expression for this construct is:
var = a == b

not:
var = a = b


Best wishes,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 445
Posted: 07:15pm 15 Nov 2020
Copy link to clipboard 
Print this post

in MSX Basic works fine

10 DIM X,Y,Z
20 X=1
30 Y=2
40 Z=X=Y
50 PRINT Z


The result is 0

For Y=1 (equals X) the result is -1
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3848
Posted: 07:23pm 15 Nov 2020
Copy link to clipboard 
Print this post

  matherp said  
  Quote  I don't believe it to be syntactically ambiguous


But it is ambiguous

What does
c=7;
a = b= c;
do in C?


This is an example of assignment chaining and it assigns the value of 'c', i.e. 7 to 'a' and 'b' But BASIC is not C and has different rules.

By not syntactically ambiguous I meant that a BASIC parser could unambiguously determine the meaning of = from its context.

If a statement starts "LET|DIM|CONST|STATIC|LOCAL var =" or "var =" (where var might be an array variable) then "=" is the assignment operator, otherwise it is the dyadic equality operator.

I've cited 3 (4 if you count MMBasic) versions of BASIC where the = operator behaves as I have described and used. Do you have a counter example ?

This is "fun" ,

Tom
Edited 2020-11-16 05:25 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3848
Posted: 07:29pm 15 Nov 2020
Copy link to clipboard 
Print this post

  LeoNicolas said  in MSX Basic works fine ...


And MSX Basic is definitely a Microsoft BASIC such as that with which MMBasic claims compatibility ... let's not start to argue whether 1 or -1 should be the true value of true

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5735
Posted: 08:04pm 15 Nov 2020
Copy link to clipboard 
Print this post

I've never seen
var = a = b
as valid BASIC. I'm rather surprised that you can get a result out of it at all . I'd have expected a syntax error. I must admit that I've never actually tried it. :)

I can imagine it working in Sinclair BASIC (if it will let you enter it) as that has a lot of quirks (some that I love, like string slicing being valid on the LHS of the equation).

var = (a = b) is perfectly valid, of course.

Surely var = a = b could mean any of:
1. set var to a then set a to b
2. set both a and b equal to var
3. set var to the true/false result of (a=b)
It seems very ambiguous to me.
Mick

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

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3848
Posted: 08:26pm 15 Nov 2020
Copy link to clipboard 
Print this post

  Mixtel90 said  Surely var = a = b could mean any of ...


And a+b could mean push 'a' onto the stack, pop the top two values of the stack and add them, push the result onto the stack and then push 'b' onto the stack, but it doesn't because we are using the rules/syntax of BASIC not RPN.

When I used the word "ambiguous" I meant to the parser, not to a user unfamiliar with the language's idiosyncrasies.

Can anyone cite a (non-toy) BASIC that does not support var = a = b ?

Best wishes,

Tom
Edited 2020-11-16 06:32 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
RetroJoe

Senior Member

Joined: 06/08/2020
Location: Canada
Posts: 290
Posted: 08:46pm 15 Nov 2020
Copy link to clipboard 
Print this post

Just checked on my Apple //e.

AppleSoft BASIC also supports this syntax.

] a=7=7
] print a
1

I don’t think it is ambiguous at all if you know that BASIC does not have an explicit assignment operator (I’ve always been partial to Pascal’s := myself ...).

Whatever semantic ambiguity exists is caused by the optional use of the keyword LET.

If LET is used consistently, then the code reads like English I.e. Let (this variable) take on the value of (everything that appears on the RHS of the = sign).
Edited 2020-11-16 06:51 by RetroJoe
Enjoy Every Sandwich / Joe P.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5911
Posted: 08:51pm 15 Nov 2020
Copy link to clipboard 
Print this post

var = a = b

The LET is only implied for the first equals sign.
LET var = a = b
  Quote  LET is automatically assumed if a statement does not start with a command.


The second equals sign is going to be an equality test.
To make it clear and to make sure that you don't get caught by order of precedence, use brackets.
var = (a = b)

This all had nothing to do with the bug you found and only served as a distraction.

  Quote  FUNCTION fil.exists%(f$)
'  On Error Skip
fil.exists% = 2
END FUNCTION


would have been a better example to show the bug.

Jim
VK7JH
MMedit   MMBasic Help
 
     Page 2 of 4    
Print this page
© JAQ Software 2024