Re: [Ql-Users] Function type error

2017-08-10 Thread Per Witte via Ql-Users
I couldnt resist wading in here. Regarding Michael's original question the
Mint% routine should answer.Try this:

100 :
110 a = 330.7: b = 440.7
120 PRINT #0, Min_Int%(a, b), Mint%(a, b)
130 PAUSE -1
140 STOP
150 :
160 DEFine FuNction Min_Int%(x%,i)
170  IF x% < i : RETurn x% : ELSE : RETurn i
180 END DEFine
190 :
200 DEFine FuNction Mint%(x%, i)
210 LOCal a%
220 IF x% < b: a% = x%: ELSE : a% = i
230 RETurn a%
240 END DEFine Mint%
250 :

Dilwyn's solution is somewhat different in that a% = INT(a) <> a% = a, as
can be verified by running the routine below:

100 CLS: FOR i = 4 TO 5.1 STEP .1: PRINT Flint(i)! i
110 DEFine FuNction Flint(a%)
120 LOCal x%
130 x% = a%
140 IF INT(a%) = x%: RETurn 1
150 RETurn 0
160 END DEFine Flint
170 :

(But replacing the line 100 above with the line below, wheres the logic in
this:
100 CLS: FOR i% = 4 TO 5.1 STEP .1: PRINT Flint(i%)! i%
? Probably the result of hitting a RIRO design paradigm?)

Per

On 10 August 2017 at 18:22, Dilwyn Jones via Ql-Users <
ql-users@lists.q-v-d.com> wrote:

