Posted by bpt on 05:15:00 02-18-2002
Write a simple message-passing object system. Entries may be in ANSI Common Lisp, O'Caml, Haskell, Forth, Squeak Smalltalk, Forth, Joy, assembly (NASM or GAS, or the osimplay ``compembler'') Prolog, Self, any Unix shell with a freely available GNU/Linux-compatible implementation, Scheme, ANSI C, Java, or ANSI C++, or possibly other languages upon request. Many extra points for multiple inheritance, non-hierarchicality (like ZetaLisp's Flavors system), high efficiency, and orthogonal persistance. Entries should not rely too much on the implementation language's object system, if any (this is subjective). Good luck!
Posted by KaGez on 12:36:00 02-18-2002
/me is dizzy
erm.... what?!
[addsig]
Posted by sacah on 13:07:00 02-18-2002
what about Batch???
and whats a message-passing object system??
I think it might be a good thing to find out before I start programming
(-;
Posted by fsvara on 13:10:00 02-18-2002
bpt: note most people here aren't studying computer science... (yet?)
Posted by KaGez on 12:47:00 02-19-2002
yes yes, we are lame... just go on and tell us!
[addsig]
Posted by robost86 on 06:33:00 02-21-2002
/me thinks bpt wants to show us all he knows this fancy word
Posted by KaGez on 15:20:00 02-22-2002
oooookkk... but maybe explaining it to use would make some ppls actually participate, since nobody seems to understadnd it :/
[addsig]
Posted by Mintegra on 23:15:00 02-22-2002
I am guessing somewhere along the lines of how Win32 API passes messages?
Posted by dxprog on 03:10:00 02-23-2002
huh?
Posted by KaGez on 11:42:00 02-23-2002
what?
/me can't understand it ...
[addsig]
Posted by seunosewa on 17:22:00 03-31-2002
Just "one" thing I want to know:
What exactly do you mean?
What's the point; why should we do this?
Wouldn't your rating system be too subjective?
What problems will the program solve?
Can you give us a sample of what u've done already?
Just five things I really wanted to know!
[ This Message was edited by: seunosewa on 2002-03-31 17:23 ]
Posted by bpt on 04:25:00 04-05-2002
Quote:
On 2002-03-31 17:22, seunosewa wrote:
Just "one" thing I want to know:
What exactly do you mean?
I mean that the contest is to implement an object system.
Quote:
What's the point; why should we do this?
For the same reason as any other contest. To have fun and gain skill.
Quote:
Wouldn't your rating system be too subjective?
No.
Quote:
What problems will the program solve?
It will solve all the usual problems of an object system, such as defining and instantiating classes, etc.
Quote:
Can you give us a sample of what u've done already?
No. I'm very busy working on NOPE right now. If anyone shows any interest I'll write one. Currently I am only preparing a design for it, not an implementation unless there is some interest.
Quote:
Just five things I really wanted to know!
[ This Message was edited by: seunosewa on 2002-03-31 17:23 ]
Posted by Yjo on 21:56:00 04-06-2002
It seems a pretty vague contest specification.
An object system? how much of one? what would it be expected to do? why use an already-OOP language like plus-plus to write an object system?
Posted by bpt on 08:20:00 05-13-2002
Even though no one else has actually bothered to write an object system, here's an example one in Common Lisp, which is mostly complete but needs some more macrology (i.e. maybe a DEFINE-OBJECT macro to more easily specify slots and methods in one place):
;; Copyright (C) 2002 Brian P Templeton
(defstruct object
(slots (list))
(methods (list)))
(defmethod get-slot ((obj object) slot)
(cdr (assoc slot (object-slots obj))))
(defmethod set-slot ((obj object) slot value)
(push (cons slot value)
(object-slots obj)))
(defsetf get-slot set-slot)
(defmacro define-method (obj (name &rest arglist) &body body)
`(push (cons (quote ,name) (lambda ,(cons 'self arglist) ,@body))
(object-methods ,obj)))
(defun apply-method (method obj args)
(progv
(mapcar #'car (object-slots obj))
(mapcar #'cdr (object-slots obj))
(apply (cdr (assoc method (object-methods obj)))
(cons obj args))))
;; DEFDELIM and DDFN are from _On Lisp_ by Paul Graham
(defmacro defdelim (pair params &body body)
`(ddfn ,(car pair)
,(cadr pair)
#'(lambda ,params ,@body)))
(let ((rpar (get-macro-character #\))))
(defun ddfn (left right fn)
(set-macro-character right rpar)
(set-macro-character left
#'(lambda (stream char)
(declare (ignore char))
(apply fn
(read-delimited-list right stream t)))
t)))
(defdelim (#\[ #\]) (obj method &rest args)
`(apply-method (quote ,method) ,obj ,(cons 'list args)))
(defdelim (#\{ #\}) (obj slot)
`(get-slot ,obj (quote ,slot)))
(defvar *standard-object*
(make-object))
(define-method *standard-object* (clone)
(make-object :slots (copy-seq (object-slots self))
:methods (copy-seq (object-methods self))))
(defun new-object ()
[*standard-object* clone])
#| Example:
;; Dog
(defvar dog (new-object))
(setf {dog name} "Max")
(define-method dog (angry &key at)
(format t "~&Growl!~%")
[self bite at])
(define-method dog (bite what)
(format t "~&The dog bit ~A!~%" {what name}))
;; Owner
(defvar owner (new-object))
(setf {owner name} "Joe")
(define-method owner (say &rest stuff)
(format t "~&Owner: ~A~%" (apply #'format nil stuff)))
(define-method owner (kick thing)
[self say "I kicked ~A." {thing name}]
[thing angry :at self])
for example, [owner kick dog] will print:
Owner: I kicked Max.
Growl!
The dog bit Joe!
|#
It's prototype-based like Self, PMD, Slate (if I recall correctly), and "Who, Me?", so you clone existing objects intead of instantiating classes. (more flexible, especially if it supports delegations as, e.g., PMD does)
Posted by MooKeen on 02:04:00 08-31-2002
Alright, I finally decided to enter this contest. I wrote a rather simple message-passing object system with multiple inheritance in Common Lisp. I kept extending the original code without modifying it much, so it's a bit yucky, and not very efficient. But hey-- it was a learning experience :)
Here it is:
Code:
#|
Cros by [An]drew Kuehn, August 25-29, 2002
``Do what thou wilt shall be the whole of the law'' -- A. Crowley
This is my simple object system. We'll call it Cros, an acronym
for CRockish Object System. It's all my code, except for defdelim
and ddfn which I took from Paul Graham's fine book _On Lisp_, just
to prove that I'm not too arrogant to copy somebody else's good code. :)
I've never written an object system before, or even studied up on them,
so don't take Cros too seriously. Have fun!
|#
(defmacro second-value (&rest values)
`(cadr (multiple-value-list ,@values)))
(defun slot-exists? (slot obj)
(if (second-value (gethash slot obj))
t
nil))
;; Looks for slot in obj, and then in parents, left to right-
;; only one value can be returned
(defun get* (slot obj)
(if (slot-exists? slot obj)
(gethash slot obj)
(loop for parent in (gethash :parents obj)
when (second-value (gethash slot parent))
return (gethash slot parent))))
(defmacro get-slot (obj slot)
`(get* (quote ,slot) ,obj))
(defmacro set-slot ((obj slot) value)
`(setf (gethash (quote ,slot) ,obj) (quote ,value)))
(declaim (special self))
(defmacro pass-message (obj message &rest args)
`(let ((self ,obj))
(apply (get* (quote ,message) ,obj) (quote ,args))))
(defmacro new-object (name (&rest parents))
`(prog1 (setq ,name (make-hash-table :test #'equal))
(setf (gethash :parents ,name) (list ,@parents))))
(defmacro define-method (obj (name &rest args) &body body)
`(setf (gethash (quote ,name) ,obj) (lambda ,args ,@body)))
;; This macro is evil-- only used for debugging purposes
(defmacro define-macro-method (obj (name &rest args) &body body)
`(define-method ,obj (,name ,args) (eval ,@body)))
;; Paul Graham rules! And I don't completely understand readmacs yet
(defmacro defdelim (pair params &body body)
`(ddfn ,(car pair)
,(cadr pair)
#'(lambda ,params ,@body)))
(let ((rpar (get-macro-character #))))
(defun ddfn (left right fn)
(set-macro-character right rpar)
(set-macro-character left
#'(lambda (stream char)
(declare (ignore char))
(apply fn
(read-delimited-list right stream t)))
t)))
;; Read-macros for easier usage
(defdelim (#[ #]) (obj message &rest args)
`(pass-message ,obj ,message ,@args))
(defdelim (#{ #}) (obj slot &optional eval-obj)
`(get-slot ,obj ,slot))
#|
Example:
---------------------------------------------
(new-object dog ())
(set-slot (dog name) "Charles")
(define-method dog (woof &key polite)
(if polite (format t "~&Bowow. My name is ~A.~%" {self name})
(format t "~&Hooooooowl! Woof Woof!~%")))
(new-object cow ())
(set-slot (cow name) "Isabell")
(define-method cow (moo &key polite)
(if polite (format t "~&Moo. My name is ~A.~%" {self name})
(format t "~&MOOOOOOoOOOOOOOOooooOOOOOOO!~%")))
(new-object dogcow (dog cow))
(set-slot (dogcow name) "Zarf")
(define-method dogcow (moof &key polite)
(if polite
(progn [self moo :polite t]
[self woof :polite t])
(progn [self moo]
[self woof])))
---------------------------------------------
CL-USER > [dogcow moof]
MOOOOOOoOOOOOOOOooooOOOOOOO!
Hooooooowl! Woof Woof!
NIL
CL-USER > [dogcow moof :polite t]
Moo. My name is Zarf.
Bowow. My name is Zarf.
NIL
|#
And there you have it!
Added section:
Well, it turns out the messageboard wants to be retarded and magically strip the backslashes out of
#<slash>}, #<slash>{, #<slash>], #<slash>[, and #<slash>). I suggest we get this fixed. In the mean time, it would be a good idea to grab the code from:
http://troy-isi.no-ip.com/~moo/cros.lisp
Oh, and BTW, I tested it on Xanalys LispWorks (Windows), CMUCL (Linux), and CLISP (Linux), and it seems to work on all of them, although CMUCL gives me some warnings. It will /not/ work on pre-ANSI (CLtL1) Common Lisps such as GCL and friends.
Joy to the world,
D. Kuehn
[ This Message was edited by: MooKeen on 2002-08-31 02:59 ]
Posted by KaGez on 02:06:00 08-31-2002
erm... hello?
would you guys please be so kind and upload that stuff somewhere and paste a link?
Thank you for your kind understanding and cooperation!
[addsig]
Posted by sg on 21:56:00 09-07-2002
what's happening ?? object system ... ??
/me confused ....
....
Posted by KaGez on 22:16:00 09-07-2002
ok, you're not the only on who doesn't know what a object system is
[addsig]