1
votes

Context

Our team is using some more functional patterns in other languages (IE javascript and ruby) and we've had some recreational conversations on standardized naming. My familiarity is largely limited to Clojure and Ramda.js.

Both Clojure and Ramda have assoc and Clojure has assoc-in with a Ramda version at assocPath. I'm guessing Ramda cribbed its name from Clojure here.

I note that common lisp doesn't seem to even have a clear comparable to assoc-in. See this conversation.

The Question

What other lisps or lisp-likes have assoc and assoc-in comparables, and what do they call them?

Bonus Points

Do there exist any resources for "rosetta stone" inter-lisp comparison of function names? A place to easily see where comparable behavior has similar or different names, or to see where comparable names have similar or different behavior?

1
I think the "rosetta stone" part of the question is the most interesting part, and the only part that might garner "an answer", as opposed to a mass quantity of comments that contribute one tiny piece of the puzzle. - Biped Phill
I already saw "update". Common Lisp has acons but not for recursive keys, you'd need to use the FSet library to have something equivalent. - coredump
Not what you asked for, but I have seen at least one Clojurescript/Javascript translation table. - Mars

1 Answers

1
votes

You're right that Common Lisp doesn't have assoc-in or something similar. I would say, overall, it has pretty basic support for hash-table operations in the standard library (which I attribute to lack of practical experience with them at the time of the development of the standard). However, even if more hash-table-related stuff was present, I still doubt something like assoc-in would be added. That's because, in Lisp, the preferred approach to deal with assignment is via the setf'able places machinery that involves the macro define-setf-expander.

For instance, the rutils library I am maintaining provides a lot of additional hash-table-related operators, as well as Clojure-like literal syntax for them. Yet, this is how I'd handle the assoc-in case using its primitives (including the ? operator that is a shorthand for generic-elt):

CL-USER> (ql:quickload :rutils)
CL-USER> (in-package :rtl-user)
RTL-USER> (named-readtables:in-readtable rutils-readtable)
RTL-USER> (toggle-print-hash-table)
RTL-USER> (let ((ht #{:a 1 :b 3}))
            (setf (? ht :c) #{:d 33})
            ht)
#{
  :A 1
  :B 3
  :C #{
       :D 33
      }
 } 

I'd say that it's a question of taste which approach to prefer. To me, the Lisp one has more advantages: it's more uniform and explicit.

The other advantage is that the get-in part becomes really straightforward:

RTL-USER> (? * :c :d)
33

(Here, I use * to refer to the results of the previous REPL computation that happen to be the hash-table we created in the assoc-in exercise).

P.S. As for the Rosetta stones, here are a few attempts: