pika-dev
[Top][All Lists]
Advanced

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

Re: [Pika-dev] Keyword type?


From: Tom Lord
Subject: Re: [Pika-dev] Keyword type?
Date: Wed, 26 May 2004 17:42:25 -0700 (PDT)

    > From: Andreas Rottmann <address@hidden>

    > Once strings and symbols are in place, what about providing a keyword
    > type such as many popular Schemes do? 

Yes.

Basically, there should be a non-numeric, symbolic, self-evaluating
type (which is what keyword values are).


    > Keywords might come handy later for keyword arguments
    > and other syntax extensions.

Here's the problem.   It's not a deal-killing problem, just something
to note.

The main use for keywords is, as you say, keyword arguments.   They
give you a disjoint set of values that can be used to disambiguate 
an otherwise ambiguous argument list.   For example:

        (some-proc 'a 'b 'c 'd)

Is that four arguments which are symbols?   Or two which
are the values of keyword arguments 'a and 'c?

The keyword version (I prefer a non-R5RS syntax):

        (some-proc 'a 'b :c 'd)

disambiguates (two positional arguments, 'a and 'b, plus a 
keyword argument :c whose value is 'd).

That's swell.  But weird.  It just pushes the problem off to
the side, it doesn't really fix it.   After all, what is this:

        (some-proc :a :b :c :d)

Is that a call with four arguments that happen to be keywords?  or is
it two keyword arguments with keyword values?   Or is it four keyword
arguments that don't take a value?

The problem there is that keywords are both syntax for calls and
values in scheme.   That results in ambiguity.

Ok, so maybe keyword arguments should be an entirely separate thing.
So, for example, 

        :b

is not a valid scheme expression at all.   It doesn't denote a value.
There's no such thing as:

        (keyword? :b)

That would eliminate the ambiguity of calls.  For example:


        (some-proc :a :b :c :d)

would certainly be a call with four keywords and no positional
arguments or keyword arguments.

But now what, exactly, does `eval' take?

So, as an argument-passing mechanism, keywords don't fit quite
perfectly into Scheme.   Bummer.

Nevertheless, self-evaluating atomic values which have a
human-readable name are intrinsicly useful.   Programmers can avoid
the ambiguities mentioned above just by not using them for anything
that would conflict with their use as keyword-argument markers.

So, yes, I'd like them.

(How do you feel about :foo instead of #:foo?  It violates R5RS, I
guess, but -- in any way that is likely to really matter?)

-t



 





reply via email to

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