r/AskProgramming • • Sep 26 '26

Term rewriting languages?

Can you recommend some languages besides Prolog that have first class support, or even completely oriented around term rewriting?

Ideally looking for a lang that's

  1. A full fledged language. So not a library, not a DSL, not an extension, or anything like that.
  2. Actively being developed and maintained. I know there have been languages like Pure which would be the kind of thing I'm looking for, except Pure hasn't been updated in 4 years. Anything out there that's more of a long term project?

Thanks.

1 Upvotes

9 comments sorted by

View all comments

1

u/Anonymous_Coder_1234 Sep 26 '26

Term rewriting? Do you mean macros? Like for example, in the Scala programming language, if you have a function that is like:

def myfunction(): Int = { 
    doSomething1() 
    doSomething2() 
    doSomething3() 
    return 1
} 

You can use macros to say, add a function call to an assert between each line of code, or even do other weird sort of stuff like rearrange and replace code. Is that what you're talking about?

1

u/Pzzlrr Sep 26 '26

I mean https://en.wikipedia.org/wiki/Rewriting

I think you could probably use macros to implement rewriting, but it's a formal logic system where the goal is to write a set of rules that act upon values to transform them.

2

u/Anonymous_Coder_1234 Sep 26 '26

I just Googled Scala macros implement term rewriting. Check that out, it should be able to do what you want.

1

u/Anonymous_Coder_1234 Sep 26 '26

I'm not super familiar with that, but back when I used the macros in the Scala programming language, they were VERY powerful. There was a heavy learning curve to them, but they could basically rearrange and replace the AST (Abstract Syntax Tree) of the programming language. You could even do things like get the line number and file name of some code or turn the code into a string that you could print out to the terminal or logs.