DEV Community

Cover image for Functional, Verbose, Sensical: A Programming Language Proposal
megazear7
megazear7

Posted on

Functional, Verbose, Sensical: A Programming Language Proposal

A while back I wrote up some quick thoughts on what a programming language would look like if it's identifiers could contain spaces. In my example program I also had the colon used for setting spaces and the single equals sign used for comparisons. The other day I had some ideas for a purely functional version of some of these same concepts.

Here are the features of the as of yet non existent programming language:
The only objects are modules, globals, functions and parameters.

  1. No variables. This is a purely functional language.
  2. Every global and parameter is a stream and so can have 0, 1, or more values.
  3. Modules define, import, and export globals and functions.
  4. Each module can have a single entry function which is the function that is run when the module is run.
  5. Identifiers can contain spaces
  6. Setting globals and parameter defaults uses a colon
  7. Conditional equality expressions uses a single '='.
  8. If statements are streamlined as shown below for easy conditional handling.
  9. Each function can only contain a single expression making this language purely functional
  10. Error handling is done using the if statement.
  11. You can use values that might not exist and then handle the error cases further down the if statement.

Below is what a programming language with these features might look like. As this programming language does not exist I could not add syntax highlighting. However I posted this same example code on my blog and was able to manually add in syntax highlighting there.

module age groups {
  import print from command line output;
  import error from command line output;

  max baby age: 2;
  max kid age: 12;
  max teenager age: 17;

  function tell the user they are a baby {
    print('You are a baby')
  }

  function tell the user that they are a kid {
    print('You are a kid')
  }

  function tell the user that they are a teenager {
    print('You are a teenager')
  }

  function tell the user that they are an adult {
    print('You are an adult')
  }

  export function tell the user what age group they are in (age) {
    ? age <= max baby age :
      tell the user they are a baby
    ? age < max kid age :
      tell the user that they are a kid
    ? age < max teenager age :
      tell the user that they are a teenager
    ? has one value(max teenager age) :
      tell the user that they are an adult
    ? has multiple values(max teenager age) :
      error('Please provide only one age')
    ? no values(max teenager age) :
      error('No age was provided')
    : // this would be the else case, but based upon the above statements it should never be reached.
  }
}

module my program {
  import tell the user what age group they are in from age groups;
  import the users age from command line arguments;

  entry function run the program {
    tell the user what age group they are in(the users age)
  }
}
Enter fullscreen mode Exit fullscreen mode

Check out my blog for more of my musings upon technology and various other topics.

Top comments (3)

Collapse
 
itr13 profile image
Mikael Klages

What would happen if somebody tried to name a variable "the users age from command line arguments"?

Interesting ideas, but personally I find it harder to read the code if I don't know if a space is part of the variable or meant to split tokens just by looking at it (though maybe syntax highlighting makes this easier?).

I like the switch-like-syntax for the if statements.

Collapse
 
megazear7 profile image
megazear7

"from" would be a reserved word and so couldn't be used in an identifier. However it is a good point as it is a common word and would be limiting. Maybe using a symbol such as "<-" for the same purpose?

the users age <- command line arguments

However that kind of harms the original intent of making the code read like sentences. The manual syntax highlighting that i did here helped. The fact that as programmers we read code better when identifiers have no spaces is a bit of an artifact of age old decisions that have become almost universal. It's probably best to stay the course as far as identifiers go just because of the uniqueness cost to breaking that trend, however I thought it would be interesting to see what it would like.

Collapse
 
itr13 profile image
Mikael Klages

Hmm, but even without the bias I think it would be harder to separate variables from reserved words like this, but who knows.

I think fortran ignores all whitespace, so maybe it's possibel to find wisdom in what fortran developers have said. Though that would have other potential readability issues since "GO TO" would equal "GOTO" and so on.