From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vk1-xa31.google.com (mail-vk1-xa31.google.com [IPv6:2607:f8b0:4864:20::a31]) by sourceware.org (Postfix) with ESMTPS id 016C43858D32 for ; Thu, 1 Dec 2022 11:19:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 016C43858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-vk1-xa31.google.com with SMTP id bi15so662365vkb.11 for ; Thu, 01 Dec 2022 03:19:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=h/irZaw1fuTF1fGXGu/FHD7F19JNRVRdoVjKggt4vyo=; b=MIm20BrYzKrS+qn/BYJJeEVzmFXLFqcualMymIIzzeiVnCM8oJXAgYjGFRNNjZWs0X A2ZlA4I81Z8i0jekG3HDbxQAyfsbbGfAwk5f4Rz56PlOlFL9TdxRDIUmoOo/NMkknxMr gCqQgH1s4USbK0h3Wxdn+IG7kOyQJyqXLcE4ADQHRmplr6o3RNSkWK/70Ax61L8dHBPH R9ClLvVXEL2xqRIx581su2a7MYQztD2na3XF7uJJtVdb97OyjUc8hfRj3gfZ0k72mVgD T1p11hE3YSJtBlaRYx9xXAH1zjaUitvuimdYKbyLA0QlMYjcLLZMOIGAsdsEtsriQFVd blkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=h/irZaw1fuTF1fGXGu/FHD7F19JNRVRdoVjKggt4vyo=; b=cqmsEXqfylSrKLux5c8l/fZaKryPIA8y2644XeYslocpkVmrGEQOLTpz1NzvkEz1nC FOYyTcKMfBUngZjB9FKW0PHiYDwWFIEQ0gne5XgwBZAHMA2fsv8/cW5JAXl98lg07Ib1 4r3kPsw0uZ8RUIrGY8Q7CTuMrT9wI80oU+2Q6M1EhiHJKnANRu16c5JGyoWpHxpbYLUP 30+KrsVi42oRe8ueGAOHWEykgmnQj+2ljSmFUaijytd9luv7moRgmHCwDKqxySLj6u84 ij0j2yAEFwv4V0hZB6/0on3sr3tbP/TXbFTJxLpMZ3FFPHtOc2yVCoiLxq2XE2eD/nhr bObg== X-Gm-Message-State: ANoB5plCpatD1Oo1hbqCNEUnS5SP1wLLkJa5X0GGQRHR5rHJnS4ipKAm 6axJ5vbAcWH5cbXccN7xrrHRalUGs19Np/30Pd9aragTJt8itA== X-Google-Smtp-Source: AA0mqf6TCNtzFsPewA+qNjkzKGeTrL9r/sxAFIsJDQLJaq2PhEaYueVC7/MJWK3JLR8hitP29fxXJF92QOhUoFP1YW4= X-Received: by 2002:a1f:c645:0:b0:3b8:685e:22eb with SMTP id w66-20020a1fc645000000b003b8685e22ebmr27958920vkf.33.1669893568059; Thu, 01 Dec 2022 03:19:28 -0800 (PST) MIME-Version: 1.0 From: Panicz Maciej Godek Date: Thu, 1 Dec 2022 12:19:15 +0100 Message-ID: Subject: Having Named Parts To: kawa@sourceware.org Content-Type: multipart/alternative; boundary="000000000000efdeaa05eec264f9" X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP 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: --000000000000efdeaa05eec264f9 Content-Type: text/plain; charset="UTF-8" Hi, I've been trying to build a simple wrapper for a hash table, that I call Bundle, such that (Bundle x: 5 y: 10) would return a bundle object, let's call it b, so that I could refer to its fields using b:x and modify them using (set! b:x new-value) And such that it would print itself as (Bundle x: 5 y: 10) and be equal to every other object with the same keys and values. I have found that Kawa offers a gnu.mapping.HasNamedParts interface which facilitates value reference, so that if I define the following class, it lets me refer to the contents of a hash map: (define-simple-class Bundle (gnu.mapping.HasNamedParts) (table ::java.util.Map (java.util.HashMap)) ((get key::String) (table:get key)) ((isConstant key::String)::boolean #f) ((*init*) ;for test purposes (table:put ("x":toString) 5))) (define b ::Bundle (Bundle)) #|kawa|# b:x 5 However, when I invoke (set! b:x 5) Kawa responds with the following error: java.lang.RuntimeException: no such field x in Bundle at gnu.kawa.reflect.SlotSet.apply(SlotSet.java:115) at gnu.kawa.reflect.SlotSet.setField(SlotSet.java:25) at gnu.kawa.functions.SetNamedPart.apply3(SetNamedPart.java:52) at gnu.mapping.Procedure3.applyToObject(Procedure3.java:61) at gnu.mapping.Procedure.applyToConsumerDefault(Procedure.java:75) at gnu.mapping.CallContext.runUntilDone(CallContext.java:586) at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:343) at kawa.Shell.run(Shell.java:300) at kawa.Shell.run(Shell.java:183) at kawa.repl.processArgs(repl.java:724) at kawa.repl.main(repl.java:830) I also saw that there is the gnu.mapping.HasSetter interface, but the getSetter method seems not to be invoked in that context. The source code for the gnu.kawa.functions.SetNamedPart.apply3 method reveals, that there was a plan for supporting this -- the method begins with a commented-out fragment: /* if (container implements HasNamedParts) return ((HasNamedParts) container).getNamedPart(part); */ which wouldn't work with current Kawa, because the HasNamedParts interface doesn't containt getNamedPart method, and instead it contains a method called get. I think that this could be fixed by: - adding a method Object set(String key, Object value) to the HasNamedParts interface - uncommenting and fixing the above snippet to invoke the above method. By the way, the interface also contains isConstant method, which doesn't seem to be documented anywhere. I think that also - for consistency - the interface should also provide a boolean hasPartNamed(String name) method. But this only solves one problem, and there's another one, namely - when I try to initialize Bundle as, say (Bundle x: 5 y: 10) I get the following warnings: /dev/tty:6:20: warning - no field or setter 'x' in class Bundle /dev/tty:6:20: warning - no field or setter 'y' in class Bundle These are issued from the build() method in gnu.kawa.reflect.CompileBuildObject. It does seem that this class doesn't take into account the existence of the HasNamedParts interface at all (but I don't understand it well enough to come up with any idea of fixing it). And the *init* method doesn't seem to accept variable-length arguments. On the other hand, if I wanted to provide a lot of *init* methods like ((*init* k1::gnu.expr.Keyword v1) (table:put (keyword->string k1) v1)) ((*init* k1::gnu.expr.Keyword v1 k2::gnu.expr.Keyword v2) (table:put (keyword->string k1) v1) (table:put (keyword->string k2) v2)) then I'd need to quote the keywords in order to make it work (which isn't something that I want). Is there any way out of this situation? --000000000000efdeaa05eec264f9--