Path: news.daimi.aau.dk!olevi From: olevi@daimi.aau.dk (Ole Villumsen) Newsgroups: comp.lang.beta Subject: Re: what is a pattern? Date: 8 Sep 1994 15:41:16 GMT Organization: DAIMI, Computer Science Dept. at Aarhus University Lines: 97 Message-ID: <34nbas$a8d@belfort.daimi.aau.dk> References: <34n5ad$36s@gort.oit.umass.edu> NNTP-Posting-Host: bmw.daimi.aau.dk gzenie@neural.hampshire.edu writes: >i've read the FAQ. beta seems like a _very_ interesting language but >i'm having a hard time understanding what exactly a pattern is. could >somebody who does perhaps explain to me (perhaps with some code >examples). for some reason the explanation in the faq didn't click >properly. I think, in this case the FAQ may be more useful for people who already know some Beta. You should read the book! "Object-Oriented Programming in the BETA Programming Language", by Ole Lehrmann Madsen et al. It's on ACM Press and Addison-Wesley. ISBN is 0-201-62430-3. For starters, think of a pattern as a generic word for both a class and a procedure or function. This is not all there is to it, but it will get you started. In Beta, a pattern is anything starting with (# and ending with #). As a silly example, write a function that multiplies two numbers: multiply: (# a,b: @integer; enter (a,b) exit a*b #); multiply, as defined above, is an example of a pattern; a procedural pattern to be more precise, since it would be used like a procedure or function in other languages. In Beta a call to multiply might look like: (9,13) -> &multiply -> &putInt; (putInt is a procedure that writes the result on the screen.) As another silly example, let's build a stack class, the way any object-oriented person would do it - only simpler :-) (are you familiar with object orientation?): stack: (# content: [100] @integer; currentSize: @integer; push: (# e: @integer; enter e do currentSize+1 -> currentSize; e -> content[currentSize]; #); empty: (# exit (currentSize=0) #); pop: (# e: @integer; do content[currentSize] -> e; currentSize-1 -> currentSize; exit e #); #); Now, stack is a pattern. You may call it a class pattern, since it's meant to be used as a class: to make instances, the actual stacks. Beta has a lot of options for making the example much more elaborate (information hiding, generic stacks, exceptions due to overflow, dynamic expansion of the stack capacity, you name it); but I wanted to keep the example simple. And just in case you were wondering: Yes, the methods defined for stack; push, empty and pop, are also patterns, defined inside the stack pattern. Someone else should be able to explain some of the aspects I've left out. >also, in a previous append (one of the two) there was some simple >benchmarking done. does anybody know if any extensive benchmarking >has been done between moljner beta and other language (common lisp, >smalltalk, c++, etc). I believe Mjolner has measured some execution times; but I'll let them answer for themselves. >finally, is is true that beta doesn't have multiple inheritence? if >this is true and if any of the developers of beta are monitering this >newsgroup, i would be curious what led to that descision. It's a bit of a long story. It's not that bad to define multiple inheritance for *classes* (though I wouldn't want to write the compiler that implements it :-) But since patterns are so much more than classes, defining multiple inheritance for patterns would involve a lot more complications. In some situations, it's really not obvious what multiple inheritance should mean at all. Fortunately, in a lot of cases you will be able to simulate multiple inheritance using part objects. As you may know, often a superclass and a part object can be interchanged. It was explained once in a posting on the usergroup mailing list how to do this, and also how to hide the fact that the multiple inheritance is simulated. I won't go into the details here. Yours, Ole Disclaimer: I am working with some of the people in Mjolner Informatics. I speak only for myself.