help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Differences between Elisp and Lisp


From: Friedrich Dominicus
Subject: Re: Differences between Elisp and Lisp
Date: 01 May 2003 07:41:54 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Native Windows TTY Support)

Lars Magne Ingebrigtsen <address@hidden> writes:

> "Stefan Monnier" <monnier+gnu.emacs.help/news/@flint.cs.yale.edu> writes:
> 
> >>>>>> "Lars" == Lars Magne Ingebrigtsen <address@hidden> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]