📜 ⬆️ ⬇️

Katahdin: metaprogramming on the verge of science fiction

Katahdin is an interpreted programming language in which syntax and semantics can be changed during execution . To make the idea clear, I will immediately give an example from the official site . In the example, the operation of obtaining the remainder of division ("%" in C, "mod" in Pascal) is defined.
class ModExpression : Expression {
pattern {
option leftRecursive;
a:Expression "%" b:Expression
}

method Get() {
a = this.a.Get...();
b = this.a.Get...();
return a - (b * (a / b));
}
}


In particular, all constructions of some existing language can be described on Katahdin. As a result, we get an interpreter of this language. Thus, Fortran and Python are already implemented.

With Katahdin, you can easily combine code in multiple languages ​​in one program. And, moreover, you can load modules for working with different languages ​​dynamically. I can not come up with a practical application for such opportunities, but it is definitely worth exploring them. Here is an example.
 
  import "fortran.kat"; 
  import "python.kat"; 

  fortran { 
      SUBROUTINE RANDOM (SEED, RANDX) 

      INTEGER SEED 
      REAL RANDX 

      SEED = 2045 * SEED + 1 
      SEED = SEED - (SEED / 1048576) * 1048576 
      RANDX = REAL (SEED + 1) /1048577.0 
      RETURN 

      END 
  } 

  python { 
      seed = 128 
      randx = 0 

      for n in range (5): 
          Random (seed, randx) 
          print randx 
  } 
 

In general, the language is very interesting, although it is not clear yet how it can be applied in practice. The project, unfortunately, is not developing now, since the only active developer is not able to continue working on the project.

Links


UPD Wikipedia article deleted. It's a shame.
UPD2 Article returned under a different name. Link corrected.

')

Source: https://habr.com/ru/post/70714/


All Articles