Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Can't pass functions within a class....
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Clayton




PostPosted: Thu Dec 14, 2006 4:07 pm   Post subject: Can't pass functions within a class....

hey guys, I'm having trouble. First of all, if you haven't seen my String Class, and the discussion thats been taking place there, I suggest you do as you will then know more thouroughly what I'm trying to do.

Now, In my string class, I have a function to remove punctuation, or spaces, or whatever. Now, because I have multiple checks to do, I figured (with some help from wtd) that I should just pass a function into my main generic function that removes said characters from the main string. However, it appears that you cannot use class subprograms as subprogram variables. So for example, the following is illegal:

code:

class Foo
    export qux
   
    proc bar (f : function x : string)
        put f
    end bar

    fcn wooble : string
        result "hey"
    end wooble

    proc qux
        bar (wooble)
    end qux
end Foo

var baz : ^Foo

new Foo, baz

baz -> qux


I know all I've done here is (in theory) made a really complex way to say "hey", but it illustrates the point. You can't do such a thing, as wooble is a class subprogram, and apparently you can't pass class subprograms, so my question to you is, is it possible to get around this some other way?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Dec 14, 2006 4:15 pm   Post subject: (No subject)

what if you declear that function outside of a class?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Clayton




PostPosted: Thu Dec 14, 2006 4:17 pm   Post subject: (No subject)

Then you can pass it, however, then it's not as portable, and that's not exactly what I want. If it comes to it, I suppose I could take it out and leave it so that you have to pass a function to the generic method that takes care of everything else, but I don't really want to...
ericfourfour




PostPosted: Thu Dec 14, 2006 5:01 pm   Post subject: (No subject)

The only problem with Tony's suggestion is that you cannot use it with units.
Clayton




PostPosted: Fri Dec 15, 2006 9:54 am   Post subject: (No subject)

exactly, and that's what I want to be able to do. Does anybody have any theory why class functions can't be passed anyways?
Tony




PostPosted: Fri Dec 15, 2006 9:58 am   Post subject: (No subject)

could you pass the class itself, and call the function from within?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Clayton




PostPosted: Fri Dec 15, 2006 10:00 am   Post subject: (No subject)

that might work, I don't have time to try right now, but I will when I get the chance
wtd




PostPosted: Fri Dec 15, 2006 10:00 am   Post subject: (No subject)

Because they shouldn't be able to be used this way, given the style of OOP Turing implements.

Functions inside a class carry around an extra "this" or "self" context, and as such are not the same as plain old functions.
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Fri Dec 15, 2006 10:04 am   Post subject: (No subject)

Hmmm, nevermind, that won't work, the function that you pass is still a class subprogram, even when referenced through self. I still don't understand why you can't use class subprograms as parameters, that just seems dumb to me.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: