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 : CMM2 - function$ for CALL somehow limited, bug?

Author Message
jirsoft

Guru

Joined: 18/09/2020
Location: Czech Republic
Posts: 533
Posted: 01:52pm 04 Apr 2021
Copy link to clipboard 
Print this post

Hi,
I used in program for programming challenge CALL command for very simple and effective key->routine selector  and found some (for me) strange behaviour:
This code is working

key$= "abc"
func$="nabc"
DO
 fun$ = MID$(func$, INSTR(keys$, LCASE$(INKEY$)) + 1, 1)
 CALL fun$
LOOP
END

SUB n 'empty function, needed for no key press
END SUB

SUB a
 ?a
END SUB

SUB b
 ?b
END SUB

SUB c
 ?c
END SUB


But when I put it all into CALL
DO
 CALL MID$(func$, INSTR(keys$, LCASE$(INKEY$)) + 1, 1)
LOOP

I will get Argument list error. But some primitive string handling are working properly. Is it a bug?
Jiri
Napoleon Commander and SimplEd for CMM2 (GitHub),  CMM2.fun
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 04:32pm 04 Apr 2021
Copy link to clipboard 
Print this post

  Quote  But when I put it all into CALL
DO
CALL MID$(func$, INSTR(keys$, LCASE$(INKEY$)) + 1, 1)
LOOP

I will get Argument list error. But some primitive string handling are working properly. Is it a bug?


Check the manual. I'm surprised the first version works - certainly not by design
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 04:45pm 04 Apr 2021
Copy link to clipboard 
Print this post

I'm missing something, in what way does the manual entry suggest that this wouldn't work?

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: 04:47pm 04 Apr 2021
Copy link to clipboard 
Print this post

  Quote  This is an efficient way of programmatically calling user defined subroutines
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 04:58pm 04 Apr 2021
Copy link to clipboard 
Print this post

Still not getting it Peter: n, a, b & c are USER defined subroutines.

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

Guru

Joined: 18/09/2020
Location: Czech Republic
Posts: 533
Posted: 05:13pm 04 Apr 2021
Copy link to clipboard 
Print this post

I don't see here anything wrong
fun$ = MID$(func$, INSTR(keys$, LCASE$(INKEY$)) + 1, 1)
CALL fun$


When it will be
fun$ = "MID$(func$, INSTR(keys$, LCASE$(INKEY$)) + 1, 1)"
CALL fun$
then it will be calling built-in function.

But interesting is, when I will change it to
key$= "abc"
func$="nabc"
DO
 fun$ = MID$(func$, INSTR(keys$, LCASE$(INKEY$)) + 1, 1)
 CALL "f" + fun$
LOOP
END

SUB fn 'empty function, needed for no key press
END SUB

SUB fa
 ?a
END SUB

SUB fb
 ?b
END SUB

SUB fc
 ?c
END SUB
Then it will work OK, so some calculations are allowed in CALL...
Jiri
Napoleon Commander and SimplEd for CMM2 (GitHub),  CMM2.fun
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 05:18pm 04 Apr 2021
Copy link to clipboard 
Print this post

Yes but MID$ isn't so

CALL MID$(func$, INSTR(keys$, LCASE$(INKEY$)) + 1, 1)

can't work. Everything after the CALL command is interpreted as though it was normal inline code but you can't have two in-built command tokens in a row

You are correct of course about CALL fun$ that is what it is designed for - me being stupid
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 05:19pm 04 Apr 2021
Copy link to clipboard 
Print this post

EDIT: written before Peter's previous response.

My guess is that the parser thinks one of the commas in MID$ or INSTR is a parameter separator in the CALL command.

But I could be talking tripe,

Tom
Edited 2021-04-05 03:22 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
jirsoft

Guru

Joined: 18/09/2020
Location: Czech Republic
Posts: 533
Posted: 05:34pm 04 Apr 2021
Copy link to clipboard 
Print this post

Thanks Peter,
clear with more than one token. In normal life (not one page challenge  ) one row more isn't problem...


I still think it's pretty effective way to select routines depending on key, you have just one condition, all function names need to have exact same length. Maximum length of func$ can be solved with LONGSTRING if needed.

Selector with 5 characters per function:
key$= "abc"
func$="emptyFUNCaFUNCbFUNCc"
DO
      fun$ = MID$(func$, 5*INSTR(keys$, LCASE$(INKEY$)) + 1, 5)
      CALL fun$
LOOP

SUB empty 'empty function, needed for no key press
END SUB

SUB FUNCa
      ?a
END SUB

SUB FUNCb
      ?b
END SUB

SUB FUNCc
      ?c
END SUB

Edited 2021-04-05 03:36 by jirsoft
Jiri
Napoleon Commander and SimplEd for CMM2 (GitHub),  CMM2.fun
 
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