From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailtransmit05.runbox.com (mailtransmit05.runbox.com [IPv6:2a0c:5a00:149::26]) by sourceware.org (Postfix) with ESMTPS id 98329385841A for ; Tue, 30 Aug 2022 18:57:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 98329385841A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=bothner.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=bothner.com Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit05.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1oT6QK-00EeSG-6c for kawa@sourceware.org; Tue, 30 Aug 2022 20:57:20 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=bothner.com ; s=selector1; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:Cc:From: References:To:Subject:MIME-Version:Date:Message-ID; bh=Fv2THvpqWrWFWoAyMyh4rDLii4HdGnOnsQD21vI/674=; b=ob07t8BTeE26d9eRjqzF48aX3u e7HP8cSdUi9D0XFaMvaW/B0d6bcRb+maFXRsPSueNtsg8nPCAq0e61Bi3yky6W1yvlHU9xUUCYPEr tCQxTZ9fYMWOM/xS6tXYQCBEr8DhLHaTVxINu7s9p/keK8LBziVqcbO9mfyep5ARX7CX9aIxQR4kH s9Lq0HqSU5hufWZ8iTe3bEMLuEB3ugoZYwB/TKzM47NnB4xO16Bt/proh0W3uqqoPvYL38N/9Ay23 YSMAi3nKUMtt99DSK/yvil9jXAN3POoU0uhBD0BpbmfnymxKCFrhRCVPKom/MILLC/nS8iG8GLnvk 4fY5P4lg==; Received: from [10.9.9.74] (helo=submission03.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1oT6QE-0003Zq-Lj; Tue, 30 Aug 2022 20:57:14 +0200 Received: by submission03.runbox with esmtpsa [Authenticated ID (524175)] (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) id 1oT6Q8-0001U7-0c; Tue, 30 Aug 2022 20:57:08 +0200 Message-ID: Date: Tue, 30 Aug 2022 11:57:03 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: The Expression problem Content-Language: en-US To: kawa@sourceware.org References: <51486d80-0d3f-aa47-caca-9b23b2618174@bothner.com> From: Per Bothner Cc: daniel szmulewicz In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 8/30/22 11:24, daniel szmulewicz via Kawa wrote: > Thank you for the prompt response. This reference indeed tells me how to > create new classes or extend existing classes. However, I was interested in > a way to add functionality without touching existing code. For example, > make all instances on the java.lang.String class respond to `foo`, as in > (foo "a string") -> "bar". I think of "extending a class" as "creating a new class that extends an existing class". You're asking for something a little different, which I would call "multi-methods". Common Lisp calls them "generic functions" (using "generic" in a different way than Java does). Common Lisp also differs from Java-style classes in that CL "methods" do not "belong" to a class, which allows for more flexibility. Kaws does have some support for "generic functions": https://www.gnu.org/software/kawa/Generic-procedures.html I don't remember if the "Warning" accurately describes the current state of Kawa and method resolution. You can certainly solve "the Expression problem" if you provide the methods to make-procedure in proper order (most-specific to least-specific). I think there is a mechanism to automatically sort by specificity, but I don't remember - it's been a long time. I think Common Lisp generics are problematic if you have a module system (or library system to use R7RS terminology) based on static name resolution. CL generics assume a generic function is global, and as each module is loaded it dynamically adds methods to the generic procedure. This is powerful, but seems contrary to modern module system. I've thought a bit about how best to specify multi-methods in a more disciplined way. It's not an easy problem. -- --Per Bothner per@bothner.com http://per.bothner.com/ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailtransmit05.runbox.com (mailtransmit05.runbox.com [IPv6:2a0c:5a00:149::26]) by sourceware.org (Postfix) with ESMTPS id 98329385841A for ; Tue, 30 Aug 2022 18:57:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 98329385841A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=bothner.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=bothner.com Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit05.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1oT6QK-00EeSG-6c for kawa@sourceware.org; Tue, 30 Aug 2022 20:57:20 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=bothner.com ; s=selector1; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:Cc:From: References:To:Subject:MIME-Version:Date:Message-ID; bh=Fv2THvpqWrWFWoAyMyh4rDLii4HdGnOnsQD21vI/674=; b=ob07t8BTeE26d9eRjqzF48aX3u e7HP8cSdUi9D0XFaMvaW/B0d6bcRb+maFXRsPSueNtsg8nPCAq0e61Bi3yky6W1yvlHU9xUUCYPEr tCQxTZ9fYMWOM/xS6tXYQCBEr8DhLHaTVxINu7s9p/keK8LBziVqcbO9mfyep5ARX7CX9aIxQR4kH s9Lq0HqSU5hufWZ8iTe3bEMLuEB3ugoZYwB/TKzM47NnB4xO16Bt/proh0W3uqqoPvYL38N/9Ay23 YSMAi3nKUMtt99DSK/yvil9jXAN3POoU0uhBD0BpbmfnymxKCFrhRCVPKom/MILLC/nS8iG8GLnvk 4fY5P4lg==; Received: from [10.9.9.74] (helo=submission03.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1oT6QE-0003Zq-Lj; Tue, 30 Aug 2022 20:57:14 +0200 Received: by submission03.runbox with esmtpsa [Authenticated ID (524175)] (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) id 1oT6Q8-0001U7-0c; Tue, 30 Aug 2022 20:57:08 +0200 Message-ID: Date: Tue, 30 Aug 2022 11:57:03 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: The Expression problem Content-Language: en-US To: kawa@sourceware.org References: <51486d80-0d3f-aa47-caca-9b23b2618174@bothner.com> From: Per Bothner In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: kawa@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Kawa mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Aug 2022 18:57:24 -0000 Message-ID: <20220830185703.8HvBkVk2RdR6_YK0TJaEf9F9GUteeAnA_-eSCS0NoOs@z> On 8/30/22 11:24, daniel szmulewicz via Kawa wrote: > Thank you for the prompt response. This reference indeed tells me how to > create new classes or extend existing classes. However, I was interested in > a way to add functionality without touching existing code. For example, > make all instances on the java.lang.String class respond to `foo`, as in > (foo "a string") -> "bar". I think of "extending a class" as "creating a new class that extends an existing class". You're asking for something a little different, which I would call "multi-methods". Common Lisp calls them "generic functions" (using "generic" in a different way than Java does). Common Lisp also differs from Java-style classes in that CL "methods" do not "belong" to a class, which allows for more flexibility. Kaws does have some support for "generic functions": https://www.gnu.org/software/kawa/Generic-procedures.html I don't remember if the "Warning" accurately describes the current state of Kawa and method resolution. You can certainly solve "the Expression problem" if you provide the methods to make-procedure in proper order (most-specific to least-specific). I think there is a mechanism to automatically sort by specificity, but I don't remember - it's been a long time. I think Common Lisp generics are problematic if you have a module system (or library system to use R7RS terminology) based on static name resolution. CL generics assume a generic function is global, and as each module is loaded it dynamically adds methods to the generic procedure. This is powerful, but seems contrary to modern module system. I've thought a bit about how best to specify multi-methods in a more disciplined way. It's not an easy problem. -- --Per Bothner per@bothner.com http://per.bothner.com/