
'Can a Programming Language Implement Time Travel?' (stackoverflow.blog) 89
Stack Overflow's blog reports on a new programming language called Mariposa.
They call it a "toy" programming language, "created as a way to play around with a novel or odd feature, like variable assignment outside of the normal order of execution — more colloquially, time travel." Computer science has long sought to reason about time in electronic systems, thanks to a consistent interest in concurrency and real-time messaging... Mariposa allows you to manipulate the order of execution by assigning an instant to a variable, then setting the context of that instance. Here's a basic example, taken from the Mariposa readme:
x = 1
t = now()
print(x)
at t:
x = 2
According to the normal order of operations, this code should print "1". But because t is assigned to the instance in the second line, any modifications specified within an at t: block are applied immediately, and this code prints "2"...
While Mariposa caught a fair amount of attention recently, it's not the first implementation of time travel in programming. There is a Haskell package appropriately called tardis, which creates two state transformers: one travels forward in time and one backward. As the docs explain, "The most concise way to explain it is this: getPast retrieves the value from the latest sendFuture, while getFuture retrieves the value from the next sendPast." One function's past is another one's future.
The article explores "the history and future of other programming paradigms" applying logic to time, including interval temporal logic systems as well as "modeling, analysis, and verification languages/tools that allow temporal and state modeling without requiring temporal logic understanding."
They call it a "toy" programming language, "created as a way to play around with a novel or odd feature, like variable assignment outside of the normal order of execution — more colloquially, time travel." Computer science has long sought to reason about time in electronic systems, thanks to a consistent interest in concurrency and real-time messaging... Mariposa allows you to manipulate the order of execution by assigning an instant to a variable, then setting the context of that instance. Here's a basic example, taken from the Mariposa readme:
x = 1
t = now()
print(x)
at t:
x = 2
According to the normal order of operations, this code should print "1". But because t is assigned to the instance in the second line, any modifications specified within an at t: block are applied immediately, and this code prints "2"...
While Mariposa caught a fair amount of attention recently, it's not the first implementation of time travel in programming. There is a Haskell package appropriately called tardis, which creates two state transformers: one travels forward in time and one backward. As the docs explain, "The most concise way to explain it is this: getPast retrieves the value from the latest sendFuture, while getFuture retrieves the value from the next sendPast." One function's past is another one's future.
The article explores "the history and future of other programming paradigms" applying logic to time, including interval temporal logic systems as well as "modeling, analysis, and verification languages/tools that allow temporal and state modeling without requiring temporal logic understanding."
This is just a fancy way of bloating memory usage (Score:3)
With multiple tagged instances of a variable. Instead of a clean 64 bit int, now your "int" is a hashtable.
This isn't time travel.
Re: This is just a fancy way of bloating memory us (Score:2)
Any credible news on Chris's whereabouts these days?
Re: This is just a fancy way of bloating memory u (Score:2)
Well I have yet to see proof. But he has been uncharacteristically silent. That is not the Chris way for sure.
Re:This is just a fancy way of bloating memory usa (Score:5, Insightful)
Explain how you think this is actually implemented then if you don't think this is just memory bloat, not actually time travel.
You think they managed to create FTL travel inside your computer to have a light signal travel back and forward in time to get values in memory at different times ?
Of course not. When you say x = 1, it adds x to a hashtable in the default position. When you then say t = now, it creates a timestamp label named t. When you say "as of t, x = 2", all it does is insert 2 in the x hashtable in the t position, using the earlier created label.
Ain't no magic dude, it's computers.
Re: This is just a fancy way of bloating memory us (Score:2)
Well, one approach is for the compiler to handle the "now()" as a sort of sync point keyword. It then reorders the instructions accordingly. Other approaches might include virtual closures, similar to how a single JavaScript async function under the hood looks more like multiple chained functions sharing a closure scope.
Re: (Score:2)
> It then reorders the instructions accordingly.
Which would mean copying instructions in multiple place, sort of like a loop unroll, resulting in a bigger executable and thus still more memory usage.
Re: (Score:2)
No, you'd just run over the code with a preprocessor and untangle it.
Re: (Score:2)
> Explain how you think this is actually implemented then if you don't think this is just memory bloat, not actually time travel.
You can't get something from nothing. Otherwise I could store data in "time" instead of space for free. Putting that aside, the important question is even with the memory bloat are there use cases for this? I wouldn't expect an entire software platform to use this but maybe functions or code blocks where undoing operations make sense?
Re: This is just a fancy way of bloating memory us (Score:2)
To me this seems like one of those really nasty bugs you'd get that causes crashes and security issues.
Re: (Score:2)
To me this seems like one of those really nasty bugs you'd get that causes crashes and security issues.
Welcome to multithreaded environments and libraries that are not thread safe. Pass by reference parameters in this case.
Re: (Score:3)
It basically works by calling a linked list of functions. There are no hash tables involved.
It's pretty simple. The structure can be flattened as an optimisation to get rid of the linked lists. There are no hash tables needed. It's just a way to make code behave unintuitively.
I mean, th
'print' is not thread safe, pass by reference (Score:2)
'at t' blocks a thread until time 't'. 't' is now so the blocking immediately ends, if it ever started at all.
'print' is running in a separate thread. The 'print' thread takes more time to get to the point it reads 'x' than the ''x' thread takes to reassign 'x' to 2. Since the 'print' thread is using an 'x' passed by reference it reads the 2. It 'x' had been passed by value then 'print' would have had a copy of the original '1' rather than
Re: (Score:2)
Re: (Score:2)
There's also a language, forger which one, the implements the "come_from" instructions. (Come_from is the opposite of "goto".)
I doubt that Mariposa will find any major use cases, but it's an example of the "block universe" that programs run in. I.e. everything is supposed to be totally deterministic, so there's nothing really surprising about "time travel" except that it's quite hard to reason about. In a way it's like languages where every variable is immutable, but the variable names can be rebound to
Re: (Score:2)
That's Intercal, the programming language that also gave us gems such as "DO ABSTAIN FROM ABSTAINING". Or maybe "PLEASE DO ABSTAIN FROM ABSTAINING" if you have not been polite enough.
if speed=88MPH then enable unit.fluxcapacitor (Score:2)
if speed=88MPH then enable unit.fluxcapacitor
Seriously? (Score:3)
This should be fun to debug. Are they trying to increase programmer suicides or something?
Re: Seriously? (Score:2)
Just what I was thinking. This sort of paradigm would make BASIC "goto" sphagehetti code seem like something Knuth would be proud of.
Re: (Score:2)
Don't bash on Basic. Besides the nostalgia c64 Basic invokes in me, it was rather okay as a language, not much worse than another procedural language.
But GOTO: c have it and even though I hardly ever use it, it is there and it has its own specific use cases, like exiting a loop and do something specific* for that case that can happen multiple times in that loop. Sure, it's an ugly hack, useful nonetheless, and should never be recommended to use.
* like unlocking mutexes, and "break" might not exit the loop b
Novel or odd feature? (Score:3)
Re: (Score:3)
There are a lot of younger people out there (especially in the blog-o-verse) who have messed around with python for a few years and think that's made them coding experts. When they learn something new, they assume it's novel for everyone.
And what has Python ever given us in return? (Score:2)
Removed the semi colons and curly braces?
Well right! It used to be you couldn't do a code review without confusing the control flow over some curly braces that weren't indented properly.
The libraries?
Right again. I don't know how we ever got anything done without the libraries.
The Legions of inexperienced coders?
Well, everyone know you can drive costs down by hiring coders at low wages. That goes without saying.
Re: (Score:2)
Re: (Score:1)
More like undefined.
Race conditions as a features? (Score:3)
I mean, to each their own, and I’m all for playful languages, but why the coverage on this? They’ve made a class of bugs a first class feature.
Re: Race conditions as a features? (Score:1)
Re: (Score:3)
Fatal error: temporal decoherence: User has never been born. Quit to press any key.
Re: (Score:2)
Go ahead, read that Bible of yours and watch the progression from "God is one of the gods" to "God is the only god" over the course of the text.
The godcides in between were thoroughly hidden, all traces covered.
Re: (Score:2)
Hehe, this dude doesn't know that the Christian god of war was sent to annihilate all those other gods. It's pretty common knowledge... I mean it's right there in the Nag Hammadi texts, like even the 4 horsemen of the apocalypse ride with the heads of all the other fools that had ever claimed godhood hanging from their saddles. ;-P
Re: (Score:1)
Can you show us on the doll where the priest's red flag touches occurred?
Re: (Score:2)
Yes, I believe one such implementation is called 'ntpd' which is short for 'network time protocol daemon'
And you'd be wrong. ntpd doesn't change the time, nor make it run backwards. It only skews it.
Re: (Score:1)
Yes, I believe one such implementation is called 'ntpd' which is short for 'network time protocol daemon'
And you'd be wrong. ntpd doesn't change the time, nor make it run backwards. It only skews it.
Woosh!!!!
INTERCAL? (Score:5, Interesting)
Looks lame (Score:2)
Is this not just a hard to debug method of creating a function for x=2?
Ok... (Score:2)
How is this useful or interesting? This seems both stupid and a waste of time in both developing and "playing" with it.
Re: (Score:1)
Re: (Score:2)
Ok. But that doesn't mean someone should create an inherently terrible programming language. A new programming language isn't needed to accomplish these tasks. I'm not even sure it would necessarily be good at doing any of that.
Re: (Score:2)
But that doesn't mean someone should create an inherently terrible programming language.
I felt a great disturbance in the Force, as if millions of CS graduate students voices cried out in terror and were suddenly silenced.
Re: (Score:2)
You can very easily know that, you record it with a time tag, then look up the record when necessary. Any common language can do that very easily.
Re: (Score:1)
I've seen applications where it was important to be able to know what conditions existed at a particular time in the past ...
In future news: Republicans ban programming language. :-)
Re: (Score:1)
If we can simulate it can we build it, or did the universe already?
Re: (Score:2)
Yes, you could easily make these sorts of mistakes in any other programming language. This seems like someone fiddling around with ancient bugs, but they have so little knowledge of the topic that they think they are new.
Re: (Score:1)
Or, have you considered that you might just be projecting?
the wheel: reinvented? (Score:2)
3dsmax At Time [autodesk.com]
Messing with causality is not "time travel" (Score:2)
In the given context, the right term is "stupid".
Re: (Score:2)
Hey, anything can implement time travel... for sufficiently loose definitions of "time travel".
Re: (Score:2)
Luckily you are the "Futurama quotes" person so it is funnier.
A "sufficient definition of time travel" could be that the language can only affect future variables, i.e. go forward in time. But time is a loop so it can affect variables in previous executions of the ".exe" or whatever.
That must have been in the last season why the characters did that.
function == timeless (Score:3)
Whenever I do imperative programming I'm always conscious of time. Each statement may change state and I'm aware of how that can affect the system. I'm very aware of "time".
When I do functional programming (like Scala) I feel like I'm writing mathematical statements that aren't causing actions but just stating truths. It feels like time doesn't exist.
I know it's just a feeling and under the hood there's still a Von Neumann engine chugging away, but it's a feeling I can't seem to shake.
Re: (Score:2)
Re: function == timeless (Score:2)
Functional programming is just a fancy name for polymorphism-by-value and recursion as a first class construct. It makes a small number of simple algorithms easier to implement at the expense of making all the others a damn site harder.
Paradox (Score:2)
A better alternative (Score:2, Interesting)
I've been working on a language where there is a focus on immutability. In this language, "variable" (actually constants) assignments can come anywhere in the scope. The compiler figures out the dependency graph for each line of code and orders them accordingly.
A better refined, and more useful approach IMO.
Re: (Score:2)
Variables won't, constants aren't.
- Seen somewhere.
It's just limited time travel (Score:2)
Why only inside an at block? Let the compiler search the entire codebase for any possible change to x.
Better yet, let it do a quantum search for past and future changes in the codebase. Now we're talking about real time travel.
And a compiler with a severe case of burnout.
Realtime (Score:2)
Re: At first... (Score:2)
Newsflash: just about anyone who develops professionally has to cope with concurrency in the form of threading. It's a solved problem albeit a hard one to get right without hidden race conditions.
How would one attach the language to a DB? (Score:2)
Not time travel, snapshots (Score:2)
The example in TFS seems more like using snapshots with variable values.
Calling it time travel is just wrong. (Score:2)
Can we ... (Score:2)
Just asynchronous programming... (Score:2)
Not time travel, just bog-standard asynchronous programming. When dealing with async constructs, or even just callbacks, the order instructions appear when printed is not the order of execution. Any competent software engineer ought to grok that.
If you want a brain-bender, look up Intercal's computed COME FROM construct and ponder the fact that someone actually worked out how to implement this elder horror.
Re: (Score:2)
Not time travel, just bog-standard asynchronous programming. When dealing with async constructs, or even just callbacks, the order instructions appear when printed is not the order of execution. Any competent software engineer ought to grok that.
In short it's a thread unsafe call in a thread environment. 'print' running in a separate thread than 'x'. A parameter pass by reference rather than pass by value.
I suppose a thread being able to block itself until print completion would have worked.
Re: (Score:2)
It happens in a single-thread environment too. After the assignment "t = now()" completes, the "at t:" trigger causes control to transfer there and the assignment "x = 2" executes. Control then returns to where it was before the trigger and the print statement outputs the current value of x. One thread, no simultaneous execution, just the trigger code executing when the trigger is satisfied rather than when it's declared.
Re: (Score:2)
SQL Server temporal tables (Score:2)
SQL Server has something like this, called "temporal tables." With these tables, it's possible to query the values of records in that table as they were at a specified time.
I'm not sure what this language does that has a practical use, but maybe there's something I'm missing.
Define "time travel." (Score:2)
No. There's no time travel happening here (Score:2)
If the microprocessor cannot natively do a thing, then no programming language (which is, itself, just a blob of code) can do that thing with that processor.
What we have here is a poorly designed and implemented toy computer language. That's it. Nothing more, and not actually article-worthy.
Re: (Score:1)
Can I program a microprocessor to say "this statement is a lie"?
Re: (Score:2)
> Can I program a microprocessor to say "this statement is a lie"?
Yes, that is a string literal.
I can't think of a single use case for this (Score:2)
other than creating impossible-to-find bugs
Super maintainable... (Score:1)
print(t)
at t:
t = 2
Lucid programming language also made time explicit (Score:2)
Check out the Lucid programming language:
https://en.wikipedia.org/wiki/... [wikipedia.org]
It made the time sequence of each variable explicit. It also treated time as multidimensional, with nested time lines corresponding to nesting levels of loops in a more conventional language. It didn't catch on, but it's a good example to stimulate thinking about alternative views of programming.
There's probably a Perl module that does that... (Score:2)
Just a fancy GOTO (Score:2)
x = 1
goto t;
back:
print(x)
t:
x = 2
goto back;
Time travel? (Score:2)
No, this is just perfectly logical.
I really cant see how anyone would think this is time travel, it just another way of altering the flow of a program. If it were tim travel the I'd expect X to still be set to 1 after 2 was printed, but thats not the case as X was 1 when t was set, but a code block that sets X to 2 is to be extecuted at time t. T being now() makes that code block execute when t is set, which sets X to 2 (totally logical so far) and RETURNS EXECUTION to the line before the block executed a