From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 35071 invoked by alias); 6 Mar 2015 19:15:23 -0000 Mailing-List: contact kawa-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: kawa-owner@sourceware.org Received: (qmail 35049 invoked by uid 89); 6 Mar 2015 19:15:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.2 X-HELO: aibo.runbox.com Received: from aibo.runbox.com (HELO aibo.runbox.com) (91.220.196.211) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 06 Mar 2015 19:15:20 +0000 Received: from [10.9.9.209] (helo=mailfront04.runbox.com) by bars.runbox.com with esmtp (Exim 4.71) (envelope-from ) id 1YTxiN-0002OY-SQ for kawa@sourceware.org; Fri, 06 Mar 2015 20:15:15 +0100 Received: from 70-36-239-115.dsl.dynamic.fusionbroadband.com ([70.36.239.115] helo=toshie.bothner.com) by mailfront04.runbox.com with esmtpsa (uid:757155 ) (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.76) id 1YTxiJ-0001H2-HG for kawa@sourceware.org; Fri, 06 Mar 2015 20:15:11 +0100 Message-ID: <54F9FCBB.4080904@bothner.com> Date: Fri, 06 Mar 2015 19:15:00 -0000 From: Per Bothner User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: kawa@sourceware.org Subject: Re: [patch] set setter for array-ref to array-set! References: <3100F387-4E57-4C91-B7CB-FBFF61379A4A@theptrgroup.com> <54F4C353.9060601@bothner.com> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2015-q1/txt/msg00058.txt.bz2 On 03/04/2015 11:54 PM, Jamison Hope wrote: > What do you think about doing similar things for hash tables? > > This works (even though RNRS hashtable-ref takes a third argument): > > (import (rnrs hashtables)) > (set! (setter hashtable-ref) hashtable-set!) > > (define h (make-eq-hashtable)) > (set! (hashtable-ref h 'year) 2015) > h => {year=2015} It's a little ugly because of the weirdness with the default parameter - i.e. that (hashtable-ref h 'year) is not a valid call, even after the set!. Plus it doesn't make the code any more compact or readable. > It seems like function call notation would be nice for java.util.Map > instances, too: > > (set! (h k) v) => (h:put k v) > (h k) => (h:get k) > > Thoughts? Part of a GSoC project, perhaps? Too small for a GSoC project. Using function call notation seems reasonable, but I think I had some concerns I can't quite remember. One minor issue is the "conflict" with colon notation when it comes to string or symbol keys. Should we prefer: (my-table "foo") or: my-table:foo That issue is probably a distraction. Another issue to note: If we support function call notation, I'd like it to work for any java.util.Map, not just those returned by make-hash-table or make-hashtable. Finally there is the issue of defaults. If a key isn't in my-table what should be the result of this? (my-table key) Arguably this should throw an exception as key isn't in its domain. The other alternative is to return #!null, for simplicity and compatibility with the Java Map interface. My inclination would be to throw an exception, and also introduce: (my-table key default: default-value) If default-value is #!null this should be compiled to a call to the Map get routine. If default-value is non#!null it should be compiled to the getOrDefault method if either the target is Java 8 or if my-table is known to be a sub-class of AbstractHashTable; otherwise we call a static helper method. (Of course if my-table isn't known to be a Map at compile-time we have to check if it's a Map at run-time.) Comments? -- --Per Bothner per@bothner.com http://per.bothner.com/