[Top][All Lists]

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

Re: defining new character names?

From: Lynn Winebarger
Subject: Re: defining new character names?
Date: Thu, 22 Aug 2002 03:39:07 -0500

On Thursday 22 August 2002 02:42, address@hidden wrote:
> On Thu, Aug 22, 2002 at 12:16:24AM -0500, Lynn Winebarger wrote:
> > 
> >       By setting constants, I meant binding a name to a value
> > and that value not being allowed to change during its lifetime.
> > It's not quite the same as a "settable constant".
> Hmm, but where then is the difference to a plain ol' variable?
> A variable is a symbolic name that stands for 'something'. That
> 'something' can be changed (by means of 'set!', for example), even
> so most functional programmers try to avoid it.

   It's a variable, just not a scheme variable. 
   And Scheme is not a pure functional language.  It's about as close to 
assembly as a higher level language can get (thanks to the tail 
recursion requirement and set!).  Unless gcc's computed goto
feature has been made part of the C standard, it's closer 
than even C in that regard.

> This is exactly what variables are for. It seems to me that what you
> suggest is: #\abcd is a variable that can be changed during program
> run time (where the '#\' part of the symbol is just an indication that
> the 'something' that is bound to it is a character). This has two
> consequences: 
>  - you leave scheme's weak typing system (where a variable
>    can be bound to things of different type). There's nothing
>    like "character space" is scheme, as much as there isn't a
>    "function space" (as there is in LISP).

     There's no prohibition against it.  As you point out below,
anything beginning with #\ is _not_ a Scheme variable. 

>  - You leave rNrs: the character sequence '#\' is reserved to
>    start a character constant (r5rs, Section 6.3.4). 
     Here's the funny thing.  My proposal would have the property
that such character names would be constant _as far as the scheme
code could tell_.  That is, even if chose to change the lookup
table, those values could not get captured by scheme code. (But they
could compare to differently named character constants differently).
For example:
(set-char-name! 'foo #\a)
(define a #\foo)
(eq? a #\a) => #t
(eq? a #\b) => #f
(set-char-name! 'foo #\b)
(define b #\foo)
(eq? a #\a) => #f
(eq? a #\b) => #t
(eq? a b) => #t 
    R5RS says character constants are self-evaluating, which it then
defines as "they do not have to be quoted in programs."  Well, this proposal
has that property.  The only time these character variables would be looked
up is when comparing two characters (as above) or when reading/writing
them.  Either way they don't have to be quoted (except to the extent you
consider #\ a form of quotation).

reply via email to

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