Programming in Bit

0

Control flow and tips in Bit

I'm new to Bit, and I'm not sure about how to do certain things like loops, if statements, and other control flow, could someone explain those concepts to me at a beginner level? I'm just starting with the language, so if I could know these and other tips that would be great!

FireCubez

Posted 2018-09-11T15:30:07.163

Reputation: 857

Question was closed 2018-09-11T18:42:12.473

4Should this be tips for golfing instead? – user202729 – 2018-09-11T15:53:09.913

@user202729 I made this for the nomination which recommends adding a tips question. It doesn't state whether for help or golfing. There aren't many tips for golfing though. – FireCubez – 2018-09-11T15:56:20.587

I think it might be a good idea to open a meta post asking how bytes should be counted for this, particularly in regards to file names. Code-golf is by far the most common type of question on this site, so it's good to have a plan there. In particular, I don't think there are any existing languages that so fundamentally rely on multiple files with specific names, so I doubt the existing rules provide sufficient guidance. – Kamil Drakari – 2018-09-11T16:06:51.733

@KamilDrakari Well, I think file names should count as bytes as well, because the naming of files is an important part of the program. So bytes = bytes of all files added + all file names except the main file. Should I still open a meta post or is it fine if I just "state" it like I just did. – FireCubez – 2018-09-11T16:12:08.853

@KamilDrakari We already have default for that. – user202729 – 2018-09-11T16:18:13.830

1@user202729 I would rather have a meta post to point people to if they ask about the language specifically, or count incorrectly in their own answers, rather than relying on everybody interpreting the defaults the same way. But maybe I'm being paranoid, I agree with the method that FireCubez mentioned so maybe it's sufficiently obvious. – Kamil Drakari – 2018-09-11T16:43:07.373

(note. It's unusual to have tips question on the site which doesn't have a winning criteria. [tips] tag info page says"to make it a better answer to a programming challenge that is on-topic on this site",which implies there should be a winning criteria.//Oddly...read this. You may want to have a consensus whether "tips for golfing" for non-trivial language is on-topic. Note that triviality is subjective, most PPCG users are very smart so they may consider this language trivial. Just look at Malbolge or Three-star programmer...

– user202729 – 2018-09-12T01:05:01.677

1It's a bit sketchy to pretend to not know anything about a language and ask for advice about it, when in fact you created it yourself... – Jo King – 2018-09-12T06:09:15.160

@JoKing I'm just sharing knowledge, there's a button under "Ask a question" that literally says "Answer your own question". It's also for nomination so I kind of needed to make it – FireCubez – 2018-09-12T11:15:10.400

2@FireCubez: It's not sketchy to offer advice, nor is it sketchy to answer your own question. What is sketchy here, is that you wrote the question from the perspective of someone who knows little to nothing about a programming language that you created. – 3D1T0R – 2018-09-12T19:00:57.690

@3D1T0R Feel free to edit the question to make it less sketchy. – FireCubez – 2018-09-12T20:17:12.973

@FireCubez: We're not supposed to make edits that change the OP's intended meaning. If such changes are needed, we're supposed to inform the OP of what's wrong, and they're supposed to [edit] it. – 3D1T0R – 2018-09-12T21:20:59.933

@3D1T0R Well I don't know how to make it any better, I need to make a tips question for the nomination, how else do I do it then asking for help then answering myself? – FireCubez – 2018-09-12T21:57:36.323

@FireCubez: Usually this site's [tag:tips] Qs are for golfing (reducing the size of the source code) in a particular language, not just a general 'how to use x'. If you want to improve this Q in hopes that it will be accepted by the community, I would recommend the title be changed to "Tips for programming in Bit", and then you should state your intention directly. Something along the lines of "Bit is a new programming language that I'm developing at [link]. [Then you should describe how it works.] If you have tips for other users of Bit please post them in the answers section." – 3D1T0R – 2018-09-12T22:23:09.057

Answers

1

ASCII

First off, you should be familiar with ASCII codes, because Bit uses them a lot when dealing with I/O.

Loops

There is no explicit "loop" command, looping must be done with recursion. For example to turn this pseudocode into Bit, we do this:

Pseudocode:

...

loop 3 times:
    ...

rest of program...

Bit:

BIT 0
... $$ Set value to 48
BYTE i $$ make a var called "i" with value 48
IMPORT var $$ Assuming var is "loop.bit"

loop.bit:

IMPORT i $$ referencing that variable from earlier, because you can do that
ADD 1 i i $$ Add i+1 and set the result to i, aka increment
IMPORT var $$ again, assuming it is "loop.bit"

3:

rest of program...
BYTES 0 $$ MANDATORY, this is invalid so it stops the interpreter with an error
$$ we need this to terminate the loop otherwise the interpreter will hang in an infinite loop
$$ (however, a bug in the interpreter makes this not work, use dividing by 0 or BIT 2 instead. Answers that use BYTES 0 are valid but just won't work on the interpreter)

Import flow

Bit uses IMPORTs to control the program flow, this is inferior to GOTOs and if statements and the like, but it encourages intuitive thinking. So always try to make use of the IMPORT statement.

Golfing

The preferred method of counting bytes in BIT with a multiple file scenario is total source bytes + total bytes of file names excluding the main file

FireCubez

Posted 2018-09-11T15:30:07.163

Reputation: 857

As far as I can tell, the loop implementation provided seems to rely on undocumented behavior. Specifically, it looks like it will call IMPORT i with values from 0-3, with the expected result that the ones with i < 3 will do nothing(?) and then the i = 3 iteration will read file 3 and execute it. Either there need to be additional files 0, 1, and 2 that are not provided, or the behavior of IMPORT i when there is no file with the right name is important but not listed in the documentation. – Kamil Drakari – 2018-09-11T15:55:27.763

2@KamilDrakari I'm sorry about that, I forgot to state in the documentation that files that don't exist just silently don't execute – FireCubez – 2018-09-11T15:57:10.720

1There, added it. – FireCubez – 2018-09-11T15:59:41.563