Hi Sahithi,

> When I used "(colorize-string "hello" '(GREEN))" in REPL that gave me a
> error unbound variable colorize-string

This means that “colorize-string” was not defined in the REPL 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’s look at the definition
of “colorize-string” and “color”:

(define (color . lst) …)
(define (colorize-string str . color-list) …)

Notice the dot?  This is important.  “color” takes any number of
arguments, including zero.  It simply binds all arguments as a list to

When you evaluate “(color 'GREEN 'ON-BLACK 'BOLD)” the value of “lst”
will be equivalent to

    (list 'GREEN 'ON-BLACK 'BOLD)

Likewise, when you evaluate “(color)” the value of “lst” will be the
empty list, equivalent to “'()” or “(list)”.

Now, “colorize-string” takes at least one argument “str” followed by any
number of arguments that are bound to “color-list”.

Originally, you did this:

    (colorize-string "hello" '(GREEN))

This means that inside “colorize-string” the value of “str” was "hello"
and the value of “color-list” was a list containing a list:

    (list '(GREEN))



This procedure then applies the “color” procedure to the list

    (apply color '((GREEN)))

This is the same as

    (color '(GREEN))

And that’s not correct, because “color” expects its arguments to be any
number of symbols, not a list containing symbols.

The “color” procedure tries to find each of its arguments in the
ansi-color-tables, but can’t find '(GREEN) — the table only contains
'GREEN, not '(GREEN).

And that’s why the output is not green.

Your attached code worked fine for me.  I see “Hello!” printed 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 ….)

You should see the same as I did.

To see what’s going on with your modifications to “(guix ui)” it would
help if you could go through your changes once more (use “git diff” to
be sure to inspect all the lines you have changed) and send your changes
to this list.


Reply via email to