> The fact that the function name ends in % doesn't seem to make it an
> integer function (although the QL user guide says that "the type of data
> returned by the function is indicated by the type appended to the function
> identifier") any more than  parameter names have no type until they are
> set, so parameter x% could be float or integer, depending on what it is
> made when parameters are passed.
>
> As a workaround, add INT in line 160
>
> 160 IF INT(x%) < i : RETurn INT(x%) : ELSE return INT(i)
>
> Dilwyn
>
> -Original Message- From: Michael Bulford via Ql-Users
> Sent: Thursday, August 10, 2017 5:54 PM
> To: ql-users@lists.q-v-d.com ; ql-users-requ...@lists.q-v-d.com
> Subject: [Ql-Users] Function type error
>
>
> Hi all,
> I've no idea whether this has been mentioned before, but consider this …
> 100 :110 PRINT #0, Min_Int%(330.7, 440.7)120 PAUSE -1130 STOP140 :150
> DEFine FuNction Min_Int%(x%,i)160  IF x% < i : RETurn x% : ELSE : RETurn
> i170  END DEFine The correct result should be 331, sincethis is an integer
> function.On QPC2, SBASIC gives the result as 330.7QLiberator likewise also
> gives 330.7 Can anything be done? Michael
>
> ___
> QL-Users Mailing List
>
> ---
> This email has been checked for viruses by AVG.
> http://www.avg.com
> ___
> QL-Users Mailing List
___
QL-Users Mailing List

Re: [Ql-Users] Function type error

2017-08-10 Thread Michael Bulford via Ql-Users
Thanks for your explanations.  This is all specific to SBASIC.
Tobias gives an example with a LOCal name the same as the function name.
Although this is possible, it cannot be recommended.  You will not be able
to call the function recursively.  And it won't compile with either QLiberator 
or Turbo!
Michael

On Thu, 10 Aug 2017 20:33:58, Tobias Fr?schle via Ql-Users 
 wrote:

The type of a function is not determined by the function name ending in a $ or 
% sign, but rather by what it returns - You can even write a function STRING% 
that returns a string or a function a$ that returns an integer value. The name 
you give your function is simply a hint to yourselves on what it might return.

What you actually return in your original function is the result of an 
/expression/ - and numerical expressions in S*BASIC are of type floating point. 
If you assign the value to the expression to a LOCal integer value and return 
that, you will actually get your desired result.

1000 DEFine FuNction x% (param)
1010   LOCal x%
1020   x% = param / 10
1025  REMark assign to integer variable x% to make sure INT is returned
1030  RETurn x%
1040 END DEFine x%
___
QL-Users Mailing List


Re: [Ql-Users] Function type error

2017-08-10 Thread Tobias Fröschle via Ql-Users
The type of a function is not determined by the function name ending in a $ or 
% sign, but rather by what it returns - You can even write a function STRING% 
that returns a string or a function a$ that returns an integer value. The name 
you give your function is simply a hint to yourselves on what it might return.

What you actually return in your original function is the result of an 
/expression/ - and numerical expressions in S*BASIC are of type floating point. 
If you assign the value to the expression to a LOCal integer value and return 
that, you will actually get your desired result.

1000 DEFine FuNction x% (param)
1010   LOCal x%
1020   x% = param / 10
1025  REMark assign to integer variable x% to make sure INT is returned
1030  RETurn x%
1040 END DEFine x%

Dilwin's proposal /looks/ like it would be doing the right thing, but actually 
isn't. INT in S*BASIC returns a long integer which cannot be properly 
represented in the language, so it's actually converted to a floating point 
value and returned (albeit with the proper value).

Tobias


> Am 10.08.2017 um 19:22 schrieb Dilwyn Jones via Ql-Users 
> :
> 
> The fact that the function name ends in % doesn't seem to make it an integer 
> function (although the QL user guide says that "the type of data returned by 
> the function is indicated by the type appended to the function identifier") 
> any more than  parameter names have no type until they are set, so parameter 
> x% could be float or integer, depending on what it is made when parameters 
> are passed.
> 
> As a workaround, add INT in line 160
> 
> 160 IF INT(x%) < i : RETurn INT(x%) : ELSE return INT(i)
> 
> Dilwyn
> 
> -Original Message- From: Michael Bulford via Ql-Users
> Sent: Thursday, August 10, 2017 5:54 PM
> To: ql-users@lists.q-v-d.com ; ql-users-requ...@lists.q-v-d.com
> Subject: [Ql-Users] Function type error
> 
> Hi all,
> I've no idea whether this has been mentioned before, but consider this … 100 
> :110 PRINT #0, Min_Int%(330.7, 440.7)120 PAUSE -1130 STOP140 :150 DEFine 
> FuNction Min_Int%(x%,i)160  IF x% < i : RETurn x% : ELSE : RETurn i170  END 
> DEFine The correct result should be 331, sincethis is an integer function.On 
> QPC2, SBASIC gives the result as 330.7QLiberator likewise also gives 330.7 
> Can anything be done? Michael
> 
> ___
> QL-Users Mailing List
> 
> ---
> This email has been checked for viruses by AVG.
> http://www.avg.com 
> ___
> QL-Users Mailing List

___
QL-Users Mailing List

Re: [Ql-Users] Function type error

2017-08-10 Thread Dilwyn Jones via Ql-Users
The fact that the function name ends in % doesn't seem to make it an integer 
function (although the QL user guide says that "the type of data returned by 
the function is indicated by the type appended to the function identifier") 
any more than  parameter names have no type until they are set, so parameter 
x% could be float or integer, depending on what it is made when parameters 
are passed.


As a workaround, add INT in line 160

160 IF INT(x%) < i : RETurn INT(x%) : ELSE return INT(i)

Dilwyn

-Original Message- 
From: Michael Bulford via Ql-Users

Sent: Thursday, August 10, 2017 5:54 PM
To: ql-users@lists.q-v-d.com ; ql-users-requ...@lists.q-v-d.com
Subject: [Ql-Users] Function type error

Hi all,
I've no idea whether this has been mentioned before, but consider this … 100 
:110 PRINT #0, Min_Int%(330.7, 440.7)120 PAUSE -1130 STOP140 :150 DEFine 
FuNction Min_Int%(x%,i)160  IF x% < i : RETurn x% : ELSE : RETurn i170  END 
DEFine The correct result should be 331, sincethis is an integer function.On 
QPC2, SBASIC gives the result as 330.7QLiberator likewise also gives 330.7 
Can anything be done? Michael


___
QL-Users Mailing List

---
This email has been checked for viruses by AVG.
http://www.avg.com 


___
QL-Users Mailing List

[Ql-Users] Function type error

2017-08-10 Thread Michael Bulford via Ql-Users
Hi all,
I've no idea whether this has been mentioned before, but consider this … 100 
:110 PRINT #0, Min_Int%(330.7, 440.7)120 PAUSE -1130 STOP140 :150 DEFine 
FuNction Min_Int%(x%,i)160  IF x% < i : RETurn x% : ELSE : RETurn i170  END 
DEFine The correct result should be 331, sincethis is an integer function.On 
QPC2, SBASIC gives the result as 330.7QLiberator likewise also gives 330.7 Can 
anything be done? Michael
   
___
QL-Users Mailing List