Did you know ... Search Documentation:
Pack cosmos -- docs/comp - Copy.md

Logic programming --

Cosmos could be seen as a modern take on LP.

In fact, it currently compiles to Prolog code (it's a "transpiler" language).

In doing so, it aims to provide syntax sugar and utilities that may not have been there in "classical Prolog" as most know it.

This includes,

  • Modules.
  • Types and better error-checking.
  • Functional programming.
  • Operators such as if and not that work seamlessly. Syntax --

    As a point of comparison,

    rel human(x)
    rel mortal(x)

    See Prolog code below.

    mortal(x) <-

    While we lose the ability to define simple facts like human(socrates) in fact notation, note that complex relations remain mostly the same, i.e. it's possible to use LP-style programming.

    The whitespace syntax is also useful when it comes to introducing more complex operators like if and helps also avoid the dangling-comma problem. This is specially useful in LP as you may want to switch clauses.

    All the while, this addresses common criticisms of the language. For instance, one can decrease the amount of explict variables by nesting them in function notation, i.e. x=double(double(2)).

    Too much ! -- The main complaint has always been that Prolog programmers often have to resort to the ! operator.

Scripting languages

While the syntax is inspired by scripting languages, specifically prototypal ones, some criticisms are also addressed.

  • No such thing as having both a === and == operator.
  • Variables are local by default, not global. The latter means there's no necessity to write local keywords every time. Even a x=2 statement still makes x a local variable.

    Note that we avoid having too many operators as a matter of course. A language, specially a prototypal one, may have var/val/let keywords at the same time. These practically mean the same thing! This is quite overdoing it.


            rel human(x)
            rel mortal(x)

    While inserting functions/relations in a map to create a module or object is a common pattern in such languages, this is often not possible with such clean syntax.

    That is, code outside of a module can be simply inserted as-is into the module or object. It's then possible to switch from an Object to a non-Object style or vice versa.