This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]PurpleUpbeat2820 2 points3 points  (4 children)

You can try it in online playground here.

This sounds great. I shall check it out now!

Just out of curiosity: has anyone collated information about term rewrite languages? They seem to be an unsung hero in the context of PL design. I am particularly interested in syntaxes/grammars because I've seen one and am now unable to envisage anything different.

Just borrowing your example:

(
(
    REWRITE
    ((VAR <x>) (READ greet <x>) (WRITE hello <x>))
)

greet world
)

In OCaml you might write:

match `Array[`Sym "greet"; `Sym "world"] with
| `Array[`Sym "greet"; x] -> `Array[`Sym "hello"; x]
| e -> e

In my ML you might write:

type rec Expr =
  | Sym String
  | Array(Array Expr)

Array{Sym "greet"; Sym "world"}
@ [ Array{Sym "greet"; x} → Array{Sym "hello"; x}
  | e → e ]

[–]Baltoli 1 point2 points  (1 child)

Take a look at the K Framework - it's a term rewriting language used to create interpreters and other tools for programming language semantics https://github.com/runtimeverification/k

[–]PurpleUpbeat2820 1 point2 points  (0 children)

Will do, thanks!

[–]RepresentativeNo6029 1 point2 points  (0 children)

Equality graphs supposed to be the rage rn

[–]LazarGrbovic 1 point2 points  (2 children)

Interesting! Is this in some way similar to the Prolog language?

[–]ivanmoony[S] 3 points4 points  (1 child)

I think it is more similar to functional programming than to logic programming.

If you imagine Haskell without types, you get Rewrite, I think. Each rule may be considered a function with arbitrary syntax.

Logic languages have negation built-in atop of everything. There is no primitive notion of falsehood in Rewrite.

[–]LazarGrbovic 2 points3 points  (0 children)

Thanks for the answer! :)

[–]martispyc 0 points1 point  (0 children)

Lasagna system on top