Computer Science Canada

Why can't class subprograms be subprogram variables?

Author:  Mackie [ Thu Mar 27, 2008 5:17 pm ]
Post subject:  Why can't class subprograms be subprogram variables?

Turing:
proc foo (run : proc _)
    run
end foo

class bar

    import foo

    proc foobaz
        put "FizzBiz"
    end foobaz

    foo (foobaz)

end bar


Here is a very simple example of my problem, I planned out a whole new version of my file browser around being able to do this, assuming I was able to. But, I can't so is there some way around this, or does anyone have any suggestions for an alternative method?

Author:  Saad [ Thu Mar 27, 2008 5:53 pm ]
Post subject:  Re: Why can't class subprograms be subprogram variables?

Classes are supposed to be blue prints for objects, consequently when you try calling foo (foobaz), it doesn't occur since your calling foo with a foobaz that belongs to an object of that class.

Although it is possible to create a variable for a procedure.

Turing:

proc foo (run : proc _)
    run
end foo

class bar
    import foo
    var bodyFunction : proc _ ()

    %% This call works because we know that it belongs to the instance of bar
    foo (bodyFunction)

end bar


: