Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8058959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:30:51+00:00 2026-06-05T09:30:51+00:00

The code below works in common lisp, but in emacs lisp, it complains (error

  • 0

The code below works in common lisp, but in emacs lisp, it complains “(error “Unknown class type orc in method parameters”)”. Why and how can i fix it in emacs lisp? Thanks.

(defun randval (n)
  (1+ (random (max 1 n))))

(defstruct monster (health (randval 10)))

(defstruct (orc (:include monster)) (club-level (randval 8)))

(defmethod monster-show ((m orc))
  (princ "A wicked orc with a level ")
  (princ (orc-club-level m))
  (princ " club"))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:30:53+00:00Added an answer on June 5, 2026 at 9:30 am

    The thing is… defmethod needs it to be a class, not a struct, structs in eLisp are just vectors. Maybe you could come up with your own generic dispatch method, but probably just using classes instead of structs will solve it – classes are implemented in eieio.el, so you may look at the insides of it and see how they do dispatching. Or you could simply have it something like:

    (defun foo (monster)
      (cond
        ((eql (aref monster 0) 'cl-orc-struct) ...) ; this is an orc
        ((eql (aref mosnter 0) 'cl-elf-struct) ...) ; this is an elf
        (t (error "Not a mythological creature"))))
    

    It would really depend on how many classes of creatures are there, probably you could come up with some macro that hides the condition or rather returns the function to call based on the type tag etc.

    Below is a simplified idea for making your own generics, just in case you want to stick with the structs and you don’t require a lot of functionality or are happy to implement it on your own:

    (defvar *struct-dispatch-table* (make-hash-table))
    
    (defun store-stuct-method (tag method definition)
      (let ((sub-hash
         (or (gethash method *struct-dispatch-table*)
             (setf (gethash method *struct-dispatch-table*)
               (make-hash-table)))))
        (setf (gethash tag sub-hash) definition)))
    
    (defun retrieve-struct-method (tag method)
      (gethash tag (gethash method *struct-dispatch-table*)))
    
    (defmacro define-struct-generic (tag name arguments)
      (let ((argvals (cons (caar arguments) (cdr arguments))))
        `(defun ,name ,argvals
           (funcall (retrieve-struct-method ',tag ',name) ,@argvals))))
    
    (defmacro define-struct-method (name arguments &rest body)
      (let* ((tag (cadar arguments))
         (argvals (cons (caar arguments) (cdr arguments)))
         (generic))
        (if (fboundp name) (setq generic name)
          (setq generic 
            `(define-struct-generic 
              ,tag ,name ,arguments)))
        (store-stuct-method 
         tag name 
         `(lambda ,argvals ,@body)) generic))
    
    (define-struct-method test-method ((a b) c d)
      (message "%s, %d" a (+ c d)))
    
    (test-method 'b 2 3)
    "b, 5"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My code below works in Firefox to toggle a border on an image,but does
the code below works fine but it takes an absolute age to run. How
This code below works in all web browsers except IE: <input type="text" name="passwordLogin" value="Password"
The code below works in FF, Safari, Chrome. But IE is giving me issues.
The example code below works as as a server process. But when I add
I have to code below - works great in IE and Opera, but does
I think i have the most common actionscript error.In the code below i have
I have written the below code for LCS. It works for many cases but
This block of code shown below using a php header redirect works locally, but
The code below works great. I have a MySQL database that contains book titles

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.