From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Omar Polo Newsgroups: gmane.emacs.help Subject: Re: let-alist can't deal with the keys which includes spaces. Date: Tue, 20 Jul 2021 17:35:22 +0200 Message-ID: <87h7gpyp51.fsf@omarpolo.com> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8562"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.15; emacs 28.0.50 Cc: help-gnu-emacs@gnu.org To: Hongyi Zhao Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jul 20 17:36:02 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m5rmq-0001zF-W3 for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 20 Jul 2021 17:36:01 +0200 Original-Received: from localhost ([::1]:41694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m5rmp-0005x3-SQ for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 20 Jul 2021 11:35:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5rmS-0005uW-0a for help-gnu-emacs@gnu.org; Tue, 20 Jul 2021 11:35:36 -0400 Original-Received: from mail.omarpolo.com ([144.91.116.244]:59006) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5rmP-0000Ea-0N for help-gnu-emacs@gnu.org; Tue, 20 Jul 2021 11:35:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=omarpolo.com; s=20200327; t=1626795326; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=FfaPlRy3BJt4NrBJFe5PpVV4Ymm0hsFOHDJ5w14bfh8=; b=SlASrU45BOephBmsjhOk5VnwjaUdYMB61WfT3E2KftixWFL4W5dJ2y2l+mTqvmsZQHaAMD wLye9NXERTdPQX52bkDl0f0sLRr0ZoWlEBPaiO2lXHrvKJeEo+vUCoUGFzO0Bkd63uBOEj 8aRPILujZEjbz4gLrVCcAfdafcYJCZU= Original-Received: from localhost (host-95-232-43-92.retail.telecomitalia.it [95.232.43.92]) by mail.omarpolo.com (OpenSMTPD) with ESMTPSA id fa433bfc (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 20 Jul 2021 17:35:25 +0200 (CEST) Original-Received: from venera (localhost [127.0.0.1]) by localhost (OpenSMTPD) with ESMTP id 3438ac31; Tue, 20 Jul 2021 17:35:22 +0200 (CEST) In-reply-to: Received-SPF: pass client-ip=144.91.116.244; envelope-from=op@omarpolo.com; helo=mail.omarpolo.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:131879 Archived-At: Hongyi Zhao writes: > I adapted the examples given on > > 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(#) > 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