Comments (6)
@nivekuil, as far as I understand Emacs alist
looks like '((:a . 1) (:b . 2))
, whereas plist
looks like '(:a 1 :b 2)
. So, if you need to pass a map to Clojure, you can store your data in alist
and convert it by this function call:
(clomacs-alist-to-map '((:a . 1) (:b . 2))) => "{:a 1 :b 2}"
Would you like to have clomacs-plist-to-map
function in clomacs too?
from clomacs.
Per the emacs manual, an alist is supposed to be a list of cons cells. I presume a list is also a cons cell because (consp '(:a 1 :b 2))
is t
, so I think the json-alist-p
behavior is correct in identifying that as an alist.
if you need to pass a map to Clojure, you can store your data in alist and convert it by this function call:
This doesn't become a map in clojure for me:
(clomacs-defun cl-type type)
(cl-type '((:a . 1))) => "clojure.lang.PersistentArrayMap"
(cl-type (clomacs-alist-to-map '((:a . 1))) => "java.lang.String"
In general I am curious how to get the latter case working, i.e. how I can pass from elisp a string that represents a map, into clojure where it then gets treated as an actual map.
Would you like to have clomacs-plist-to-map function in clomacs too?
I think that would be handy, as plists are the closer abstraction (non-duplicate keys). Could we just use json-plist-p for this? I think the actual conversion part is just a single character change from clomacs-alist-to-map
, changing (cdr pair
) to (cadr pair)
on line 248.
from clomacs.
Am I missed something?
https://www.gnu.org/software/emacs/manual/html_node/elisp/Association-Lists.html
https://www.gnu.org/software/emacs/manual/html_node/elisp/Property-Lists.html#Property-Lists
What are you trying to do? Using alist
in the Elisp side can always be considered as a map
in Clojure side, whereas plist
can be used as a list
or a map
in Elisp side, but it's a simple list
in Clojure side. To unify that I assume users will use alist
for maps to ensure they mean maps. E.g. you have a Clojure assoc
function. Its parameters list are: (assoc map key val)
. So, you want to pass a map
as it's the first argument. Ok, it will be auto-converted:
(clomacs-defun cl-assoc assoc)
(cl-assoc '((:a . 1) (:b . 2)) :c 3) => "{:a 1, :b 2, :c 3}"
So, normally, you should not call clomacs-alist-to-map
manually.
By default, Elisp side assumes output form Clojure as a string
, but you can provide you conversion function in :return-type
parameter of the clomacs-defun
maco or use clomacs/format-result
in Clojure side and :eval
for autoconversion. E.g.:
Clojure
:
(require '(clomacs))
(defn my-assoc [map key val]
(clomacs/format-result
(assoc map key val)))
Elisp
:
(clomacs-defun cl-my-assoc my-assoc
:return-type :eval)
(cl-my-assoc '((:a . 1) (:b . 2)) :c 3) => ((:a . 1) (:b . 2) (:c . 3))
from clomacs.
Using
alist
in the Elisp side can always be considered as amap
in Clojure side, whereasplist
can be used as alist
or amap
in Elisp side, but it's a simplelist
in Clojure side. To unify that I assume users will usealist
for maps to ensure they mean maps.
That's a good point. parseedn-print-str
seems to assume that any list with an even # of elements and keywords as keys is a map, and I expected clomacs to behave the same, but maybe the needs are different.
By default, Elisp side assumes output form Clojure as a
string
, but you can provide you conversion function in:return-type
parameter of theclomacs-defun
maco or useclomacs/format-result
in Clojure side and:eval
for autoconversion.
Ah, I missed this. Thanks.
from clomacs.
Unfortunately, clomacs documentation is a bit outdated. For more real examples please look at https://github.com/kostafey/ejc-sql/blob/master/ejc-interaction.el.
Can I consider the issue closed?
from clomacs.
Yup, thanks.
from clomacs.
Related Issues (13)
- nrepl not found HOT 1
- Passing escaped substrings HOT 1
- clomacs-httpd-start FileNotFoundException on Windows 10 HOT 6
- cdr: Wrong type argument: arrayp, ("clojure-test") HOT 2
- Please make cljs-clomacs. HOT 8
- Create clomacs server HOT 2
- Try README CLJ call Elisp function demo error HOT 1
- Adding babashka as runtime HOT 3
- Async call-type example
- Error: Symbol’s function definition is void: clomacs-doc HOT 2
- void variable clomacs--doc HOT 13
- Warning msg when installing in spacemacs and the dependent package (ejc-sql) fails to install HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clomacs.