From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ricardo Wurmus Subject: Re: Fwd: Re: Patch file for colorize module Date: Sat, 09 Jun 2018 22:57:29 +0200 Message-ID: <8736xv1xvq.fsf@elephly.net> References: <8ea5d026-fab9-7b12-198e-610ad7743cb2@swecha.net> <87o9gwpcmx.fsf@elephly.net> <2f71be8d-c672-c66a-0b16-bc3abc748754@swecha.net> <877enjpquf.fsf@elephly.net> <557b30de-5aa2-113f-7e90-a4a23e86bb07@swecha.net> <87602zbrcc.fsf@elephly.net> <328742c6-f96f-74b8-68ef-3b165a6199aa@swecha.net> <87zi0a3m3t.fsf@elephly.net> <07c93c07-2172-6bf1-6188-88830c1d8b4c@swecha.net> <87o9gpyq4t.fsf@elephly.net> <91773c8b-3072-2a82-dca3-cbeb5adf826d@swecha.net> <87fu1zznl3.fsf@elephly.net> <87bmcnzjsp.fsf@elephly.net> <18408eca-ad0b-111a-0ef6-ab452c9ca89c@swecha.net> <878t7ryxvf.fsf@elephly.net> <02e1a59a-ebc1-dfce-e1d6-22e97e742214@swecha.net> <874lifypeb.fsf@elephly.net> <648f81fc-0607-2c3b-f9a3-ca3b29cd637b@swecha.net> <87bmck22uz.fsf@elephly.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:53430) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSqBf-0006jf-3T for guix-devel@gnu.org; Tue, 12 Jun 2018 16:46:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSqBb-0003wJ-4L for guix-devel@gnu.org; Tue, 12 Jun 2018 16:46:43 -0400 Received: from sender-of-o51.zoho.com ([135.84.80.216]:21009) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSqBa-0003vl-Vl for guix-devel@gnu.org; Tue, 12 Jun 2018 16:46:39 -0400 In-reply-to: List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Sahitihi Cc: guix-devel Hi Sahithi, > When I used "(colorize-string "hello" '(GREEN))" in REPL that gave me a > error unbound variable colorize-string This means that =E2=80=9Ccolorize-string=E2=80=9D was not defined in the RE= PL session. You would need to re-evaluate the definition. > When i used the same in attached file this gave me a colorless output > > However when I tried with "(colorize-string "hello" 'GREEN)" in same > file this gave me colored output but in REPL still a unbound-variable. > > So, I tried changing "(GREEN)" to "GREEN" in ui.scm but resulted with a > colorless output. This is exactly the cause of the errors. Let=E2=80=99s look at the definit= ion of =E2=80=9Ccolorize-string=E2=80=9D and =E2=80=9Ccolor=E2=80=9D: (define (color . lst) =E2=80=A6) (define (colorize-string str . color-list) =E2=80=A6) Notice the dot? This is important. =E2=80=9Ccolor=E2=80=9D takes any numb= er of arguments, including zero. It simply binds all arguments as a list to =E2=80=9Clst=E2=80=9D. When you evaluate =E2=80=9C(color 'GREEN 'ON-BLACK 'BOLD)=E2=80=9D the valu= e of =E2=80=9Clst=E2=80=9D will be equivalent to (list 'GREEN 'ON-BLACK 'BOLD) Likewise, when you evaluate =E2=80=9C(color)=E2=80=9D the value of =E2=80= =9Clst=E2=80=9D will be the empty list, equivalent to =E2=80=9C'()=E2=80=9D or =E2=80=9C(list)=E2=80=9D. Now, =E2=80=9Ccolorize-string=E2=80=9D takes at least one argument =E2=80= =9Cstr=E2=80=9D followed by any number of arguments that are bound to =E2=80=9Ccolor-list=E2=80=9D. Originally, you did this: (colorize-string "hello" '(GREEN)) This means that inside =E2=80=9Ccolorize-string=E2=80=9D the value of =E2= =80=9Cstr=E2=80=9D was "hello" and the value of =E2=80=9Ccolor-list=E2=80=9D was a list containing a list: (list '(GREEN)) or '((GREEN)) This procedure then applies the =E2=80=9Ccolor=E2=80=9D procedure to the li= st =E2=80=9Ccolor-list=E2=80=9D: (apply color '((GREEN))) This is the same as (color '(GREEN)) And that=E2=80=99s not correct, because =E2=80=9Ccolor=E2=80=9D expects its= arguments to be any number of symbols, not a list containing symbols. The =E2=80=9Ccolor=E2=80=9D procedure tries to find each of its arguments i= n the ansi-color-tables, but can=E2=80=99t find '(GREEN) =E2=80=94 the table only= contains 'GREEN, not '(GREEN). And that=E2=80=99s why the output is not green. Your attached code worked fine for me. I see =E2=80=9CHello!=E2=80=9D prin= ted twice in red. To make this work for yourself try this: * open a fresh REPL * input: ,use (srfi srfi-1) * paste your file without the module header; start with (define ansi-color-tables =E2=80=A6.) You should see the same as I did. To see what=E2=80=99s going on with your modifications to =E2=80=9C(guix ui= )=E2=80=9D it would help if you could go through your changes once more (use =E2=80=9Cgit diff= =E2=80=9D to be sure to inspect all the lines you have changed) and send your changes to this list. -- Ricardo