From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.help Subject: Re: How to describe something in Lisp? Date: Fri, 06 Feb 2009 12:53:47 -0600 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <86myczqtvo.fsf@lifelogs.com> References: <929ccd880902030623t1ccb3567weecce35deb378f73@mail.gmail.com> <7c63jq3319.fsf@pbourguignon.anevia.com> <87ljslipmt.fsf@galatea.local> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1233949306 32112 80.91.229.12 (6 Feb 2009 19:41:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 6 Feb 2009 19:41:46 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Feb 06 20:43:01 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LVWb8-0006Ny-FJ for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Feb 2009 20:42:46 +0100 Original-Received: from localhost ([127.0.0.1]:48762 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LVWZo-0003n4-Mn for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Feb 2009 14:41:24 -0500 Original-Path: news.stanford.edu!headwall.stanford.edu!newsfeed.news2me.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!news.albasani.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 44 Original-X-Trace: news.albasani.net modjpm5x4EXEtta1rU3vtEV79fF/wONO2sCueXN2C6y3eU+PvDWRb1wGbxjZOkM9r1tOUw4RvMEKfNiSYWuKL8GF3vtz9hZKuPd0Q8HRVjr7lOBiS4MqTlkRZ9noIPH8 Original-X-Complaints-To: abuse@albasani.net Original-NNTP-Posting-Date: Fri, 6 Feb 2009 18:51:59 +0000 (UTC) X-User-ID: ddo1K/xZv6bY6gC6SSHDWdLoPtdXFBRuyfq+5GouXg0= X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6; d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" Cancel-Lock: sha1:0sY44dq4URKdk9gHfJcN/hNAoKo= sha1:wtwXllnnGRQOVmY7WyTPVXU72z8= User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.60 (gnu/linux) X-NNTP-Posting-Host: QXMIe22Pm8Khk8esVN3j6dtPMwQR1kc67mGg7q+bRMo= Original-Xref: news.stanford.edu gnu.emacs.help:166649 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:61960 Archived-At: On Thu, 5 Feb 2009 08:22:27 +0100 Johan Andersson wrote: JA> For the mode I was asking about, regular p-lists are fine. But I'm planning JA> to do another mode. In this mode I will have a general class and one JA> subclass for each programming language, where each subclass defines what JA> should be done in that particular language. After your description I think JA> defclass will work best since there's inheritance involved. You might like this, which I think is really nice because it's self-describing and very clean. I didn't write it :) Ted ;;; from J.V. Toups (defun toups-bang (sym) (intern (format "%s!" sym))) (defun toups-s-cat (sym1 sym2) (intern (format "%s-%s" sym1 sym2))) (defun toups-ques (sym) (intern (format "%s?" sym))) (defmacro defstruquine (name &rest slots) (let* ((n-fields (length slots)) (i 1) (out `(progn (defun ,(toups-bang name) ,slots (list ',(toups-bang name) ,@slots)) (defun ,(toups-ques name) (item) (eq (car item) ',(toups-bang name)))))) (loop for slot in slots do (setf out (append out (list `(defun ,(toups-s-cat name slot) (item) (elt item ,i))))) (setf i (+ i 1))) (append out (list nil)))) ;; Which can be used thusly: ;; (defstruquine person first-name last-name age) ;; (let ((p (person! "Edward" "Olmos" 61))) ;; (person-first-name p) ;; is "Edward" ;; (person-age p) ;; is 62 ;; p) ;; returns (person! "Edward" "Olmos" 61)