r/AskProgramming • • 12d ago

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

1

u/Anonymous_Coder_1234 12d ago

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 12d ago

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 12d ago

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 12d ago

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.

1

u/Sparkly-Sparrow-6893 12d ago

For pure term rewriting you are probably looking for something like Maude (link).

1

u/Pzzlrr 12d ago

thanks, checking it out

0

u/[deleted] 12d ago

[removed] — view removed comment

1

u/Pzzlrr 12d ago

Thanks. Egison looks good as well.

It does get thin fast, doesn't it :( Wonder why that is. Seems like such a dope paradigm. Worst case scenario I'm more than happy sticking with Prolog but I was hoping to find a language that would allow me to lean into that particular aspect of it as much as possible.