Git Product home page Git Product logo

cognate's Introduction

The Cognate programming language

Cognate is a small dynamic quasi-concatenative language for functional programming. Cognate aims to express complex programs in a simple and readable way through its unique syntax, which emphasises embedding comments into statements. This makes programs very readable and helps a programmer better express their intentions.

Cognate is readable

Cognate's compiler ignores words beginning with lowercase letters, allowing comments and code to be interwoven. This 'informal syntax' being optional allows Cognate to be verbose where detail is needed and concise where it isn't.

Cognate is efficient

CognaC (the Cognate Compiler) compiles Cognate sources directly into C. This produces very small and rather fast binaries, allowing Cognate to outperform most dynamic languages. This also makes Cognate a candidate for scripting in embedded environments, such as microcontrollers.

Cognate is simple

Cognate has only a handful of syntax elements. This makes the language very consistent and easy to learn. In future this will allow me to elegantly introduce metaprogramming constructs.

Cognate is functional

Cognate is designed for functional programming - but does not require a PhD in discrete mathematics to use. While Cognate is oriented around first-class functions, no restrictions are placed on IO - making debugging and refactoring less headache-inducing.

Cognate is powerful

Cognate is a stack-oriented programming language. This means that all intermediary values reside in a stack data structure. This allows powerful features such as:

  • Multiple return values
  • Point-free functions
  • Operation chaining

Building Cognate

Currently, Cognate will run on Linux and MacOS systems. If you use Windows, then you can install Cognate on the Windows Subsystem for Linux. To build Cognate, you will need make, flex, bison, and a C compiler (currently supported are GCC, Clang, and TCC). After installing these, simply run:

make

If that succeeds, install the compiler with:

make install

This installs cognate to the .local prefix. To install to a different directory:

make PREFIX=/my/prefix/dir install

You should then run the test script to test Cognate's functionality. This should work regardless of operating system.

make test -j

If the tests all pass (they should!), you can then try running some of the included demo programs:

cognac examples/fizzbuzz.cog
./examples/fizzbuzz

Here is an work-in-progress introduction to the language.

cognate's People

Contributors

crabbo-rave avatar dragoncoder047 avatar fennecdjay avatar jake-87 avatar stavromulabeta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

cognate's Issues

Speed of restrict_chars

Due to potentially being called a lot in large programs, the speed of restrict_chars could be extremely important. Is there a reason for the replacement words, here:

	char* with[]	 = {"DASH", "XMARK", "QMARK", "EQ", "LT", "GT", "PLUS", "STAR", "SLASH"};

to be full strings, instead of say, 'D', 'X', 'Q', 'E', 'L', 'G', 'P', 'S', 'H'?
The only thing I can think of is debugging.
If these were to be replaced with single char versions, you'd be able to much more quickly remove them.

Note this will not affect other variables, due to the sanitation process - I can provide examples if needed.

We could always provide two versions, using a flag like DEBUG to enable the slower version.

Build fails in clang 15.x

In the C23 standard, functions without prototypes (int func() instead of int func(void)) are removed. Clang has deprecated the feature all versions of C as a result. When I try to compile the hello world example with cognac, I get the following error log:

hello.c:41:21: error: a block declaration without a prototype is deprecated  [-Werror,-Wstrict-prototypes]
typedef void(^BLOCK)();
                    ^
                     void
hello.c:323:26: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
static void assert_impure();
                         ^
                          void
hello.c:409:26: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
static void debugger_step()
                         ^
                          void
hello.c:605:26: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
static void assert_impure()
                         ^
                          void
hello.c:1971:23: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
static void VAR(debug)()
                      ^
                       void
5 errors generated.

Word synonyms for binary operators

Cognate looks really cool. The one place I think the literate aspect can be improved is with the binary operators, which are hard to read in a sentence as prefix symbols.

Print * 3 by - 7 2;  

If the following looks nice, I will make a pull request to add synonyms like this:

Print Multiply 3 by Subtract 7 from 2;

and so on, + would be Add, Inequal? and Equal? for != and ==, because of the same for While (!= "done" Twin Input)

Documentation for Cognate words??

There isn't any documentation on each builtin word, and so for the ones that take and/or return blocks, the semantics are very confusing. Case in particular. What are the semantics of that, and everything else? Writing it as Forth stack-effect diagrams or just some example code would help.

Actual interpreter for microcontroller?

From the readme:

CognaC (the Cognate Compiler) compiles Cognate sources directly into C. This produces very small and rather fast binaries, allowing Cognate to outperform most dynamic languages. This also makes Cognate a candidate for scripting in embedded environments, such as microcontrollers.

... but microcontrollers can't compile and run C. Is there a "pure interpreter" for a microcontroller somewhere that actually executes the code instead of transpiling it to C? If there isn't, how do I make one out of this code here?

Weird Segfault.

I noticed a weird segfault that appeared in my code. Here is a small reproduction:
This segfaults when ran, yet

Def Push-op as (Let Op; Push Op);
Let Commands be List ("+" "-" "%" "*")
Let Error be False;
List ();
For command in Commands
    Case "+" (Push-op)
    Case "-" (Push-op)
    Case "*" (Push-op)
    else (Set Bad-command; Set Error to True; Prints ("Error: Unknown Command " Bad-command "\n"));
Do If Not Error
    (Set Commands; For command in Commands Print)
    (Print "");
Clear;

This code works,

Def Push-op as (Let Op; Push Op);
Let Commands be List ("+" "-" "%" "*");
Let Error be False;
List ();
For command in Commands
    Case "+" (Push-op)
    Case "-" (Push-op)
    Case "*" (Push-op)
    else (Set Error to True; Put "Error: Unknown Command "; Print);
If Not Error
    (Set Commands; For command in Commands Print)
    (Print "");
Clear;

and the only difference seems to be this code which causes the segfault

else (Set Bad-command; Set Error to True; Prints ("Error: Unknown Command " Bad-command "\n"));

as opposed to this code which works.

else (Set Error to True; Put "Error: Unknown Command "; Print);

Further information: Prints doesn't segfault by itself, based on this reproduction I made that works,

Let Bar be  "Bar"; Prints ("hielo " Bar "\n");

Creating C file for non-existent file

Something that is most likely a bug, is that when you try to compile a nonexistant cognate file, it creates a C file for it, which is both annoying and wrong. Evidence:
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.