Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

Some Programs

Some Programs

Daerax
Journal · · 2 min read
1,121 0
So the language is currently basically just the untyped lambda calculus with floats, strings, booleans, Console Input, abbreviation of lambdas (e.g. function a b vs. fun a. fun b) and +, - , *, / , < , > , == operators. It is a simple language, getting most of its power as a side effect of the effectiveness of higher order functions.

The fact that the language I am implementing it in has tail recursion, pattern matching and garbage collection has made it quite easy to make an almost word for word conversion of the abstract descriptions and rules. I do not think Id have it so easy and move as quickly were that not the case. The F# parser and lexing tools really help, making it almost too easy.

So I wrote some of the first programs in the language:

pi  = rec ( function pi den val one .                  if den < 1000.0 then                             pi (den + 2.0) (val + one * (4.0 / den)) (neg one)                  else			     val );pi 1.0 0.0 1.0 //3.13959265558979

The PI calculator. You will notice however that I stop at 1000. This is because recursion is done via the Y combinator, a function which fixes a function whose definition refers to itself, the implementation of recursion is done not in the VM but using the language itself. As such recursing too high causes a stack overflow. A guessing game:
r = "20";game = rec (function game guess.		if r == guess then		     "Got It"	         else		     game ReadInput)); "Guess the number: ";guess = ReadInput;game guess;


As you can see a number of deficiencies are highlighted here. As this is basically a direct translation of the lambda calculus there is no sequencing available. So I cannot tell the user that they have gotten the guess wrong. There is also no ability to get from strings to floats.

Some targets are to get the full version of these programs working. Some things I wish to add are: types, sequencing, let bindings, while loops and let rec recursion bindings that are more optimized by taking advantage of the host language.

Discussion

Loading comments...