Skip to content

Self-aware environments #3

@weswigham

Description

@weswigham

Namely, a function should be aware of its context and be able to modify it.

Firstly, a function should have a method by which it can call itself, anonymous fn or otherwise. (it's certainly more clear if the method is the same)

fn -> 
    puts("Top level")
    (fn (i:Int) ->
         cond | i<10 ->
             puts("Inner level: #%d" % i)
             ^(i+1)
    )(0)

Which would output

Top level
Inner level: 0
Inner level: 1
Inner level: 2
Inner level: 3
Inner level: 4
Inner level: 5
Inner level: 6
Inner level: 7
Inner level: 8
Inner level: 9

Secondly, a function should probably have access to it's :before's and :after's; ie:

fn example ->
    cond | ^.before.length>0 -> 
                puts("Apparently something went before me... NO MORE.")
                ^.before.each -> |k, v|
                    ^.before[k] = nil
            | * -> 
                puts("I am alone in this world, as I should be.")

fn example:before ->
    puts("This happens before the example, bwahahaha")

This is to simply allow for dynamically adding and removing before and after hooks.

It would also be useful to have a function's type signature available to the function, and maybe even a copy of the arguments it was passed.

It would also be nice to extend the syntax (^^^^^'s!) to let a function get these same attributes of its caller (and therefore its caller's caller, and its caller's caller's caller, etc...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions