C*

From Esolang
Jump to navigation Jump to search
This is still a work in progress. It may be changed in the future.

C* or Cx, pronounced "C Times", is an extension of the C++ programming language by User:H33T33. It is designed to be much more flexible and easier to read and write with.

It's basically just a Python/C++ hybrid.

Major Changes

Outputting and Semicolons

Outputting and Inputting have been slightly tweaked to be more convenient.

int main(){
    println("Hello, world!")
    print("Goodbye, Earth.")
}

As you can see, outputting has been simplified. It mimics Python's "print" method, the only difference being that it does not automatically move to the next line, which is what "println" is for.

Semicolons are also no longer a requirement as far as representing the end of lines.

Inputting

int main(){
    int var
    input(var)
}

As shown above, variable 'var' is declared with an integer data type. It is then run through an 'input' method, where it will be defined as whatever the user inputs. If the given variable doesn't exist, it will just create a new one by that name. If the variable doesn't exist, it will also inherit the data type of the user's input. The downside to this is that it can be quite janky when deciding the data type and it won't throw an error if the variable doesn't exist. Debugging will be a pain with this one, so be careful.

Variables

int main(){
    var = 0
}

A variable does not require a data type when defined if it is given a value.

Functions, Parameters, and IFs

Typically, in C and C++, every value must be given a predetermined data type. While that is still a requirement in C*, that only applies to variables. Functions don't need to be given a return type as long as they return literally any value at all, in which case it will inherit the value's data type.

func1(){
    return 0
}
func2(){
    return 'a'
}

In the above code, two functions are declared: func1 and func2. func1 returns an integer, so func1 now has an integer return type. Whereas func2 returns a character data type and therefore now has a character return type.

Now that functions base their return type on the value that they return rather than a predetermined type, they aren't

If a function does not return anything, it will throw an error as, obviously, every variable and function still needs a data type. You can still give a function a predetermined return type, the tradeoff is just that you lose flexibility in terms of what you can return.

Because of this, a single function can return multiple different data types. The below is an example of how this would work:

func1(int param){
    if(param<0){
        return 0
    }else if(param>0){
        return 'a'
    }else{
        return "bcd"
    }
}

If a given parameter is less than 0, func1 returns 0 and is then redefined with an integer return type.

If the parameter is more than 0, func1 returns 'a' and is redefined with a character return type.

If neither of the conditions is true, then it returns "bcd" and is redefined as a string/character pointer.