haasn / -g-pl

/g/ programming language
13 stars 2 forks source link

Recursion #15

Open haasn opened 13 years ago

haasn commented 13 years ago

Recursion is currently not possible due to the way the system works - creating a function will not assign any name to that function, and even if we do so later on via >implying, it's not inside the closure at the time of the function's creation. Plus, it doesn't work with anonymous lambda functions.

So to resolve this, I propose a special form of function call, in which you reference “this”. Eg:

>this [parameters];

For example, a factorial function could look like this:

>implying factorial isn't >function(n)
    >is n 0; TIER: 1
    SHIT TIER: >mul n >this >sub n 1;;;
100% accurate
haasn commented 13 years ago

I'm going to add this to the spec for now, can be revised later on if anybody has further input.

One thing I haven't though about how to deal with is mutual recursion / calling a parent function from a child function.