public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Duncan Mak <duncanmak@gmail.com>
To: Per Bothner <per@bothner.com>
Cc: kawa mailing list <kawa@sourceware.org>
Subject: Re: Extending functional call syntax for Sequences to include Maps
Date: Sat, 4 Jul 2020 00:07:44 -0400	[thread overview]
Message-ID: <CABgWrqpBnzZDULWpKx9OCw1-WfXz+saajHDNMMyCZoupXkcvDA@mail.gmail.com> (raw)
In-Reply-To: <b5d0a614-e40a-4728-6c9b-4989ee08d9a8@bothner.com>

I think with an optional keyword argument, this could look quite nice!

(aMap "key" default: "default value")

The keyword could be 'default', or even 'or'.

(aMap 'key or: "empty")


On Fri, Jul 3, 2020 at 6:05 PM Per Bothner <per@bothner.com> wrote:

> On 7/3/20 2:24 PM, Duncan Mak via Kawa wrote:
> > More concisely, you can use (Kawa-specific) function call syntax:
> >
> > (vec1 3) ⇒ 8
> >
> >
> > I was a little disappointed when I found out that this doesn't work for
> > Maps, which is also something Clojure allows [0]:
> >
> > ;; This is Clojure not Scheme
> >
> > ({:age 42 :name "Joe"} :name)     ; ⇒ "Joe"
> > ({:age 42 :name "Joe"} :age)      ; ⇒ 42
> > ({:age 42 :name "Joe"} :unknown)  ; ⇒ nil
>
> I vaguely remember discussing this some years ago, and I think the main
> (conceptual) problem is how to handle arguments with no binding, i.e.
> the 3rd case above.  By analogy with sequences, it should throw an
> exception - which may not be the most convenient
>
> I mentioned a couple of possible approaches, but I don't recall
> what they were.  I think I was leaning towards a way to specify
> a default value - and throw an exception when no default was specified.
>
> I haven't been able to find that email, so far.
>
> A possibly solution:
>
> (htab key [default])
>
> If there is no entry for key in htab, then default is returned
> if specified; otherwise an exception is thrown.
>
> You should also be able to do:
>
> (set! (htab key) new-value)
> --
>         --Per Bothner
> per@bothner.com   http://per.bothner.com/
>


-- 
Duncan.

  reply	other threads:[~2020-07-04  4:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-03 21:24 Duncan Mak
2020-07-03 22:05 ` Per Bothner
2020-07-04  4:07   ` Duncan Mak [this message]
2020-07-15 18:44   ` Jamison Hope
2020-07-16  5:24     ` Per Bothner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CABgWrqpBnzZDULWpKx9OCw1-WfXz+saajHDNMMyCZoupXkcvDA@mail.gmail.com \
    --to=duncanmak@gmail.com \
    --cc=kawa@sourceware.org \
    --cc=per@bothner.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).