public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* Extending functional call syntax for Sequences to include Maps
@ 2020-07-03 21:24 Duncan Mak
  2020-07-03 22:05 ` Per Bothner
  0 siblings, 1 reply; 5+ messages in thread
From: Duncan Mak @ 2020-07-03 21:24 UTC (permalink / raw)
  To: kawa mailing list

Hello,

I've been reading the Kawa docs quite seriously when I was looking to learn
the Pattern design. I noticed that Sequences implement Procedure, as shown
here in the documentation:

To extract an element from Scheme sequence of type stype there is usually a
function stype-ref. For example:
(define vec1 (vector 5 6 7 8))
(vector-ref vec1 2) ⇒ 7


More concisely, you can use (Kawa-specific) function call syntax:

(vec1 3) ⇒ 8


Which is pretty neat (and reminds me of what they did in Clojure also,
http://clojure-doc.org/articles/language/functions.html#sets-as-functions).

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


[0]
http://clojure-doc.org/articles/language/functions.html#maps-as-functions

Duncan.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-07-16  5:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-03 21:24 Extending functional call syntax for Sequences to include Maps Duncan Mak
2020-07-03 22:05 ` Per Bothner
2020-07-04  4:07   ` Duncan Mak
2020-07-15 18:44   ` Jamison Hope
2020-07-16  5:24     ` Per Bothner

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).