[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Colorized REPL

From: Ludovic Courtès
Subject: Re: [PATCH] Colorized REPL
Date: Sat, 12 Jan 2013 22:16:32 +0100
User-agent: Gnus/5.130005 (Ma Gnus v0.5) Emacs/24.2 (gnu/linux)

Hi Daniel,

Daniel Hartwig <address@hidden> skribis:

> On 11 January 2013 22:33, Ludovic Courtès <address@hidden> wrote:


>> I still think that using a disjoint type for
>> colors would be better than symbols.
> These are arbitrary control codes and can be applied in any
> combination.  Essentially, the best you can do with a disjoint type
> is:
> (define-record-type foo
>   (make-foo name code) …
> Which you would still need a dictionary to look them up by name, or
> export a binding for every code and combination, or provide additional
> operators to combine them …


> List of symbols is a convenient abstraction over the natural form:
> list of control codes.  Embedding this in to a record with named and
> function-presuming fields is too much and needlessly complicated, IMO.
> List of symbols is also compatible with the interface established by
> the earlier guile-lib module, for whatever that is worth.
> Using list of symbols:
> (colorize-string "foo" '(RED))
> (colorize-string "foo" '(BOLD ON-CYAN))
> It is not clear to me the interface you are proposed at this level.
> Will you provide counter examples to these two calls?

In general, using symbols like this amounts to introducing an alternate
name space, with its own rules, and its own support (or lack thereof).
For instance, if you use variables to hold colors, you could write:

  (colorize-string "foo" red)
  (colorize-string "foo" (with-background cyan bold))

And you get unbound variable warnings and errors if there’s a typo, a
type error if you’re passing something unrelated, etc.

That’s why as a rule of thumb I prefer disjoint types and variables for
singleton instances.

Now, there may be cases where this is overkill, or not appropriate for
some reason.  I’m not completely sure about ANSI escapes, so perhaps
you’re right that what I suggest is inappropriate.  Yet, the RED,
ON-CYAN, etc. symbols look ugly to me as an abstraction.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]