Share your repls and programming experiences

← Back to all posts
Q Language
sugarfi (482)

Q

This is the beta version of the Q language.

What is Q?

Q is a functional-ish esoteric-ish language. It is based around the concept of
streams/queues, hence the name. There are four main types in Q:

  • A blob, which is just a bunch of raw numbers.
  • A queue, which is just a list of any of the other types.
  • A promise, which is a command to push a blob to a queue.
  • A handler, which is a command to execute a certain promise whenever a certain queue changes.

Blobs

Blobs are just raw blobs of numbers. To declare a blob, use the syntax:

[1 2 3]

The brackets are mandatory.

Queues

A queue is just a list of any of the other data types. All programs are simply queues. To
"execute" a queue, the interpreter simply pops items off of it. If the item popped is a promise,
it is resolved. Otherwise, it is pushed again. This keeps going until the queue is empty.

Promises

A promise is like a JS promise: the interpreter "promises" to execute a bit of code, but gives
you no guarantee when (so maybe it's not exactly like a JS promise, whatever). To declare a
promise, use the format:

(queue <- [1 2 3])

A promise currently must be made up of a queue name followed by a <- followed by a blob.
All programs are simply sequences of promises and handlers. If the queue referenced by a promise
does not exist, it is created.

Handlers

Handlers are not really a type - they are declared before runtime. A handler simply sets up
an event handler of sorts, which will trigger whenever a certain queue is pushed to. To
declare a handler, use the syntax:

(queue -> (queue2 <- [1 2 3]))

A handler must be made up of a queue name followed by a -> followed by a promise. Since handlers
are set up before runtime, they can be declared anywhere in the program, even before their
queue is pushed to.

Roadmap

Q is far from finished, and I plan to add quite a few features, including:

  • An stdlib
  • The ability to push promises to a queue
  • Syntatic sugar for strings and numbers
  • More flexible handlers

License and Credits

This code is licensed under GNU GPL v3.0. It was all written by me, sugarfi.

Commentshotnewtop
CodeLongAndPros (594)

Is Q the name of the program or the name of the language? (Star trek reference)

CSharpIsGud (387)

replit needs more stuff like this

theangryepicbanana (1533)

Looks good!
As a side note, you could remove a lot of boilerplate by changing stuff like

class Node
    @name : String
    @arrow : String
    @blob : String | Node
    def initialize(name : String, arrow : String, blob : String | Node)
        @name = name
        @arrow = arrow
        @blob = blob
    end
    def name
        @name
    end
    def arrow
        @arrow
    end
    def blob
        @blob
    end
end

to

class Node
    property name : String
    property arrow : String
    property blob : String | Node
    
    def initialize(@name, @arrow, @blob)
    end
end

by using builtins and stuff :)

theangryepicbanana (1533)

Additionally, you can use modules instead of classes with static properies/methods

sugarfi (482)

@theangryepicbanana i tried using modules, and it didn't work. also, thanks for the tip, i wasn't able to find something like that for crystal!

sugarfi (482)

@theangryepicbanana AlSo pLeAsE UpVoTe i nEeD MoRe cYcLeS

theangryepicbanana (1533)

@sugarfi Re: upvote, nO bEGgInG fOr CyClEs

DynamicSquid (1134)

Now that's a real language!