Sidex

From Esolang
Jump to: navigation, search

Sidex is an advanced esoteric programming language that is very hard to program in. Sidex is completely based on concurrency (that is, purely concurrent); most other concurrent languages implement concurrency as a side-effect. However, Sidex implements them by default. Sidex stands for SIDe-by-side EXecution. Sidex currently supports concurrency and dependent types.

Sidex walkthrough

# So, you have never programmed before. In this walkthrough I will show you a lot of code.
# Read the description and try to run the given programs independently.

Introduction on concurrent programming

# That means for each line you type,
# e.g:
# A;
# B;
# C;
# These 3 lines will execute at the same time!
# It is kind of cool, right?
# Now let us take a look at a sample program.

Sample program

# Hello, world! program
"Hello, world!" -> std.out

More concurrency

Now it gets harder when you are trying to do multiple things at the way you want it to.

We are involving latches (similar to variables; in Sidex, you have no control of the locking/unlocking of latches; they are unlocked automatically on the start of the thread and locked automatically on the end of the thread.).

Try to print the classical nursery rhyme:

"Jack and Jill went up a hill\n"-> a
"to fetch a pail of water;\n" -> b
"Jack fell down, and broke his crown,\n" -> c
"and Jill came tumbling after.\n" -> d
a -> std.out
b -> std.out
c -> std.out
d -> std.out

It executes the way you want because it can not unlock an unlocked variable, thus blocking parts of the program. The program has to execute the lines sequentially.

Possible output

JtJaaoanc cdkfk  e Jatfinceldhll  l Ja ci dalpomlawe in wl,te  unoamtfmb  dluw ipabn trgaeo  rkah;eai
 flhtlie
sr .c
rown,

Improvements

Clearly this isn't what we want ;).

This program might print the lines in the wrong order as shown above; here is our solution:

"Jack and Jill went up a hill\n"-> a
a -> "to fetch a pail of water;\n" -> b -> value.concat
b -> "Jack fell down, and broke his crown,\n" -> c -> value.concat
c -> "and Jill came tumbling after.\n" -> d -> value.concat
d -> std.out

After an assignment, unlike other languages, the name of the latch remains, but not its value.

Therefore, a concatenation can be used between the variables.

Use std.value to find the value of the variable, and std.name to append all names that has this value.

Expressions

You can use <- to split a line to represent two different threads in one line (and to obfuscate your code); You can also use \ to continue a thread on the next line.

"2 + 2 is" -> a <- a -> + 2 2 -> b -> value.concat
b -> "3 * 4 is" -> c -> value.concat <- c -> * 3 4  -> d -> value.concat
d -> "100 - 1 is" -> e -> value.concat <- e -> - 100 1 -> f -> value.concat
f -> "(33 + 2) / 5 + 11.5 is" -> g -> value.concat <- g -> + / + 33 2 5 11.5 -> h -> value.concat
h -> std.out

Sidex is with the following arithmetic operators:

Operation Symbol Example
Multiplication * * 2 3 == 6
Division / / 14.0 3.0 == 4.666666666666667
Addition + + 1 2 == 3
Subtraction - - 4 3 ==1
Modulo  %  % 14 3 == 2

whoGoesThere.Sidex

"Halt!\nWho goes there? " -> std.out
"You may pass," -> std.inp -> value.concat -> std.out

if.Sidex

0 -> a
a -> 3 -> if.jumpzero

The if.jumpzero indicator stops the current indicated-by-number thread if the first parameter is 0.

There are other threads in the if library: jumppositive, jumpnegative, jumpeven, etc;

it simply checks what type the value is stored in, and then calls that thread (with tail-call optimization).

Don't be too pleased with the "ease" of the syntax.

Extra attention

Does Sidex look like a child's play? If so, you are completely wrong. Sidex has extra limitations that makes programming in it even harder.

Resource starvation

Sidex has a horrible algorithm to handle resource starvation:

Sidex tries its best to execute all processes evenly. It executes all processes in separate virtual execution spaces for 1 step and then checks which process uses the most resources. If only that process uses the most resources, then Sidex stops that process and removes it. However, if there is only one process doing that, it will not be stopped.

This method would work fine, however, take extra care to the process that is essential to the program. If that process uses the most resources, it will be deleted no matter what.

That is why you should always make sure that your main process uses the fewest resources.