[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Function as an argument
From: |
Akiko Ogawa - RS/GIS lab |
Subject: |
Re: Function as an argument |
Date: |
Tue, 4 Apr 2000 14:11:12 -0600 (MDT) |
Marcus,
Ok, I changed the -goThroughEggsWith:InObj function as below and it worked!
Thanks.
Two more questions:
1) In my example, assuming that -scientificTest: takes one arguments and
-conventionalTest: takes two arguments (though here it doesn't), is there any
nice way for the -goThroughtEggWith:InObj function to detect how many arguments
a passed function takes so that it can switch between [obj perform: sel with:
egg] and [obj perform: sel with: egg with: somethingElse] in itself?
2) Can a selecter be a function that returns a value, as in M(getSomething),
where, -(int) getSomething?
---- In object: EggCarton -----
// This method takes a method as arguments
- goThroughEggsWith: (SEL) sel InObj: obj {
for (i=0;i<cartonSize;i++) {
id egg = [eggCartonList atOffset: i];
[obj perform: sel with: egg];
}
...
}
---- In object: EggTester ----
- compareEggTestingMethods {
(id <EggCarton>) eggCarton;
// Here passing methods as arguments
[eggCarton goThroughEggsWith: M(scientificTest:) InObj: self ];
[eggCarton goThroughEggsWith: M(conventionalTest:) InObj: self ];
...
}
// Followings are the passed methods.
- scientificTest: (id) egg {
if ([technitian xRay: egg])
boiledEggs++;
...
}
- conventionalTest: (id) egg {
if ([kid spin: egg])
boiledEggs++;
...
}
Thank you.
Akiko
-------------------------------------------
Akiko Ogawa
Forest Resources Department
Utah State University
address@hidden
-------------------------------------------
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.