LoginLogin

Optional Arguments for SB!

Root / Submissions / [.]

computableeCreated:
Download:D32N33JY
Version:2Size:
This is a program that allows the user to define multiple functions of the same name with a different argument count. The appropriate function is automatically detected and used at compile time. This program also allows you to redefine default SB functions as your own. For those with previous experience: FUNCTION OVERLOADING AND OVERRIDING!

Instructions:

First, assign PRG:OPTNL_ARGS as your SmileTool (it will download into the [DEFAULT] folder). Write your SB program in slot 0. Running the SmileTool will compile your SB into legal SB in slot 1. You can run, save, and publish this PRG independently. Example:
DEF ADD(X,Y)
RETURN X+Y
END
DEF ADD(X,Y,Z)
RETURN X+Y+Z
END
?ADD(1,2)
?ADD(1,2,3)
Normally, SmileBasic would throw a duplicate function error. However, with this program, this code runs just fine!

So, I assume it would convert that example into something like:
DEF ADD0(X,Y)
RETURN X+Y
END
DEF ADD1(X,Y,Z)
RETURN X+Y+Z
END
?ADD0(1,2)
?ADD1(1,2,3)
is there a limit on the number of these functions? Also, I think it would be even more useful if you made a decompiler, converting (for example) ADD0 and ADD1 back into ADD.

It would actually convert into
DEF ADD2(X,Y)
RETURN X+Y
END
DEF ADD3(X,Y,Z)
RETURN X+Y+Z
END
?ADD2(1,2)
?ADD3(1,2,3)
There is no limit on the amount of functions you can overload :P

This seems extremely useful; I might use it. Thanks for this!

This is rad as hell, not gonna lie. Though I can't see much use coming out of this for libraries since you would have to compile the lib... hm. As a development tool, it's a great idea! I still think they should be natively supported though.

Replying to:snail_
This is rad as hell, not gonna lie. Though I can't see much use coming out of this for libraries since you would have to compile the lib... hm. As a development tool, it's a great idea! I still think they should be natively supported though.
It would be awesome if you could specify a pre-pre compiler, kind of like how you can set the smile tool program. When you press select/start or do RUN, it would pass the code to the pre-pre compiler, and that program would output the modified code, which would then be fully precompiled.

Replying to:snail_
This is rad as hell, not gonna lie. Though I can't see much use coming out of this for libraries since you would have to compile the lib... hm. As a development tool, it's a great idea! I still think they should be natively supported though.
I would make it so that the compiler would automatically EXEC slot 1 (which I can do), but then the PRG wouldn't be able to LOAD anything from its own project folder; it would only be able to LOAD from [DEFAULT]

So I think there might be as many compilers for SB as there are actual programs. Let me get a list of compilers/interpreters for SB: This N# #AC Lowerdash Brainfuck Malbolge Befunge PTCompiler JYP# Ti-Basic SB SBSP just off the top of my head

What if you have something like
DEF M1(H, L)
RETURN H - L
END
DEF M1(H)
RETURN H + 1
END
DEF M2(R)
RETURN R-1
END
PRINT M1(51)
Would 52 or 50 be printed?

52, as is the expected behavior.

Replying to:computablee
52, as is the expected behavior.
But how would it handle this code? You said yourself that you add a number to the end.

It becomes M12, M11, and M21, and when M1(51) is called, it calls M11.

Replying to:computablee
So I think there might be as many compilers for SB as there are actual programs. Let me get a list of compilers/interpreters for SB: This N# #AC Lowerdash Brainfuck Malbolge Befunge PTCompiler JYP# Ti-Basic SB SBSP just off the top of my head
are you sure? I'm pretty sure 99% of those never got finishedstarted (except the ones you made)

Replying to:computablee
It becomes M12, M11, and M21, and when M1(51) is called, it calls M11.
Please use 'reply' when replying.

Replying to:computablee
It becomes M12, M11, and M21, and when M1(51) is called, it calls M11.
I was on mobile. I couldn't.

Replying to:computablee
It becomes M12, M11, and M21, and when M1(51) is called, it calls M11.
Yes you can :p just hit the top comment in the chain you wish to reply to and your reply will end up at the bottom of that comment chain. I posted this from mobile.

Replying to:computablee
So I think there might be as many compilers for SB as there are actual programs. Let me get a list of compilers/interpreters for SB: This N# #AC Lowerdash Brainfuck Malbolge Befunge PTCompiler JYP# Ti-Basic SB SBSP just off the top of my head
Did someone actually make a Malbolge compiler. I'm calling your bluff; proof please.

I know how this site works (I'm an admin pls), and replying does NOT work from the mobile I'm using.

Replying to:computablee
I know how this site works (I'm an admin pls), and replying does NOT work from the mobile I'm using.
Did you set the setting to forcibly show the reply button? Or is that not your problem

Replying to:computablee
I know how this site works (I'm an admin pls), and replying does NOT work from the mobile I'm using.
Well last I checked, that checkbox didn't exist. It does now though, so, I guess all is good.