Revapp

From Esolang
Jump to navigation Jump to search

revapp is a programing language created by User:Abo-Junghichi. It is based on Lambda calculus and uses call-by-need as it's evaluation strategy.

It's syntax is almost identical with De Bruijn notation, whose application syntax is reversed from that of Lambda expression. For example, a expression "E1 E2" means that caller is E2 and argument for the call is E1. This small change makes it's all operator syntaxes have right associativity only - the other syntax "λx.E(x)" already has right associativity, because "λx.λy.E(x,y)" is same to "λx.(λy.E(x,y))". So syntactic analysis for the language is as simple as programs written with it needs no intermediate representation. And, Greek Lambda (λ) can be used substitution/definition operator "=". In case of "(E1 E2)λx E3(x) E4(x) ..." for example, symbol "x" in the expression E3 and E4 and following expressions behaves as x=(E1 E2). Indeed, this language uses ASCII charactor "=" instead of "λ".

Differ from De Bruijn notation, revapp uses empty expressions/identifiers for some contexts. Bracket pairs containing no terms "()" are treated as identify-function λx.x . Even there are no way to refer identifiers expressed as zero-length string, its abstruct syntax can bind arguments with such identifiers, makes sure these arguments are never referred through these bindings.

Example

("=" followed immediately by delimiter expresses a definition which has no way to be referred.
 So it can be used to place comments in the source code.)=
(Defining the Y-combinator.)=
(=f (=s (s s) f)=s s s)=Y-combinator
(Short alias)=
Y-combinator=fix

(=string =world
 (world string putc string_output_core)=world
 world '\n' putc
)=print
((This language has no special syntaxes for expressing arbitrary immediate values such as numbers and strings.
  Construct them from list structures.
  "[", ",", "]", are also not syntaxes.
  If you forget separating them with delimiter, this language should search a definition named "[1,0,0]".)=
 (([ 1 , 0 , 0 ]) decimal)=max
 zero (=self =count =world
  (count one plus)=count
  (=base ((=div (=mod)=) undef count base divmod) zero equal)=core
  ((5 core)=b
   ((count num2str)
    ([ 'b' , 'u' , 'z' , 'z' ]) b)
   (([ 'f' , 'i' , 'z' , 'z' ])
    ([ 'f' , 'i' , 'z' , 'z' , '\s' , 'b' , 'u' , 'z' , 'z' ])
    b) 3 core)=rst
  ((world rst print) count self)
  world count max big (=) world) fix
) main

Note pre-defined definitions and primitives should vary or can easily be modified between implementations. Only those ASCII charactors "(", ")", "=", space, tab, and new-line are prevented from redefining. The one implemented by me(User:Abo-Junghichi) defines list structures using Scott encoding and defines list constructers as user-defined functions in a pre-loaded Revapp source.

(-- list --)=
(=fornil =forcons fornil)=nil
(=head =tail =fornil =forcons tail head forcons)=cons

(=done done)=[
(=done =head =isend (done head cons) isend)=,
(nil ,)=]

(-- numbers --)=

zero=0
(0 one plus)=1
(1 one plus)=2
(2 one plus)=3
(3 one plus)=4
(4 one plus)=5
(5 one plus)=6
(6 one plus)=7
(7 one plus)=8
(8 one plus)=9
(9 one plus)=10
(=base (=num_list)=
 0 (=self =done =num_list
  (=num (=t)= ((done base mul) num plus) self)
  done num_list) fix
)=numeral
(10 numeral)=decimal

Implementations

revapp-interpreter

Implemented by the author of the language. Tiny interpreter implementation that shows executing the language is possible without intermediate representation. The size of executable-file for linux built without standard library can be under 9000 bytes.