[Prev][Next][Index][Thread]

Re: Dylan & MOP



In article <382C43C2.94DBA012@miqs.com>, Scott Ribe <sribe@miqs.com> wrote:

> > Much of what you want to do is available in CLOS. Are you looking to
> > have the Dylan MOP more CLOS like?
> 
> I'm looking to either have it more CLOS like or to be convinved that
> this is not necessary for what I want to do ;-)

I kind of ignored the huge flood of messages a few days ago, so I may be
confused about what you wanted to do...

I think I saw something about that you wanted to be able to write
'myRecord.salary' and have a "no applicable method" handler basically
translate this into something like 'myRecord["salary"]'.

There is, of course, no way to do this in Dylan without having *SOME*
generic function called "salary" already in the program.

My take on it is that if your program is so static that you are in a
position to write 'myTable.salary' in the first place -- i.e. the name of
the field is known to you when you write the code, not obtained from a
data dictionary or something at runtime -- then you can equally afford to
put some minimal declaration of the field in the program as well.  And you
can use macros to help with that declaration, if necessary.

You might write a macro that lets you code like this...

   define dbtable employee (name, salary);

... which expands to this...


   define constant employee = make(<dbtable>, "employee");

   define class <employee-record> (<db-record>)
      slot key :: <something...>
   end

   define method name (record :: <employee-record>)
      get-field(employee, record, "name");
   end

   define method salary (record :: <employee-record>)
      get-field(employee, record, "salary");
   end

   define method name-setter (newVal, record :: <employee-record>)
      set-field(employee, record, "name", newVal);
   end

   define method salary-setter (newVal, record :: <employee-record>)
      set-field(employee, record, "salary", newVal);
   end


You get the idea.  There's a lot of scope for playing with this.  You
could choose to declare the type of each field as well, if you want.  Or
not.

-- Bruce



Follow-Ups: References: