[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: let-alist can't deal with the keys which includes spaces.
From: |
Omar Polo |
Subject: |
Re: let-alist can't deal with the keys which includes spaces. |
Date: |
Tue, 20 Jul 2021 17:35:22 +0200 |
User-agent: |
mu4e 1.4.15; emacs 28.0.50 |
Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> I adapted the examples given on
> <https://www.gnu.org/software/emacs/manual/html_node/elisp/Association-Lists.html>
> to the following:
>
> ;;;
> (setq colors '(("rose merry" . red) (lily (belladonna . yellow))))
>
> (let-alist colors
> (if (eq ."rose merry" 'red)
> .lily.belladonna))
> ;;;
It's not an error, it's totally expected. When you type
.lily.belladonna
emacs lisp (and I guess every lisp out there) sees the symbol
'.lily.belladonna.
Now, when you type
."rose merry"
it just doesn't make sense (from the emacs lisp parser POV). there's a
lonely dot and a string. A lonely dot is not a valid symbol. In
addition, remember that spaces aren't strictly necessary. Consider for
example:
(let ((.a 5))
.a"hello")
;; => "hello"
;; equivalent to
(let ((.a 5))
.a
"hello")
Strings and symbols are different data types and such have different
properties and different syntax.
Moreover, I don't know how wise is to use strings as alist keys (symbols
are interned, strings doesn't necessary). I suggest using something
like
(setq colors '((rose-merry . red) (lily (belladonna . yellow))))
and following the kebab-case style.
HTH
> When I try to evaluate the above code snippet, the following error is
> triggered:
>
> Debugger entered--Lisp error: (invalid-read-syntax ". in wrong context" 8 28)
> read(#<buffer *scratch*>)
> elisp--preceding-sexp()
> elisp--eval-last-sexp(t)
> eval-last-sexp(t)
> eval-print-last-sexp(nil)
> funcall-interactively(eval-print-last-sexp nil)
> call-interactively(eval-print-last-sexp nil nil)
> command-execute(eval-print-last-sexp)
>
> It seems that let-alist can't deal with the keys which includes
> spaces. Any hints for this problem will be highly appreciated.
>
> Regards
- let-alist can't deal with the keys which includes spaces., Hongyi Zhao, 2021/07/20
- Re: let-alist can't deal with the keys which includes spaces., tomas, 2021/07/20
- Re: let-alist can't deal with the keys which includes spaces.,
Omar Polo <=
- Re: let-alist can't deal with the keys which includes spaces., tomas, 2021/07/20
- Re: let-alist can't deal with the keys which includes spaces., Emanuel Berg, 2021/07/20
- Re: let-alist can't deal with the keys which includes spaces., tomas, 2021/07/20
- Re: let-alist can't deal with the keys which includes spaces., Emanuel Berg, 2021/07/20
- Re: let-alist can't deal with the keys which includes spaces., Emanuel Berg, 2021/07/20
- Re: let-alist can't deal with the keys which includes spaces., tomas, 2021/07/21
- Re: let-alist can't deal with the keys which includes spaces., Emanuel Berg, 2021/07/21