pathterminuspages/projects/aboutcontactabout me

Usage

Untyped Lambda Calculus #6 :: 18-03-2019

Contents
 -Untyped Lambda Calculus in JavaScript
 -Parser
 -Semantics
 -Evaluation
 -Testing
 @Usage

Lastly the final language can be found in the github repo. Version notes right here:

  • 1.0 : Only call-by-value. Closures seems to work.

Optimizations

  • Done:
    • None
  • Pending:
    • Closures: In order to avoid mutating closures in sub trees values are cloned when obtained from scope/closure. For programs that use recursion, like Church Numerals, this is quite slow. I might optimize when I have time.

Use the app online

You can use this application online in the tools section here.

Use the app on you webpage

You have created your own super cool webpage and so on ... Copy both lcalc.js and stack.js into some directory of you webpage. Include them or copy the code. Remember that stack.js is used by lcalc.js - that is insert the former first. Now say the program you want to evaluate is placed in prg.innerHTML. First define a printing function like this

var printfn = function(ptype,line){ switch(ptype){ case "error": out.innerHTML += "<font color='red'>"+line+"</font>"; break; case "env": out.innerHTML += "ρ"+line; break; case "res": out.innerHTML += line; break; case "tnode": out.innerHTML += line; break; default: out.innerHTML += line; break; } out.innerHTML += "\n"; };

Where out is some HTML element like a span or something. Now create a new instance and evaluate as thus:

var llang = new LambdaLang(printfn); llang.exec(prg.innerHTML);

The idea of using the printfn as callback is to be able to format on the output, ex. coloring errors red and so on.

Along with pulling the repo comes the file lcalc.html - this contains a full version of the above you can play around with.

Compressing

You can compress the .js files using some compressor. If you care about the size, you can erase the error message strings found in the actionTable near line 182. Just replace them with empty strings.

CommentsGuest Name:Comment: