unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* symbol is nested in #{ ...... }#
@ 2024-01-04 10:15 Damien Mattei
  2024-01-04 10:40 ` Tomas Volf
  0 siblings, 1 reply; 6+ messages in thread
From: Damien Mattei @ 2024-01-04 10:15 UTC (permalink / raw)
  To: guile-user

Hi,
why does
(string->symbol "#:hello")
$1 = #{#:hello}#

gives #{#:hello}# in guile instead of #:hello ?

like in Kawa or Racket

i understand it is special to guile as i can write:
scheme@(guile-user)> #:hello
$1 = #:hello

but then how can i generate a #:hello from a string or a list of char?

regards,


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: symbol is nested in #{ ...... }#
  2024-01-04 10:15 symbol is nested in #{ ...... }# Damien Mattei
@ 2024-01-04 10:40 ` Tomas Volf
  2024-01-04 11:35   ` Damien Mattei
  0 siblings, 1 reply; 6+ messages in thread
From: Tomas Volf @ 2024-01-04 10:40 UTC (permalink / raw)
  To: Damien Mattei; +Cc: guile-user

[-- Attachment #1: Type: text/plain, Size: 887 bytes --]

On 2024-01-04 11:15:55 +0100, Damien Mattei wrote:
> Hi,
> why does
> (string->symbol "#:hello")
> $1 = #{#:hello}#
>
> gives #{#:hello}# in guile instead of #:hello ?

My understanding is that keywords are not the same as symbols, that is why you
get a different representation.

>
> like in Kawa or Racket
>
> i understand it is special to guile as i can write:
> scheme@(guile-user)> #:hello
> $1 = #:hello
>
> but then how can i generate a #:hello from a string or a list of char?

You need to create a symbol and after that a keyword from it:

    scheme@(guile-user)> (eq? #:hello (symbol->keyword (string->symbol "hello")))
    $1 = #t

There might be a direct way, but this is what I managed to put together after
digging in the manual.

Have a nice day,
Tomas Volf

--
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: symbol is nested in #{ ...... }#
  2024-01-04 10:40 ` Tomas Volf
@ 2024-01-04 11:35   ` Damien Mattei
  2024-01-04 19:04     ` Thompson, David
  0 siblings, 1 reply; 6+ messages in thread
From: Damien Mattei @ 2024-01-04 11:35 UTC (permalink / raw)
  To: Damien Mattei, guile-user

thank you very much Tomas,
it solved my problem:
(symbol->keyword (list->symbol ....
me too i was digging the manual for 2 hours :-)
Damien
note: seems a bit weird anyway that guile react differently in this case
than Kawa and Racket


On Thu, Jan 4, 2024 at 11:40 AM Tomas Volf <~@wolfsden.cz> wrote:

> On 2024-01-04 11:15:55 +0100, Damien Mattei wrote:
> > Hi,
> > why does
> > (string->symbol "#:hello")
> > $1 = #{#:hello}#
> >
> > gives #{#:hello}# in guile instead of #:hello ?
>
> My understanding is that keywords are not the same as symbols, that is why
> you
> get a different representation.
>
> >
> > like in Kawa or Racket
> >
> > i understand it is special to guile as i can write:
> > scheme@(guile-user)> #:hello
> > $1 = #:hello
> >
> > but then how can i generate a #:hello from a string or a list of char?
>
> You need to create a symbol and after that a keyword from it:
>
>     scheme@(guile-user)> (eq? #:hello (symbol->keyword (string->symbol
> "hello")))
>     $1 = #t
>
> There might be a direct way, but this is what I managed to put together
> after
> digging in the manual.
>
> Have a nice day,
> Tomas Volf
>
> --
> There are only two hard things in Computer Science:
> cache invalidation, naming things and off-by-one errors.
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: symbol is nested in #{ ...... }#
  2024-01-04 11:35   ` Damien Mattei
@ 2024-01-04 19:04     ` Thompson, David
  2024-01-04 20:12       ` Damien Mattei
  0 siblings, 1 reply; 6+ messages in thread
From: Thompson, David @ 2024-01-04 19:04 UTC (permalink / raw)
  To: Damien Mattei; +Cc: guile-user

On Thu, Jan 4, 2024 at 6:36 AM Damien Mattei <damien.mattei@gmail.com> wrote:
>
> thank you very much Tomas,
> it solved my problem:
> (symbol->keyword (list->symbol ....
> me too i was digging the manual for 2 hours :-)
> Damien
> note: seems a bit weird anyway that guile react differently in this case
> than Kawa and Racket

Guile's behavior makes sense to me. #{...}# is syntax for symbols, not
keywords. Symbols can contain any arbitrary characters. Starting a
symbol with "#:" doesn't make it a keyword. Would you expect
(string->symbol "#:hello") to return a keyword? I wouldn't.

- Dave



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: symbol is nested in #{ ...... }#
  2024-01-04 19:04     ` Thompson, David
