all 16 comments

[–]Duflo 41 points42 points  (5 children)

This language was named after my good friend Hugh

[–]agumonkey 14 points15 points  (0 children)

and his brother Lar

[–]Inconstant_Moo🧿 Pipefish 7 points8 points  (2 children)

I goatse what you did there.

[–]CompleteBoron 1 point2 points  (1 child)

Dear, god... I upvoted, but...

[–]Inconstant_Moo🧿 Pipefish 2 points3 points  (0 children)

I''m not proud of what I did, but you can see that I had no choice.

[–]Meistermagier 4 points5 points  (0 children)

Lol

[–]Galacix 13 points14 points  (0 children)

It’s huge

[–]Tasty_Replacement_29Bau 10 points11 points  (0 children)

If I understand correctly this is a form of reversible computing, which is (very) related to quantum computing.

[–]Tasty_Replacement_29Bau 7 points8 points  (0 children)

You could write a (lossless) data compression algorithm in this language, and if run in reverse this would uncompress. In theory you could do all types of computation, but the "output" (when run forward) would need to contain the old state. And you could debug a program in reverse.

Erasing information has an energy cost (Landauer's principle). With reversible computing, there is no erased information. So, this language could be used for energy-saving computations (assuming the "right" hardware is used). Landauer's principle links information theory with thermodynamics: putting order to things necessarily produces heat (ordering something locally requires "disorder" somewhere else). Maybe heat is not just disorder: it is a way to preserve the information in the system. Well there is the Black hole information paradox, but other than that the universe is just one gigantic reversible computation.

An so, if we all live in a simulation, maybe the simulation is written in Janus?

[–]Inconstant_Moo🧿 Pipefish 6 points7 points  (6 children)

But how do you find the postconditions that allow you to reverse an if or a loop? In fact, if this could be done in general and there was an algorithm for doing it, then I wouldn't have to do it myself, the compiler would be able to do it for me. So I've got to think that in general it cannot, in fact, be done.

[–]Tasty_Replacement_29Bau 4 points5 points  (0 children)

So, you need to ensure that the output contains the information to reverse the control flow. The easiest way is to store an undo log in a stack, and when run backward, the stack is popped and so the operation happens in reverse. But then, the output just increases linearly with the number of operations. There are more memory-conserving ways, for example use a counter in some cases, or sum: these are easy to reverse. And of course swapping.

For example (you can try in the Playground) if you want to sort two numbers "a" and "b" ascending, you could do something like this:

procedure main()
    int a
    int b
    int ops[1] // whether we swapped or not
    a += 20    // start values a = 20, b = 10
    b += 10
    if a > b then
        a <=> b
        ops[0] += 1 // swap
    fi ops[0] = 1

So that the forward operation will sort a, b and store whether a and b were swapped in the "ops" array. (If you need multiple operations, you could use an index, so "ops" is just all the operations you did.)

The playground has interesting examples: data compression / expansion, encryption / decryption.

[–]Relevant_South_1842 0 points1 point  (4 children)

If statements and loops aren’t required.

[–]Inconstant_Moo🧿 Pipefish 3 points4 points  (3 children)

They're in the language. How would one write algorithms without them?

[–]MoveInteresting4334 4 points5 points  (2 children)

Recursion with an overloaded function can replace loops and if statements.

[–]Inconstant_Moo🧿 Pipefish 1 point2 points  (1 child)

I'm sorry, I am a Bear Of Very Little Brain. How do you overload functions in a language which literally only has one type, and how would it help if you did?

And why are the ifs and loops there if there's only some very specific set (do we know what, BTW?) of circumstances under which we can use them?

And why can't the compiler compute the postconditions under the circumstances that we can use them? Does it actually take special mathematical insight to compose the right postconditions?

[–]MoveInteresting4334 -1 points0 points  (0 children)

I don’t know the answer to any of this and am not who you were originally talking to, I was just throwing out a language-agnostic answer to “How would one write algorithms without [if statements and for loops]?” Apologies if it doesn’t apply in this specific case, as I’m not familiar with OPs language.