From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Cor Legemaat Newsgroups: gmane.lisp.guile.user Subject: Extending primitive to generic functions problem Date: Fri, 09 Oct 2020 20:30:29 +0200 Message-ID: <88f424cfefbce959534eb647b581b9c9a9552114.camel@cor.za.net> Reply-To: cor@cor.za.net Mime-Version: 1.0 Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-GNwGZ8JAvDf09lZCiF6O" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4393"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.36.1 To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Fri Oct 09 20:31:18 2020 Return-path: Envelope-to: guile-user@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 1kQxAk-00010S-CE for guile-user@m.gmane-mx.org; Fri, 09 Oct 2020 20:31:18 +0200 Original-Received: from localhost ([::1]:38174 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQxAj-00084B-AX for guile-user@m.gmane-mx.org; Fri, 09 Oct 2020 14:31:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34746) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQxAA-000843-BK for guile-user@gnu.org; Fri, 09 Oct 2020 14:30:42 -0400 Original-Received: from ns1.u-host.co.za ([178.79.144.62]:33322 helo=P3X556.catdevmem.za.net) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQxA6-0003ej-5O for guile-user@gnu.org; Fri, 09 Oct 2020 14:30:41 -0400 Original-Received: from [102.140.163.6] (port=46448 helo=[10.10.10.4]) by P3X556.catdevmem.za.net with esmtpa (Exim 4.92.3-73-5e73fc002) (envelope-from ) id 1kQxA0-0004Wo-3W for guile-user@gnu.org; Fri, 09 Oct 2020 18:30:33 +0000 X-ACL-Warn: log_message = Final spam score: -1.0 Received-SPF: none client-ip=178.79.144.62; envelope-from=cor@cor.za.net; helo=P3X556.catdevmem.za.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 14:30:33 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, KHOP_HELO_FCRDNS=0.275, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:16968 Archived-At: --=-GNwGZ8JAvDf09lZCiF6O Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi All: I am trying to extend some of the primitive functions with generic methods in a module to use them with custom classes. From 8.6.5 Generic Function and Method Examples in the manual I came up with the following module: (define-module (test ep) #:use-module (oop goops) #:use-module ((rnrs base) #:select (+ - * / map max min sqrt expt abs log) #:prefix rnrs:)) (define-macro (make-primitive-generic source destination arguments) (let ((tmp-symbol (string->symbol (string-append (symbol->string destination) "-new")))) `(begin (define-generic ,tmp-symbol) ,(if (not (defined? destination)) `(define ,destination ,source)) (let ((,destination ,source)) ,(cond ((eq? arguments 1) `(define-method (,tmp-symbol (n )) (,source n))) ((eq? arguments 2) `(define-method (,tmp-symbol (a ) (b )) (,source a b))) (else `(begin (define-method (,tmp-symbol (a ) (b )) (,source a b)) (define-method (,tmp-symbol (a )) a) (define-method (,tmp-symbol) 0) (define-method (,tmp-symbol . args) (,tmp-symbol (car args) (apply ,tmp-symbol (cdr args)))))))) (set! ,destination ,tmp-symbol) (export ,destination)))) (export make-primitive-generic) (make-primitive-generic rnrs:+ sum 0) (make-primitive-generic rnrs:max max 0) (make-primitive-generic rnrs:min min 0) (make-primitive-generic rnrs:* product 0) (make-primitive-generic rnrs:/ divide 0) (make-primitive-generic rnrs:- difference 0) (make-primitive-generic rnrs:sqrt sqrt 1) (make-primitive-generic rnrs:expt expt 2) (make-primitive-generic rnrs:abs abs 1) (make-primitive-generic rnrs:log log 1) Now 2 problems: If I don't hack the primitive with the prefix there is an 'Unbound variable:' error on those where the source and destination is the same. This works but only if compiled, the second time guile uses 100% cpu and never finish loading. Did play with eval-when but it's either not defining the methods or not loading after it's compiled. Where is it going wrong, is this possible or do I mis understand something about how guile works? Thanks in advance Regards: Cor --=-GNwGZ8JAvDf09lZCiF6O Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEXKx8yyH33F04QiAsyumn4DJDAn0FAl+ArEUACgkQyumn4DJD An1eGA//UeUKTw6lA1uY+LRRHJ77X3DRm2cvVltu58rRSqkKwaXSjXvWJJ1orari j1xnIU3I39d6fjo8e3x34MWH2jKFNu7ABtb59Tr1SmU7HsANIuYDwINDJVynoNIN Z5NXCyrVgt49SXoHWZMDobIeBiU2T0AoJHVa7X6IcTp7bmAlvlw9GgZApsLH6fe7 wiIoCXkgM759FYohdMO9fxImDgFBg85IUxoy+rlbEuo3Hkszr4pXo3U8NPogWjTV 7CKUjN/fnBiTr9SFAn2cVFEZ4zaPau/RaxJXkKhsT++3Yj7bVRRPnrNAqTpWykpE icFJtBcj+B8zrTuQkJJCVRNduSWpyZgLySD3EhzCZ+BbedfQEW9j6rixMAAlV0QH SjZlQjE4qrQLx0LglYYXX731b0MsIEopX+3dKpB7eiV2aEHD4PZ8YMqzeJ0+kgxL nDfWAMbcvIUNUtPsU6gtrBe7iNw+DT5cVg2bsr6KEWbnsjolAF1Q37WrPYHGAvQC iA+fWkbVB3WpNBXtEXGrw5nN39U5XpXajB4xW8KfBHwM6cGzdBhwxQaeQvoIwsB+ F8gSsLM6WSAuBihVJkNKprqRJHL79xx0dNDyhdEl/Kov1gnRoOh+XE5LT4y3KYd3 9B0jmm0QLhp/HnaDajg7/j4lXxGOhj+RoxltEv1z7rB92dUI0Xc= =WXhS -----END PGP SIGNATURE----- --=-GNwGZ8JAvDf09lZCiF6O--