@ 2024-01-04 20:12       ` Damien Mattei
  2024-01-04 20:20         ` Zelphir Kaltstahl
  0 siblings, 1 reply; 6+ messages in thread
From: Damien Mattei @ 2024-01-04 20:12 UTC (permalink / raw)
  To: Thompson, David; +Cc: guile-user

i understand not all.
i suppose it makes sense .
in fact my problem was parsing a scheme program to generate another scheme
program.
So i'm in the realm of simple text and as i was just searching the good
display i did not understand more the problem.

and even between kawa and racket behavior differs on keywords as in this
example:

#|kawa:1|# (string->keyword "apple")
apple:

Racket:
> (string->keyword "apple")
'#:apple

Damien

On Thu, Jan 4, 2024 at 8:05 PM Thompson, David <dthompson2@worcester.edu>
wrote:

> On Thu, Jan 4, 2024 at 6:36 AM Damien Mattei <damien.mattei@gmail.com>
> wrote:
> >
> > thank you very much Tomas,
> > it solved my problem:
> > (symbol->keyword (list->symbol ....
> > me too i was digging the manual for 2 hours :-)
> > Damien
> > note: seems a bit weird anyway that guile react differently in this case
> > than Kawa and Racket
>
> Guile's behavior makes sense to me. #{...}# is syntax for symbols, not
> keywords. Symbols can contain any arbitrary characters. Starting a
> symbol with "#:" doesn't make it a keyword. Would you expect
> (string->symbol "#:hello") to return a keyword? I wouldn't.
>
> - Dave
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: symbol is nested in #{ ...... }#
  2024-01-04 20:12       ` Damien Mattei
@ 2024-01-04 20:20         ` Zelphir Kaltstahl
  0 siblings, 0 replies; 6+ messages in thread
From: Zelphir Kaltstahl @ 2024-01-04 20:20 UTC (permalink / raw)
  To: Damien Mattei; +Cc: guile-user

Hello Damien,

That is probably, because keywords themselves can look different in Kawa and Racket.

https://www.gnu.org/software/kawa/Keywords.html (mentions both syntaxes, but 
also mentions #:name being more portable)

https://docs.racket-lang.org/guide/keywords.html (only mentions #:name syntax).

Regards,
Zelphir

On 1/4/24 21:12, Damien Mattei wrote:
> i understand not all.
> i suppose it makes sense .
> in fact my problem was parsing a scheme program to generate another scheme
> program.
> So i'm in the realm of simple text and as i was just searching the good
> display i did not understand more the problem.
>
> and even between kawa and racket behavior differs on keywords as in this
> example:
>
> #|kawa:1|# (string->keyword "apple")
> apple:
>
> Racket:
>> (string->keyword "apple")
> '#:apple
>
> Damien
>
> On Thu, Jan 4, 2024 at 8:05 PM Thompson, David <dthompson2@worcester.edu>
> wrote:
>
>> On Thu, Jan 4, 2024 at 6:36 AM Damien Mattei <damien.mattei@gmail.com>
>> wrote:
>>> thank you very much Tomas,
>>> it solved my problem:
>>> (symbol->keyword (list->symbol ....
>>> me too i was digging the manual for 2 hours :-)
>>> Damien
>>> note: seems a bit weird anyway that guile react differently in this case
>>> than Kawa and Racket
>> Guile's behavior makes sense to me. #{...}# is syntax for symbols, not
>> keywords. Symbols can contain any arbitrary characters. Starting a
>> symbol with "#:" doesn't make it a keyword. Would you expect
>> (string->symbol "#:hello") to return a keyword? I wouldn't.
>>
>> - Dave
>>
-- 
repositories: https://notabug.org/ZelphirKaltstahl




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-01-04 20:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-04 10:15 symbol is nested in #{ ...... }# Damien Mattei
2024-01-04 10:40 ` Tomas Volf
2024-01-04 11:35   ` Damien Mattei
2024-01-04 19:04     ` Thompson, David
2024-01-04 20:12       ` Damien Mattei
2024-01-04 20:20         ` Zelphir Kaltstahl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).