Backsharp

From Esolang
Jump to navigation Jump to search
A program that counts to 10,000.

Read about: Backshar | Backshar+

Is this page categorized incorrectly? Feel free to fix it!

"I am really out of ideas now. Backsharp is the best I can come up with. Seriously, 'BS#' looks stupid as fuck. What am I doing with my life?" Threesodas (talk) 22:44, 26 April 2021 (UTC)

Sometimes, we strive for pain. I wanted to simulate that. Here's Backsharp (BS#).

Syntax

Unlike Backshar+, Backsharp does not completely use symbols, but is more confusing than Backshar+.

Basics

Backsharp splits characters with spaces, but then covers whitespace with periods. For instance, you would write "Hello world and apple banana" like this:

.h.e.l.l.o.+.w.o.r.l.d.+.a.n.d.+.a.p.p.l.e.+.b.a.n.a.n.a.

Whitespace within whitespace (spaces) is replaced with +s.

Backsharp still uses symbols, but they each mean different things.

Symbol Use Example
@ Console (or output zone) [@]=>.b.a.c.k.s.h.a.r.p.!.
# Variable #[x]=>.6.9.
% String %.h.e.y.+.g.u.y.s...
$ User input #[x]<=.$.
& Function &.m.y.^f.u.n.c.
^ Uppercase (used in strings) %.^w.e.l.c.o.m.e.+.^h.o.m.e.
\\ Comment \\this does action!

IO functionality

Print something to console:

[@]=>.^h.e.l.l.o.+.w.o.r.l.d.

Why?:
Square brackets define the next object to be selected, such as a variable, or in this case, the console.
Then, we use the => operator to tell the object that it should spit something out.
If it were a variable, you'd put [@]=>.[.v.a.r.]. .
Ask for a user's name:

[@]=>.^w.h.a.t.'.s.+.y.o.u.r.+.n.a.m.e.?.
#[.n.a.m.e.]<=.$.
[@]=>.^c.o.o.l.,.+.y.o.u.r.+.n.a.m.e.+.i.s.+.[.n.a.m.e.]...

Notice that if anything in square brackets only has one character, it does not use periods. However, 2+ characters breaks this rule.
Also, this code uses <=, which means it should receive a value, in this case it's the next line from the console.

Variables

Variables can be set like this:

#[.m.y.v.a.r.]=>.v.a.l.u.e.

Print a variable:

[@]=>.[.m.y.v.a.r.].

Set a variable to another variable:

#[x]=>[y]

Add two variables together:

#[z]=>[x].s.u.m.[y]

(See Operators for a full list of math operators).
Unless you're stupid, you won't need to have to define the variable type. Just in case, here's how it's done:
Replace the # with the variable type.

.s.t.r.i.n.g.
.b.o.o.l.
.i.n.t.
.d.o.u.b.l.e.
.b.y.t.e.

Arrays

Create an array like this:

.a.r.r.[.c.a.r.s.]=>.%
 .^t.o.y.o.t.a.
 .^v.o.l.v.o.
 .^f.o.r.d.
%

Equivalent to: string[] cars = { "Toyota", "Volvo", "Ford" };

Functions

This is an example of a function:

&.m.y.f.u.n.c. &.r.e.t.u.r.n.:.v.o.i.d. &.d.e.f.i.n.e.
   #[x]=>.2.0.
   #[y]=>.4.0.
   #[z]=>[y].s.u.b.[x]
   [@]=>.[z].
&.e.n.d.d.e.f.

Every variable is global by default. Imo, protection keywords are kind of useless. Just don't fucking use the variable later on.

If/else & switch statements

Write an if statement like this:

!.w.h.e.n.(.c.o.n.d.i.t.i.o.n.)
    [@]=>.h.e.l.l.o.!.
!.e.l.s.e.(.c.o.n.d.i.t.i.o.n.)
    [@]=>.g.o.o.d.b.y.e.!.
!.e.n.d

Write a switch statement like this:

?.s.w.i.t.c.h.(.e.x.p.r.e.s.s.i.o.n.)
  ?.c.a.s.e.(.c.o.n.d.i.t.i.o.n.)
    [@]=>.p.o.o.p.y.
    ?.b.r.e.a.k.
  ?.e.n.d.
?.e.n.d.

Operators

Math

.s.u.m. : add two things
.s.u.b. : subtract two things
.m.u.l. : times two things
.d.i.v. : divide two things
.m.o.d. : calculate the modulo of something
.s.q.t. : calculate the squareroot of something
.s.q.r. : square something
.c.b.e. : cube something

Conditions

!= : not equal to
== : equal to
>= : greater than
=< : less than
>> : greater than or equal to
<< : less than or equal to

Classes

Define a class like this:

&&.m.y.c.l.a.s.s. :>
  [@]=>.p.r.i.n.t.+.f.r.o.m.+.m.y.c.l.a.s.s.
<:

The main class is always .p.r.o.g.r.a.m., which is needed to run a program.

Miscellaneous

System data

&&.s.y.s.t.e.m. :> .t.i.m.e.=>#[x] <: : get system time in milliseconds since 2000 (do math to calculate extra stuff)
&&.s.y.s.t.e.m. :> .o.s.=>#[y] <: : get system os
&&.s.y.s.t.e.m. :> .b.i.t.t.y.p.e.=>#[z] <: : get system bit type (32/64 bit)
&&.s.y.s.t.e.m. :> .a.p.p.o.p.e.n.[.a.p.p.n.a.m.e.].=>#[a] <: : check if specified app is open (works with files in general)

Example programs

Simple calculator

&&.p.r.o.g.r.a.m. :>
   [@]=>.m.e.t.a.:.c.l.e.a.r. \\this clears the console completely.
   [@]=>.^c.h.o.o.s.e.+.a.n.+.o.p.e.r.a.t.o.r.:.
   [@]=>.^a.d.d.,.+.s.u.b.,.+.m.u.l.t.,.+.d.i.v...
   #[.o.p.e.r.a.t.o.r.]<=.$.
   [@]=>.^i.n.p.u.t.+.n.u.m.b.e.r.+.1...
   #[m]<=.$.
   [@]=>.^i.n.p.u.t.+.n.u.m.b.e.r.+.2...
   #[n]<=.$.
   #[x]=>[m][.o.p.e.r.a.t.o.r.][n]
   [@]=>.^r.e.s.u.l.t.:.+.[.x.].
<:

Output:

Choose an operator:
Add, sub, mult, div.
 input
Input number 1.
 input
Input number 2.
 input
Result: variable

Family

Backshar: Prequel
Backshar+: Prequel