Externals, Functions and Procedures

Anything QL Software or Programming Related.
User avatar
desin
Brittle Membrane
Posts: 102
Joined: Mon May 10, 2021 10:33 am

Re: Externals, Functions and Procedures

Post by desin »

Code: Select all

100 OPEN#3,"con_"
110 PAPER#3,0
120 INK#3,4
130 CLS#3
140 PRINT#3
150 PRINT#3
155 :
160 DIM A_x$(0,5)
170 A_x$(0,1)="a"
180 A_x$(0,2)="p"
190 :
200 :
210 b$=F_doit$ ("querty")
220 PRINT#3,, b$
230 :
240 B_x$=A_x$(0,1 TO 2)
250 C_x$=G_doit$ (B_x$)
260 PRINT#3,,A_x$(0,1TO 2),C_x$
270 :
280 b% = i_doit%(3)
290 PRINT#3,,b%
300 :
310 c = doit(4)
320 PRINT#3,,c
330 :
350 kk$=INKEY$(#3,-1)
360 CLOSE
380 :
390 DEFine FuNction F_doit$ (x$)
400 x$=x$&"12345"
410 RETurn x$
420 END DEFine
430 :
440 DEFine FuNction G_doit$ (x$)
450 x$=x$&"1234"
460 RETurn x$
470 END DEFine
480 :
490 DEFine FuNction i_doit% (x)
510 RETurn x*10
520 END DEFine
530 :
540 DEFine FuNction doit (x)
550 x=x*10
560 RETurn x
570 END DEFine
Markus


User avatar
RalfR
QL Wafer Drive
Posts: 1143
Joined: Fri Jun 15, 2018 8:58 pm

Re: Externals, Functions and Procedures

Post by RalfR »

martyn_hill wrote: Sat Mar 01, 2025 1:44 pmor rather, between QLib and the SBASIC interpreter version you're running in SMS2.
There is no SBASIC Interpreter in SMS2. Just an environment to execute QLib executables and a parser for the QD F10 Thing to compile.

Both environment and parser are of course up to date with the release of SMS2.


7000 4E75
Tinyfpga
Gold Card
Posts: 295
Joined: Thu Sep 27, 2018 1:59 am

Re: Externals, Functions and Procedures

Post by Tinyfpga »

There appears to be a misunderstanding concerning my post where I state that:-
"I use the ancient programming environment of SMS2 adapted for SMSQE.

Most of pictures I post are SMSQE running on Q68, Pi5, PCs or tablets

As RalfR states, there is no interpreter in SMS2. I came to this forum from high resolution SMS2 on Atari but gave up using Atari computers some time ago and moved to systems that use SMSQE. As a user of SMS2 I was not exposed to interpreted BASIC and did not want to start using the interpreter that comes with SMSQE. (Except for booting).

To keep SMSQE looking and working like my original SMS2 systems I transferred the SMS2 Startup sequence to SMSQE. The SMS2 Startup file and the SMSQE Boot file I use are very similar. The software that is installed by the Boot file is identical except that I have loaded later versions of the Liberator compiler for this thread's tests.

I still use SMS2 but at low resolutions and in B&W. As far as I am concerned SMS2 and SMSQE are almost identical. (SMSQE's display software is superior of course). You can see below that there is no obvious difference.
SMS2.JPG
I have just checked on the versions of Liberator files I use. I recently upgrade those files for the tests that I display in the thread.
Most of my systems use the following:- Qlib_run v.3.31 Qlib_bin 3.25 Qlib_obj 3.31
The upgraded files used for this thread are:- Qlib_run v.3.44 Qlib_bin 3.42 Qlib_obj 3.45


martyn_hill
QL Wafer Drive
Posts: 1048
Joined: Sat Oct 25, 2014 9:53 am

Re: Externals, Functions and Procedures

Post by martyn_hill »

Ah, ok - that claiifies things and makes it easier to try to replicate.

Which version of SMSQe are you running?

Did you try the earlier suggestion, viz: "What happens if you replace the sub-string range with (1 TO 2)?"

M.


Tinyfpga
Gold Card
Posts: 295
Joined: Thu Sep 27, 2018 1:59 am

Re: Externals, Functions and Procedures

Post by Tinyfpga »

martyn_hill wrote: Did you try...
I did. Lines 28 and 35 of desin's original code did seem odd to me. It's not how I would have written it. He kindly provided an alternative. It seems that the interpreter finds A_x$(0,to 2) ok, but the compiler doesn't.
A_x$(0, 1 to 2) works fine in both cases.

On the matter of passing integers a similar thing happens. The interpreter will accept passing a number but the compiler doesn't. One needs to define an integer first and then pass it. ie c%=1 : doit%(c%). Not doit%(1)

All this is useful but not my real problem, that lies with passing arrays, or as in desin's code, passing an element of an array. At the moment I am getting really odd results in both interpreted and compiled code. I am going to re-read, for the umpteenth time, the instruction manual on Functions before I make a fool of myself.


User avatar
pjw
QL Wafer Drive
Posts: 1588
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: Externals, Functions and Procedures

Post by pjw »

I dont know if its any help or just adds to the confusion: I wrote an article on just that sort of thing for QHJ some years ago. You can find it at Knoware/Articles/Parameter Passing Techniques in S*BASIC. Lots of example; little theory..


Per
I love long walks, especially when they are taken by people who annoy me.
- Fred Allen
stevepoole
Aurora
Posts: 874
Joined: Mon Nov 24, 2014 2:03 pm

Re: Externals, Functions and Procedures

Post by stevepoole »

Hi Tinyfpja,

Here is a short demo program which may help you see what is needed to pass arrays (or even sub_arrays).
Note that the 'zeroeth' cells are dealt with. Here we pass the ENTIRE array, then work on the required internal guts...
Tested OK under QDOS and SMSQ/E, on SGC.
Ensure you pass arrays of the correct type, to or from, PROC or FN subroutines ! Steve.


stevepoole
Aurora
Posts: 874
Joined: Mon Nov 24, 2014 2:03 pm

Re: Externals, Functions and Procedures

Post by stevepoole »

Yer Tiz :
Pass_array.zip
(406 Bytes) Downloaded 18 times
Steve.


stevepoole
Aurora
Posts: 874
Joined: Mon Nov 24, 2014 2:03 pm

Re: Externals, Functions and Procedures

Post by stevepoole »

Hi again Tinyfpga,
Here is a second program showing how to modify arrays when passed as parameters to sub_routines.
In this case we simply zeroise the array, as if we were to redefine it. (Needed for example within TURBO compiled programs).
Tested ok under QDOS and SMSQ/E on SGC. Steve.
return_array.zip
(446 Bytes) Downloaded 17 times
_____________________________________________


Tinyfpga
Gold Card
Posts: 295
Joined: Thu Sep 27, 2018 1:59 am

Re: Externals, Functions and Procedures

Post by Tinyfpga »

Thanks to all that have contributed to this thread.

I have perused and downloaded stuff from Knoware many times but never noticed your article. I am about to print it out to be able to read and understand. I am sure it won't add to my confusion.

This evening I will while away some time playing arround with Pass_array.zip and the examples found in the Knoware article.

Years ago I wrote a PC accounting program for UK micro corporate entities. I still use it today on an elderly Windows XP laptop. It was written in MSBasic for Excel but it does not run properly in current versions of windows. It is a very large program and I can't bothered to find out why it doesn't work.

There are elements of the program (The database side) that I want to re-write in SBASIC, hence my interest in Arrays, Procedures and Functions.

Yesterday whilst looking for articles on Functions I came across the following site. Its no use for BASIC programming but it's a great interactive tutorial site. Anyone up for building an interactive SMSQE version of read-the-docs? Maybe me!
W3schools.jpg


Post Reply