Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a function to check if a number is inside a range #40

Open
ukcroupier opened this issue Mar 11, 2021 · 2 comments
Open

Add a function to check if a number is inside a range #40

ukcroupier opened this issue Mar 11, 2021 · 2 comments

Comments

@ukcroupier
Copy link

ukcroupier commented Mar 11, 2021

This isn't really necessary in normal programs but could be helpful for 10 liners. No idea what it would take to do it :)

I often find myself wanting to check a range of numbers (eg. check if a screen character is an enemy or a wall etc.) . The code usualy goes something like:

IF PEEK(S)>10 AND PEEK(S)<15......

It would save a fair bit of space if I could do:

IF PEEK(S)=11 TO 14

Compressed the lines are:

IFP.(S)>10ANDP.(S)<15
IFP.(S)=11TO14

This would save 7 bytes (8 if you could use a sign instead of TO). My current 10 liner uses this 6 times so that could be a saving of 48 characters.

There's probably a very good reason why this isn't possible, but it would be great if it could be done.

@dmsc
Copy link
Owner

dmsc commented Mar 12, 2021

Hi!

I often find myself wanting to check a range of numbers (eg. check if a screen character is an enemy or a wall etc.) . The code usualy goes something like:

IF PEEK(S)>10 AND PEEK(S)<15......

It would save a fair bit of space if I could do:

IF PEEK(S)=11 TO 14

Yes, but I don't like that syntax very much. The simplest is to add a function (don't really like this name either):

IF BOUND(PEEK(S), 11, 14)

What function name do you think would be appropriate? BOUNDED? IN?

Compressed the lines are:

IFP.(S)>10ANDP.(S)<15
IFP.(S)=11TO14

This would save 7 bytes (8 if you could use a sign instead of TO). My current 10 liner uses this 6 times so that could be a saving of 48 characters.

You can compress the above much more:

IFP.S>10A.P.S<15

Remember that operators (AND/OR) also can be abbreviated, and you can omit function parenthesis.

@dmsc dmsc changed the title Check range of numbers Add a function to check if a number is inside a range Mar 12, 2021
@ukcroupier
Copy link
Author

Thx, I missed the note about AND (A.) abbrev. I was going to read about parenthesis, I knew something had happened with them :)

If you use BOUND i'm guessing that abreviates to BO. unless you're gonna swap it with BYTE(B.), and assuming parenthesis can be excluded then it would compress down to:

IFBO.P.S,11,14 (14 char)
IFP.S>10A.P.S<15 (16 char)

So even given my new found compressing skills it's still a 2 char saving. Not earth shattering but a litte bit :)

BOUND seems ok, I like it better than IN, and the only other keyword I can think of atm is RANGE.

Given that it doesn't save as much as I thought it would, and that it doesn't really improve the readbility of standard code, I'd say this was a low priority - I'm sure there's other things the can use your time and bytes better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants