|
Post by bitvast on Sept 10, 2014 15:35:29 GMT 1
Just checking - it seems that DEF FN returns a float by default, so the only subscript necessary is $ for strings?
|
|
|
Post by bigbass on Sept 10, 2014 17:20:23 GMT 1
this is the normal standardized way in the docs
DEF FN First$(x$) = LEFT$(x$, INSTR(x$, " ")-1) PRINT First$("One Two Three")
however this below is a non-standard but a needed way also focus attention on the $ after First not being used *That's nice because it keeps it BaConized using BaCon's syntax and solving the big problem of when you have to port c macros (that never use the $)
DEF FN First(x$) = LEFT$(x$, INSTR(x$, " ")-1) PRINT First("One Two Three") FORMAT "%s\n"
Well its good that there are several ways to get a result Maybe we could add these too as "special extra options" for with and without the $
Joe
|
|
|
Post by bitvast on Sept 10, 2014 19:03:43 GMT 1
Hi Joe,
FUNCTION area1(FLOATING x, FLOATING y) RETURN x * y END FUNCTION
DEF FN area2(x, y) = x * y
PRINT area1(2.5, 3) PRINT area2(2.5, 3)
7 7.5
Adding the float subscript # to area1 results in 7.5, but the DEF FN function doesn't need it.
|
|
|
Post by Pjot on Sept 11, 2014 19:03:53 GMT 1
Hi bitvast,
The difference is that DEF FN is actually being replaced by the 'x*y', while the function returns a value.
Be Peter
|
|
|
Post by bigbass on Sept 12, 2014 17:55:13 GMT 1
|
|
|
Post by bigbass on Sept 13, 2014 18:15:47 GMT 1
Hey bitvast
Maybe I posted too much info in the last post looking back but there are many differences between FUNCTION and DEF FN better to think DEF FN is a preprocessed macro that doesn't need the type to be given
so just to solve your original question
here is just the working solution notice we added a return TYPE FLOATING then you can decide how you want to format the output I used %.1f to allow one decimal place to display
Hope that answer is to the point Joe
FUNCTION area1(FLOATING x, FLOATING y) TYPE FLOATING RETURN x * y END FUNCTION
DEF FN area2(x, y) = x * y
PRINT area1(2.5, 3) FORMAT "%.1f\n" PRINT area2(2.5, 3)
|
|
|
Post by bitvast on Sept 14, 2014 7:50:01 GMT 1
Hi Joe, I didn't realize that DEF FN uses C macros, just been reading up about them, now I understand. Or you can use the subscript way: FUNCTION area1#(FLOATING x, FLOATING y) RETURN x * y END FUNCTION
DEF FN area2(x, y) = x * y
PRINT area1#(2.5, 3) FORMAT "%.1f\n" PRINT area2(2.5, 3)
|
|