JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.43k stars 5.45k forks source link

Adding grammars for reversible computing #37811

Open GiggleLiu opened 3 years ago

GiggleLiu commented 3 years ago

Changes that make reversible programming happier

1. Allow specifying an optimal postcondition at the end of the if and while statements

Before (in NiLang):

if (precondition, postcondition)
    statememts...
else
    statements...
end
while (precondition, postcondition)
    statememts...
end

After:

if precondition
    statememts...
else
    statements...
end [postcondition]
while precondition
    statememts...
end [postcondition]
2. Add a new control flow for compute-copy-uncompute

Before (in NiLang):

@routine begin
    statements1...
end
statements2...
~@routine

After:

compute
    statements1...
copy
    statements2...
end

I find it particularly useful in reversible programming. Which first compute something (statement1s), then copy the result to a new space (statement2s), and finally undo the computing process (~statement1s).

1 is a non-breaking feature, so I wish it can be accepted in the near future. While for 2, we need more discussion.

Reference

https://github.com/GiggleLiu/NiLang.jl

GiggleLiu commented 3 years ago

Note: In the classic reversible programming language Janus, the if and while statements corresponds to

image

and

image

Reference

http://tetsuo.jp/ref/janus.pdf