|
Post by alexfish on Jun 28, 2015 19:56:13 GMT 1
Here can pass integer variables into a sub or function without the declaration of type
one normal casts the types in the sub or function
IE
Here one sub and one function with just the a,b & c
SUB MySub(a,b,c)
PRINT a PRINT b PRINT c PRINT "---------------" END SUB
FUNCTION MySub2(a,b,c)
RETURN a*b*c
END FUNCTION
LOCAL x , y TYPE int x= 2 MySub(x,20,3) y= MySub2(x,20,3)
PRINT y
Have Fun + BR Alex
|
|
|
Post by Pjot on Jun 28, 2015 20:53:35 GMT 1
Hi Alex,
Yes, this is true - it works in the upcoming 3.0.4 version.
If variable names have their type suffix added then BaCon can conclude their type already. If the suffix is omitted, then BaCon simply assumes NUMBER type.
E.g.:
SUB Somesub (STRING arg$) <...> END SUB
...can now be written as:
SUB Somesub (arg$) <...> END SUB
Or:
SUB Somesub (double arg) <...> END SUB
...can now be written as:
SUB Somesub (arg#) <...> END SUB
Or:
SUB Somesub (long arg) <...> END SUB
...can be written as:
SUB Somesub (arg%) <...> END SUB
...or simply as:
SUB Somesub (arg) <...> END SUB
Enjoy Peter
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jun 28, 2015 21:17:06 GMT 1
Hi Peter,
I really like your idea of symbol casting. In SB, $ is nothing but eye candy. With the new SBT extension module, I can set SB variables to the default type I wish which is a step in the direction you have taken. 95% of the time letting SB manage type works without issues.
John
|
|
|
Post by alexfish on Aug 23, 2015 16:58:25 GMT 1
Hi all
was playing around with tcc and found the below code works
REM must compile with tcc :: else crash with gcc
LOCAL my_string = "Hello Bacon" TYPE STRING
B$ = "Hello Bacon " REM PRINT my_string PRINT my_string FORMAT "%s\n" PRINT B$
my_string = "Hello Bacon" PRINT my_string FORMAT "%s\n"
FOR t = 0 TO LEN(my_string)-1 PRINT " char : ",my_string[t] ," : ", t FORMAT "%s %c %s %d \n" NEXT
FOR t = 0 TO LEN(my_string)-1 IF (my_string[t] == 32) THEN my_string[t] = '/' ENDIF NEXT
PRINT my_string FORMAT "%s\n"
PRINT "done"
+ there is a one for Peter , Peter can U remove the REM from 'REM PRINT my_string' , check the print out for spaces
LOCAL my_string$ = "Hello Bacon 3.0.4" TYPE STRING
PRINT my_string$
LOCAL my_string = "Hello Bacon 3.0.4" TYPE STRING
REM PRINT my_string
BR Alex
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Aug 24, 2015 7:09:13 GMT 1
Nice refinement Peter. Can't wait to try it.
|
|
|
Post by Pjot on Aug 24, 2015 19:25:41 GMT 1
@ Alex: thanks, this is a bug indeed. I know its cause already, and will upload a fix shortly.
@ jrs: you can proceed and install 3.1, this functionality is in there.
BR Peter
|
|
|
Post by alexfish on Aug 24, 2015 19:43:16 GMT 1
@ Peter
Thanks for the reply
BR Alex
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Aug 25, 2015 11:39:21 GMT 1
I'm looking at using BaCon as a way to create Script BASIC extension modules in BASIC like I'm doing now in C BASIC.
|
|
|
Post by Pjot on Aug 27, 2015 18:22:02 GMT 1
|
|
|
Post by alexfish on Apr 17, 2017 1:31:00 GMT 1
Hi All
another strange but true , using latest BaCon; testing CTYPES
sample code with ctypes listed in the REM statement
Have Fun + BR Alex
' use c type putchar(x) PROTO putchar
REM types to test isalnum , isalpha , isblank , isctrl , isdiget , ispunct, islower , isupper , isprint , isxdigit ' Main ===========================
LOCAL ct TYPE char
LOCAL A$ = " 2A3B4C 5D6E7 F8G9H0" LOCAL t , x LOCAL B$
PRINT "Number output" PRINT FOR t = 1 TO LEN(A$)-1 B$ = MID$(A$,t,1) ct= ASC(B$) IF (isdigit(ct)) THEN putchar( ct) x=VAL(B$) PRINT " add 1 = ", x+1 END IF NEXT PRINT PRINT "Alpha output" PRINT FOR t = 1 TO LEN(A$)-1 B$ = MID$(A$,t,1) ct= ASC(B$) IF NOT(isdigit(ct)) THEN PRINT B$; END IF NEXT PRINT PRINT PRINT "hex output" PRINT FOR t = 1 TO LEN(A$)-1 B$ = MID$(A$,t,1) ct= ASC(B$) IF (isxdigit(ct)) THEN putchar(ct) END IF NEXT ' END ALL THAT ========================
|
|
|
Post by Pjot on Apr 17, 2017 7:17:27 GMT 1
Hi Alex,
Not sure if you try to show an issue? For me, the program works as expected...
BR Peter
|
|
|
Post by alexfish on Apr 17, 2017 15:21:17 GMT 1
Hi Peter no in a polite way ,the Thread title here is 'Trouble shooting & tips and tricks' Here, Hi-lighting here the later. Interesting to see what can be done with ctypes by the forum members BR Alex
|
|