Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

User-defined function parameters

 [1/3] from: semseddinm:bircom at: 23-Jan-2009 14:43


Hi, is it possible to force a function get a parameter which is a user-defined object type? I guess no, but I would like to be sure. (sorry for bad english) Look at example below please, My-Object: [name: "" age: 0] F: func [a [My-Object!]] [...] I know it is possible to check type of "a" in runtime and throw an error if it is not in my-object type. But is there a way to do this as above? Thanks

 [2/3] from: anton:wilddsl:au at: 24-Jan-2009 1:24


Hi =DEemseddin, No, there is no formal way to check for a particular object type in the function specification. You have to do the checking yourself. Regards, Anton. =DEemseddin Moldibi [ Bircom ] wrote:

 [3/3] from: tim-johnsons::web::com at: 23-Jan-2009 11:10


On Friday 23 January 2009, =DEemseddin Moldibi [ Bircom ] wrote:
> Hi, is it possible to force a function get a parameter which is a > user-defined object type? I guess no, but I would like to be sure. > (sorry for bad english) > Look at example below please, > > My-Object: [name: "" age: 0] > F: func [a [My-Object!]] [...]
This is kind of a 'rigged' solution .... but it works for me. In python, rebol, and newlisp, I've adapted a strategy for objects or contexts: a member, always of the same name. In rebol, it might be _class_name_ so a check on the user type might be something like this. either all[ object? foo "some-class-name" = foo/_class_name_ ][do-something][throw-error] or if one is not sure one has followed the convention without fail either all[ object? foo in foo '_class_name "some-class-name" = foo/_class_name_ ][do-something][throw-error] :-)Beware: untested code! HTH tim