Cosmic

From Esolang
Jump to navigation Jump to search

Cosmic is a symbolic programming language created by User:RainbowDash in 2026, where symbols are defined in immutable ordered countable sets. All operations are defined with numerical math functions based on the index of the symbols.
The operations allowed are : > < >= <= // * + - != == ! ( )
    

Introduction

Symbols can be transferred across sets either via indexical mutation or symbolic transposition. Symbols are located inside of symbol sets, their index in the symbol set is important and the language is 1-indexed.

Making a symbol set

To begin, the most simple operation is creating a symbol set, there are several built in symbol sets which are as follows : ASCII, INTEGERS (Positive only), ALPHABET. There is also the ability to splice them in order to get a segment of the symbols.

DEFINE ANIMALS '. {THE DOG, THE CAT}
DEFINE LOVE '. {LOVES, DOES NOT LOVE}
# Splice the INTEGERS to only get {0,1,2,3,4,5,6,7,8,9}
DEFINE DIGITS '. INTEGERS[1:10]

Creating an operation

Here we will create a more symbolic computation mapping the love between cats and dogs.

DEFINE ANIMALS '. {THE DOG, THE CAT}
DEFINE LOVE '. {LOVES, DOES NOT LOVE}

OPERATION DOESLOVE '. LOVE[(X == Y)+1]
ANIMALS FELIX '. THE CAT # Felix is a variable : part of the animals set, with the value of THE CAT.
ANIMALS PLUTO '. THE DOG
PRINT '. DOESLOVE(THE CAT, THE DOG)

The truth table would become THE CAT, THE CAT : LOVES THE CAT, THE DOG : DOES NOT LOVE THE DOG, THE CAT : DOES NOT LOVE THE DOG, THE DOG : LOVES

This is because X==Y is treated as an integer output of 0 or 1, then + 1 to align with 1 indexing and you get your truth table.

Mathematics OPERATION ADD '. X+Y OPERATION MULT '. X*Y INTEGERS A '. 5 INTEGERS B '. 5 PRINT '. ADD(A,B)

You can also get INDEX(A,ALPHABET) to return the index of a symbol given a set in case that is ever needed.

Transposing and mutation

Transposing

Let's say you have the symbol sets
BITS {0,1}
DIGITS {0,1,2,3,4,5,6,7,8,9}
Then lets say you want to create a program that maps from digits to bits given an math equality.
To do so is as follows:

DEFINE BITS '. {0,1}
DEFINE DIGITS '. INTEGERS[1:10]
DIGITS A '. 5
DIGITS B '. 6
OPERATION EQUALS '. (A == B)+1
DIGITS A '. EQUALS(A,B)
# Now A will be the symbol 0 or 1
# But that is the symbolical representation not the index representation
# So for symbolic cases we use transpose
TRANPOSE A, BITS
# This will throw an error if A is not 0 or 1
# This now makes the variable the part of the bit symbol group
# So any math applied to it will now be working in the field of that symbol

Mutation

We can mutate the indexes in order to line up to where we want them.

DEFINE CATS '. {FELIX,JOHN,WHITNEY,JERRY}
DEFINE DOGS '. {HARVEY,ALEX,DON}
CATS A '. JERRY
DOGS EXAMPLE '. INDEX(A)
PRINT '. EXAMPLE

In this language, any attempts to reach an index outside of a set will just wrap it back around using modulus. So this code will print out "HARVEY" as the index wraps around.

Control Flow

Only labels and conditional gotos exist in Cosmic.
To define a variable as "True" you must state that it is true.
Anything that deviates from this "True" is false.

DEFINE BITS '. {0,1}
DEFINE_TRUE BITS '. 1

BITS LOOP '. 1
:FOREVER
PRINT '. LOOP
GOTO FOREVER IF LOOP

Another way is to do it mathamatically

INTEGERS B '. 5
INTEGERS A '. 1
OPERATION ADD '. X+Y

:LOOP
INTEGERS CONTROL '. ADD(A,B)
PRINT '. CONTROL
GOTO FOREVER IF CONTROL > 50 # This is checking the index not anything symbolic.