Interactive language lab

Try out the language!

Cosmos is an indentation-sensitive relational language: familiar expressions and data meet unification, goals, backtracking, and composable relations. Edit a sample below, then run it in the browser.

This workbench runs an experimental JavaScript interpreter for a useful Cosmos subset; it does not yet include the full compiler or SWI-Prolog runtime.

playground.cos
Source5 lines
Syntax accepted15 tokens · 0.1ms
Ready to evaluate

Run the sample or make it your own.

About

A logic language with a practical surface.

Cosmos combines relational programming with concise, readable syntax and targets Prolog as its intermediate runtime. Follow the project for source releases and ongoing language work.

Open the Cosmos project
Canvas

Draw with Space.

Switch between small visual programs, run or pause the loop, and use the source as a starting point for Cosmos graphics.

Space canvas640 × 360
space.canvas(640, 360)
center = {x=320, y=180}

rel draw(t)
  space.clear("#07101f")
  space.circle(center.x, center.y, 34, "#c8f06b")
  space.circle(center.x + cos(t) * 110,
    center.y + sin(t) * 70, 12, "#86e6c6")

space.start(draw)

Interactive preview of the Space-style canvas API. The animation runs locally in this page.

Download

Get Cosmos.

Browse published packages and releases on SourceForge.

View downloads
Learn

Language documentation.

A compact guide to the concepts that make Cosmos different, followed by the executable grammar supported in this browser lab.

01

Relations & goals

rel defines a callable relation. A newline between goals acts like conjunction, while and and or make logical composition explicit.

rel permitted(x)
  known(x) and not blocked(x)
02

Values & unification

= unifies patterns and values. Lists, dictionaries, strings, numbers, and functors can all participate in structured programs.

person = {name="Mira", roles=[reader, maker]}
head = [first | rest]
03

Control & state

if, while, and next provide direct control syntax while preserving a relational core.

i = 0
while i < 3
  print(i)
  next i = i + 1
04

Protocols & objects

Protocols describe the fields and relation modes an object provides. Objects can use a prototype while remaining ordinary tables.

Protocol(Moving,{
  Number x
  rel move(In Number dx, In Number dy)
})
Reference

Browser subset grammar

Search the productions implemented by this page.

01
Production rule

program

program ::= { declaration | statement }