chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] A question about keywords and symbol->string


From: Evan Hanson
Subject: Re: [Chicken-users] A question about keywords and symbol->string
Date: Fri, 17 Mar 2017 11:10:26 +1300

Hi there,

On 2017-03-16 17:22, megane wrote:
> Currently symbol->string strips any keyword prefixes when applied to
> keywords (e.g. (symbol->string 'foo:) returns "foo"). Is this correct
> behavior?

That's the correct behaviour, yes. symbol->string basically ignores
keywords and treats them just like normal symbols in this regard.

> Is there a way to get the full symbol name (i.e. #:foo -> "#:foo", and
> foo: -> "foo:")?

Not really. #:foo and foo: are both textual representations of the same
symbol. The "style" of the keyword isn't kept around after it's read, so
all the runtime knows is that (a) there's a symbol "foo" and (b) it's a
keyword. It's not specifically a "prefix" or "suffix" keyword until
written out again.

Anyway, to get a string that *looks* like a keyword, the easiest option
is probably to go via the written representation with something like:

   (format "~s" foo:)

However note that this is sensitive to the keyword-style parameter, as
hinted at above:

   (parameterize ((keyword-style #:prefix)) (format "~s" #:foo)) ; => ":foo"
   (parameterize ((keyword-style #:suffix)) (format "~s" #:foo)) ; => "foo:"
   (parameterize ((keyword-style #f))       (format "~s" #:foo)) ; => "#:foo"

Hope that helps,

Evan



reply via email to

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