RE: Type Class!
- Posted by tacitus <indorlaw at zdnetonebox.com> Mar 17, 2001
- 382 views
i was interested in types as well - but soon came to the conclusion that they are really just functions disguised in a slightly different syntax. the refman hints at this. mts's post simply confirms my view. to demonstrate, i was writing a library routine for dos that parsed an html file into a file readable by dos. i defined a number of tags as the type line_break, something like this:- type line_break(sequence tag) if equal(tag, "<br>") or equal(tag, "<p>") or equal(tag, "<div>") then return 1 else return 0 end if end type (i could have done better by replacing the if statement with:- return equal(tag, "<br>") or equal(tag, "<p>") or equal(tag, "<div>") ) i could test whether a tag was a line break with:- if line_break(tag) then etc i suddenly realised that the same thing could always be done better with a function. function line_break(sequence tag) -- if statement as above return 1 else return 0 end function then test for line break with: if line_break(tag) then etc note the similarity. my example is more like the traditional view of a type, but mts's examples demonstrate better the relationship with a function. the only difference i can see between a type and a function is that types provide error checking by the interpreter, while with functions you define your own error checking (or have none at all). generally, i would have thought that your own error checking will be more graceful, as the program can run to its conclusion or otherwise on your say-so. i agree there's nothing to be afraid of with types, but also not much to be excited about. cheers tacitus Mike The Spike wrote: > Here's a little trick I fished up just now... > > You like VB huh? > You like it when you can create a property, and set > and get the status of a variable... > Confused? > No problem, Eu can do that too! > > Here it is... > If you didn't know you could do this (people are > afraid of using 'type' nowadays), you'll think how you > could miss this cool feature of Eu's. > > Ok... > What if you'd want a variable, that when assigned a > value, it autmatically processes that data using your > own specifc code? > An example? > Here ya go. > > type type_writer(sequence s) > puts(1,s) > return 1 > end type > > > Now simply say; > > type_writer echo > echo = "Hello World!" > > > What happens? > "Hello World!" is printed to the screen. > Also usefull for doing Memory Dumping. > Keep track of each value assigned to a variable, by > writing them to disk. > > Wouldn't it be cool to do 'classes' in Eu, FOR REAL? > Well, you can! > Like this; > > type class(sequence func) > call_proc(func,func[2]) > return 1 > end type > > Now you can do this!; > > class myclass > myclass = {"MyPuts","Hello World!"} > > After this assignement, > routine 'MyPuts' is called with "Hello World!", thus > writing this string to the screen (assuming that's > what MyPuts does). > > > That ain't all folks... > There *LOADS* of things you can do with types... > Go ahead! > Try it! > Classes, properties, debugging, resource tracking, > ByRef passing (routine_id works on types aswell!!), > etc... > There's no limits, just your own imagination. > > So go ahead! > Types won't bite! > > > Mike The Spike > PS. Don't forget to use 'without type_check' for extra > speed boosts! > > >