|
Post by bigbass on Jul 10, 2013 17:33:51 GMT 1
I was interested in Peter's MD5 conversion
and I wanted to do DEF FN with a macro for shifting I read macros are faster and wanted to experiment with something in BaCon
C Code
#define BIT(x) (1 << (x))
convert #define to BaCon
x = 8 DEF FN BIT(x) =(1 << (x)) PRINT "the number ", x ," = " ,BIT(x) , " bits"
x=8 but we can change this to any value
*anyway a fun test Joe
|
|
|
Post by bigbass on Jul 21, 2013 16:56:26 GMT 1
to show the power of DEF FN here is another optional way using PROTO
PROTO printf
DEF FN ID(...) =#__VA_ARGS__
printf("%s \n", ID(" he llo" , "world") );
with mixed arguments
PROTO printf
DEF FN ID(...) =#__VA_ARGS__
printf("%s \n", ID(" he llo" , "world" ,new ,100) );
|
|
|
Post by bigbass on Jul 21, 2013 17:03:19 GMT 1
These below in this post are code examples by alexfish
FUNCTION MY_FUNCTION(NUMBER x, NUMBER y,...) LOCAL reply
reply=x*y
RETURN reply
END FUNCTION
DEF FN MY_MULTIPLY(x,...) = MY_FUNCTION(x, __VA_ARGS__)
PRINT MY_MULTIPLY(12,4)
============================
more examples
DECLARE MYBITS TYPE void* LOCAL GETBITS$ DEF FN ID2(...) =#__VA_ARGS__ DEF FN ID(...) =#__VA_ARGS__ MYBITS = ID(1 , 2 " he llo" , "world" , 3 , 4) GETBITS$=MYBITS PRINT "GETBITS : " ,GETBITS$
modifiied to no "" EXAMPLE 2
DECLARE MYBITS TYPE void* LOCAL GETBITS$ DEF FN ID2(...) =#__VA_ARGS__ DEF FN ID(...) =#__VA_ARGS__ MYBITS = ID(1 , 2 he llo , world , 3 , 4) GETBITS$=MYBITS PRINT "GETBITS : " ,GETBITS$
THEN some code FOR IN applies to Example 2
FOR each$ IN GETBITS$ STEP "," PRINT each$ NEXT
|
|
|
Post by bigbass on Dec 2, 2013 16:42:43 GMT 1
If you don't want to use the $ with the function name you can do it this way just remember to use FORMAT "%s\n" with the PRINT command this gets around the error: incompatible type for argument 1 of '__b2c__str' please remember the official way is to use FN MANY_ARGS $ basic-converter.org/documentation.html#DEF
DEF FN MANY_ARGS(...) =#__VA_ARGS__
arglist$=MANY_ARGS(One,Two,Three,four)
PRINT MANY_ARGS(One,Two,Three,four) FORMAT "%s\n"
count = 0 FOR each$ IN arglist$ STEP "," PRINT each$ INCR count NEXT PRINT "number of arguments in function MANY_ARGS = ", count
PRINT "---------------------" '---get first argument only DEF FN First(arglist$) = LEFT$(arglist$, INSTR(arglist$, ",")-1) PRINT "only first arg " PRINT First(arglist$) FORMAT "%s\n"
PRINT "---------------------" '---get last argument only DEF FN Last(arglist$) = RIGHT$(arglist$, INSTR(arglist$, ",")) PRINT "only last arg " PRINT Last(arglist$) FORMAT "%s\n"
|
|