From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Trust me I am a Doctor Newsgroups: gmane.emacs.help Subject: Instrumenting macro calls Date: Tue, 29 Jun 2021 22:05:55 +0200 Message-ID: <87fsx0xuw8.fsf@riseup.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15587"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jun 29 22:46:14 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lyKcX-0003pt-Kz for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 29 Jun 2021 22:46:13 +0200 Original-Received: from localhost ([::1]:60298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lyKcV-0006Ge-IN for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 29 Jun 2021 16:46:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50346) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lyKbu-0006Ch-QT for help-gnu-emacs@gnu.org; Tue, 29 Jun 2021 16:45:34 -0400 Original-Received: from mx1.riseup.net ([198.252.153.129]:36298) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lyKbs-0007iH-EZ for help-gnu-emacs@gnu.org; Tue, 29 Jun 2021 16:45:34 -0400 Original-Received: from fews2.riseup.net (fews2-pn.riseup.net [10.0.1.84]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client CN "*.riseup.net", Issuer "Sectigo RSA Domain Validation Secure Server CA" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 4GDxLy2Jm3zDv6W for ; Tue, 29 Jun 2021 13:45:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1624999530; bh=BXjcvJ2j63ioFZY0tgrZOA16JW+HLWdJDEXY+Ez7WA4=; h=From:To:Subject:Date:From; b=aoM8xsEJxnm8fBUmciz+vUEbx5bXDsWQURsaD05Q/5iZ4TQYN77Rl7utmm6D5l5Qq JUIzQgrJ9mx1XsIOZo4mpEVNe4FyawYbNSifhPEcQPwrjYzDfjCfD9SzW8mnY9MVEh agT/KXWZVgKXmcvto/Dt69wj4KkGFnWOj992fOK0= X-Riseup-User-ID: 2AF943BDE588FC08EF1E0E965F76CB80F75164359A9C31CC94C68D583D5CFF59 Original-Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews2.riseup.net (Postfix) with ESMTPSA id 4GDxLw607Rz21lq for ; Tue, 29 Jun 2021 13:45:28 -0700 (PDT) Received-SPF: pass client-ip=198.252.153.129; envelope-from=pillule@riseup.net; helo=mx1.riseup.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:131348 Archived-At: --=-=-= Content-Type: text/plain Hi, While exploring eieio I found that laconic comment --- snip --- ;; In retrospect, this is a silly function. (defun eieio-instance-tracker-find (key slot list-symbol) "Find KEY as an element of SLOT in the objects in LIST-SYMBOL. Returns the first match." (object-assoc key slot (symbol-value list-symbol))) --- snip --- So I thought I could make my own query for a tracking list of eieio objects. It is a macro that use pcase to destructuring-bind the argument list into a query that may returns matching objects or slots or whatever. --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=moirai-spindle.el Content-Transfer-Encoding: quoted-printable Content-Description: query macro (defmacro moirai-spindle (list slots-spec &rest forms) "Query a LIST of objects. SLOTS-SPEC is a list of specifications for the query. It may accepts : 1. a SLOT name, 2. a PLACE to bind it, 3. a VALUE to check against, the VALUE is delimited by the &val keyword. eg : (moirai-spindle object-list ((place4 slot4 &val value4) (slot3 &val value3) (slot2 place2) slot1) [ forms ] ) If there is a VALUE for a SLOT, it is tested with `eq'. SLOT must be unquoted, VALUE may be an arbitrary form, cases 2, 3, 4 always need to be placed in a sublist. FORMS are arbitrary forms to be evaluated that are part of the query, Thus they must return non-nil for the query to succeed. This macro allows a variable capture on the symbol `~%', It is the object currently processed by the query. Without any FORMS, the macro will collect them as a list to return. With any FORM the last FORM will be collected as a list to return if non-ni= l. You may specify `~%' as the last form to collect again only the objects. Finally the expanded code is inside a block of name nil, So the query may be stopped at any moment by using `cl-return'." (declare (indent 2) (debug (list sexp def-body))) (let ((return-list (gensym)) (return-value (gensym))) `(let (,return-list) (cl-block nil (dolist (~% ,list ,return-list) ;; This prevents errors for missing slots. (condition-case err (with-slots ,(mapcar (lambda (spec) (pcase spec ((pred atom) spec) (`(,slot &val ,_) slot) ((or `(,place ,slot) `(,place ,slot &val ,_)) `(,place ,slot)))) slots-spec) ~% (and ,@(cl-remove-if #'null ;; clean case 1 `,(mapcar (lambda (spec) (pcase spec ((or (pred atom) `(,place ,slot))) (_ `(eq ,(car spec) ,(car (last spec)))))) slots-spec)) ,@(butlast forms) (when-let ((,return-value ,(or (car (last forms)) '~%= ))) (push ,return-value ,return-list)))) (invalid-slot-name nil))))))) --=-=-= Content-Type: text/plain Until now it seems to work ok. The issue I have with it, is instrumenting the macro calls with edebug. Apparently edebug does not understand that the forms are wrapped into (and ... ), and will evaluate each of them even if some returns nil ! Is there a way to instruct edebug from that ? --=-=-=--