Loading ...
Sorry, an error occurred while loading the content.

Name clashing in multi-method defninitions

Expand Messages
  • Mike
    I ve always admired the language Dylan, and now that OpenDylan is available I ve been studying it in a bit more depth. Multi-methods are something I d really
    Message 1 of 7 , Oct 11, 2005
    • 0 Attachment
      I've always admired the language Dylan, and now that OpenDylan is
      available I've been studying it in a bit more depth. Multi-methods
      are something I'd really love to use, but with a bit of reading and
      tinkering, found that method name-clashes for generic functions can be
      a big headache. Dylan supports modules and libraries, can this get
      around the name-clashing problems? For example:

      define method do-something(object :: <class-a>)
      end;

      define method do-something(object :: <class-b>, x, y)
      end;

      do-something(my-window);
      do-something(my-button, 10, 20);


      Thanks,
      Mike
    • Chris Double
      ... Yes, in Dylan you can rename functions imported from modules. So you would rename do-something to foo-do-something , and from another module, it s
      Message 2 of 7 , Oct 11, 2005
      • 0 Attachment
        > Dylan supports modules and libraries, can this get
        > around the name-clashing problems?

        Yes, in Dylan you can 'rename' functions imported from modules. So you
        would rename 'do-something' to 'foo-do-something', and from another
        module, it's do-something can remain the same or be renamed to
        something else. If you don't do this you get a compile time error (or
        warning, I forget exactly).

        Chris.
        --
        http://radio.weblogs.com/0102385
      • Mike Austin
        ... I thought so. After a bit of thinking, if you dispatch on the class first, then on the arguments, you can achieve true OO-dispatching along with
        Message 3 of 7 , Oct 11, 2005
        • 0 Attachment
          --- Chris Double <chris.double@...> wrote:

          > > Dylan supports modules and libraries, can this get
          > > around the name-clashing problems?
          >
          > Yes, in Dylan you can 'rename' functions imported
          > from modules. So you
          > would rename 'do-something' to 'foo-do-something',
          > and from another
          > module, it's do-something can remain the same or be
          > renamed to
          > something else. If you don't do this you get a
          > compile time error (or
          > warning, I forget exactly).

          I thought so. After a bit of thinking, if you
          dispatch on the class first, then on the arguments,
          you can achieve true OO-dispatching along with
          multi-methods:

          define method move-to (self :: <window>)
          => (function :: <function>)
          curry (method (self :: <window>, x, y) => ()
          format-out ("window.move-to\n");
          end, self)
          end;

          move-to (window)(10, 20);

          Dylan supports dot-notation for single argument
          functions, which makes the above fit perfectly:

          window.move-to (10, 20);
          person.move-to ("California");

          I know it is an abuse of power, but without that
          dispatching, I don't consider Dylan a true
          OO-language.

          Mike



          __________________________________
          Yahoo! Music Unlimited
          Access over 1 million songs. Try it free.
          http://music.yahoo.com/unlimited/
        • Daniel Ehrenberg
          ... What are you talking about, true OO language? What is it, and why do we care? I don t think dispatch on the first argument makes a language any truer than
          Message 4 of 7 , Oct 11, 2005
          • 0 Attachment
            > > Yes, in Dylan you can 'rename' functions imported
            > > from modules. So you
            > > would rename 'do-something' to 'foo-do-something',
            > > and from another
            > > module, it's do-something can remain the same or be
            > > renamed to
            > > something else. If you don't do this you get a
            > > compile time error (or
            > > warning, I forget exactly).
            >
            > I thought so. After a bit of thinking, if you
            > dispatch on the class first, then on the arguments,
            > you can achieve true OO-dispatching along with
            > multi-methods:
            >
            > define method move-to (self :: <window>)
            > => (function :: <function>)
            > curry (method (self :: <window>, x, y) => ()
            > format-out ("window.move-to\n");
            > end, self)
            > end;
            >
            > move-to (window)(10, 20);
            >
            > Dylan supports dot-notation for single argument
            > functions, which makes the above fit perfectly:
            >
            > window.move-to (10, 20);
            > person.move-to ("California");
            >
            > I know it is an abuse of power, but without that
            > dispatching, I don't consider Dylan a true
            > OO-language.
            >
            > Mike

            What are you talking about, true OO language? What is it, and why do
            we care? I don't think dispatch on the first argument makes a language
            any truer than on all of the arguments.
          • Mike Austin
            ... I m sorry if I m sounding like an oo purist. I m not, I don t even like the term anymore really, and as you suggest, it doesn t mean the same thing to all
            Message 5 of 7 , Oct 11, 2005
            • 0 Attachment
              --- Daniel Ehrenberg <microdan@...> wrote:
              > > > Yes, in Dylan you can 'rename' functions
              > imported
              > > > from modules. So you
              > > > would rename 'do-something' to
              > 'foo-do-something',
              > > > and from another
              > > > module, it's do-something can remain the same or
              > be
              > > > renamed to
              > > > something else. If you don't do this you get a
              > > > compile time error (or
              > > > warning, I forget exactly).
              > >
              > > I thought so. After a bit of thinking, if you
              > > dispatch on the class first, then on the
              > arguments,
              > > you can achieve true OO-dispatching along with
              > > multi-methods:
              > >
              > > define method move-to (self :: <window>)
              > > => (function :: <function>)
              > > curry (method (self :: <window>, x, y) => ()
              > > format-out ("window.move-to\n");
              > > end, self)
              > > end;
              > >
              > > move-to (window)(10, 20);
              > >
              > > Dylan supports dot-notation for single argument
              > > functions, which makes the above fit perfectly:
              > >
              > > window.move-to (10, 20);
              > > person.move-to ("California");
              > >
              > > I know it is an abuse of power, but without that
              > > dispatching, I don't consider Dylan a true
              > > OO-language.
              > >
              > > Mike
              >
              > What are you talking about, true OO language? What
              > is it, and why do
              > we care? I don't think dispatch on the first
              > argument makes a language
              > any truer than on all of the arguments.

              I'm sorry if I'm sounding like an oo purist. I'm not,
              I don't even like the term anymore really, and as you
              suggest, it doesn't mean the same thing to all people
              in the first place.

              But, it does have a meaning. In the simplest sense,
              objects respond to messages. This makes it easy to
              write independent pieces of code and plug them
              together without conflict. If Dylan supported generic
              functions with varying number of arguments, I would
              love it and I wouldn't care if it's called oo or not.
              Without that (or the extra code above), I couldn't
              imagine writing a large application without naming
              conflicts popping up. Sure, you can do some renaming
              when this happens, but that seems like a kludge. The
              object pattern solves this problem.

              Mike



              __________________________________
              Start your day with Yahoo! - Make it your home page!
              http://www.yahoo.com/r/hs
            • Mike Austin
              ... Hey Chris, do you know how to concatinate macro pattern variables? Below, ?class and ?name should be combined into one identifier: define method ?class ##
              Message 6 of 7 , Oct 12, 2005
              • 0 Attachment
                --- Chris Double <chris.double@...> wrote:
                > > Dylan supports modules and libraries, can this get
                > > around the name-clashing problems?
                >
                > Yes, in Dylan you can 'rename' functions imported
                > from modules. So you
                > would rename 'do-something' to 'foo-do-something',
                > and from another
                > module, it's do-something can remain the same or be
                > renamed to
                > something else. If you don't do this you get a
                > compile time error (or
                > warning, I forget exactly).

                Hey Chris, do you know how to concatinate macro
                pattern variables? Below, ?class and ?name should be
                combined into one identifier:

                define method ?class ## ?name
                (self :: ?class, ?parameters) => (?results)

                Dylan is truly a nice language. If OpenDylan is
                stable enough, I just might finally ditch C++.


                Thanks,
                Mike



                __________________________________
                Yahoo! Music Unlimited
                Access over 1 million songs. Try it free.
                http://music.yahoo.com/unlimited/
              • Chris Double
                ... I don t have a running Dylan system where I am to test but if ?class ## ?name doesn t work, how about ?# class ## ?name. The ?# class turns class into
                Message 7 of 7 , Oct 12, 2005
                • 0 Attachment
                  > Hey Chris, do you know how to concatinate macro
                  > pattern variables? Below, ?class and ?name should be
                  > combined into one identifier:

                  I don't have a running Dylan system where I am to test but if ?class
                  ## ?name doesn't work, how about ?#"class" ## ?name. The ?#"class"
                  turns 'class' into a stirng and then this should contatenate with
                  ?name. Or maybe ?class ## "" ## ?name?

                  Chris.
                Your message has been successfully submitted and would be delivered to recipients shortly.