-
Notifications
You must be signed in to change notification settings - Fork 1
Temporal Logic in Cosmos
Let's present a rather novel feature of our language-temporal whiles.[1]
We've been thinking about trying the relatively unknown field of temporal logic programming for a while. We weren't sure how or why to do it though.
That's when we noticed it makes for a pretty readable while statement.
init x=1
while(x<6)
next x=1+x
print(x)//1,2,3,4,5
print(x)//6Cosmos is now a temporal logic language.
As a logic language, the statement,
x=x+1is usually a contradiction. If x is 2, we get,
2=2+1This is clearly wrong. Hence, there's to be a catch if we're making a while statement-where the above is common.
Temporal logic is a logic made to talk about time. Of course, this can be done in regular logic aswell. A statement typically happens within a given time. We could say "Aristotle is always a human" with an always_human relation. Temporal logic instead makes a modality- always would become its own operator.
We currently only make use of two operators from temporal logic-next and first (which we renamed to init).
- first: a statement is true in the first moment in time.
- next: a statement will be true in the next moment in time
This actually makes for a good declarative alternative to the procedural while-we were initially going to make something similar to the special operator ! from mercury. It's convenient that the word while in itself implies time.
The statement next x=x+1 states that x will become x+1 in the next moment (which naturally is interpreted to mean the next loop), i.e. its value will be increased by 1. It's implied the result is the final value of x.[2]
[1] The closest analogue is perhaps the language Chronolog, which implements fibonacci as follows. Or perhaps Tempura.
[2] The while statement is implemented with the semantics of our default conditional. As such, the behavior will change depending on whether you're in function or relational mode.