all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Friedrich Dominicus <frido@q-software-solutions.com>
Subject: Re: Differences between Elisp and Lisp
Date: 01 May 2003 07:41:54 +0200	[thread overview]
Message-ID: <87y91ri5p9.fsf@fbigm.here> (raw)
In-Reply-To: m3wuhb9r7w.fsf@quimbies.gnus.org

Lars Magne Ingebrigtsen <lmi@gnus.org> writes:

> "Stefan Monnier" <monnier+gnu.emacs.help/news/@flint.cs.yale.edu> writes:
> 
> >>>>>> "Lars" == Lars Magne Ingebrigtsen <lmi@gnus.org> writes:
> >> and dispatching functions based on type would be nice.
> >
> > Never heard that one.  What exactly would you like to see ?
> 
> The Common Lisp `defmethod' thingie.  Which is a part of CLOS, I
> guess, but wouldn't have to be.  But one would need a type system.

> 
> (defmethod do-stuff ((arg string))
>   ... do stuff with a string)
> 
> (defmethod do-stuff ((arg number))
>   ... do stuff with a number)
What you have missed you can have dispatch on multiple parameters
(that does not work with eieio)

(defmethod (do-stuff ((arg-1 string) (arg-2 string) ....



> 
> And then one could just say (do-stuff whatever) here and there.

> 
> This is really just syntactical sugar on the "pattern"
Not fully.

> 
> Perhaps eieio already provides this?
Partly, it just allows the first parameter to be constrained.

Here and example 

;;; eieio-example.el --- Example for defmethod in eieio


(require 'eieio)
(defclass some-num ()
  ((val :accessor val :initarg :val)))


(defclass some-string ()
  ((val :accessor val :initarg :val)))


(defmethod g+ ((val some-num) val-2)
  (+ (val val) val-2))

(defmethod g+ ((val some-string) val-2)
  (concatenate 'string (val val) val-2))


usage:

(g+ (make-instance 'some-num :val 10) 10) -> 20
(g+ (make-instance 'some-string :val "foo") "bar" -> "foobar"

Not that this is a good example, but it shows how that stuff works 


Regards
Friedrich

  reply	other threads:[~2003-05-01  5:41 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.5343.1051607007.21513.help-gnu-emacs@gnu.org>
2003-04-29 10:22 ` Differences between Elisp and Lisp Friedrich Dominicus
2003-04-29 10:27 ` Lars Magne Ingebrigtsen
2003-04-29 10:35   ` David Kastrup
2003-04-29 11:03   ` Oliver Scholz
2003-04-29 12:23     ` Phillip Lord
2003-04-29 14:17       ` Thomas Link
2003-04-29 15:43         ` Kent M Pitman
2003-04-29 15:56           ` Phillip Lord
2003-04-29 16:44             ` Kent M Pitman
2003-04-29 17:16               ` Phillip Lord
2003-04-29 18:41                 ` Kai Großjohann
2003-04-30 12:39                   ` Phillip Lord
2003-04-30 13:12                     ` Kai Großjohann
2003-04-30 18:07                     ` Kevin Rodgers
2003-04-29 18:59             ` Oliver Scholz
2003-04-30 12:43               ` Phillip Lord
2003-04-29 17:01       ` Kai Großjohann
2003-04-30 23:02   ` Stefan Monnier
2003-05-01  5:22     ` Lars Magne Ingebrigtsen
2003-05-01  5:41       ` Friedrich Dominicus [this message]
2003-05-01  5:54         ` Lars Magne Ingebrigtsen
2003-05-01  6:37           ` [OT] " Friedrich Dominicus
     [not found] ` <yoijznm9y5yr.fsf@bilbo.dd.chalmers.se>
2003-04-29 13:45   ` Kent M Pitman
2003-04-29 15:23     ` Nicolas Neuss
2003-04-29 15:28       ` Nicolas Neuss
2003-04-29 14:23   ` Marco Antoniotti
2003-04-29 14:29     ` Phillip Lord
2003-04-29 19:06       ` Oliver Scholz
2003-04-29 16:51 ` Kaz Kylheku
2003-04-29  8:57 Daniel R. Anderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y91ri5p9.fsf@fbigm.here \
    --to=frido@q-software-solutions.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.