unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* hashmark in symbols
@ 2023-01-02  2:27 Andreas Reuleaux
  2023-01-02  6:04 ` lloda
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Reuleaux @ 2023-01-02  2:27 UTC (permalink / raw)
  To: guile-user

Hi,

in common lisp I get e.g.

--8<---------------cut here---------------start------------->8---
* (format nil "~a" '\#444)
"#444"
--8<---------------cut here---------------end--------------->8---

(assuming #444 is a css color - that is my use case anyway -
and thus likewise for any other color)

Now, apparently in Guile this is not the case:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> (format #f "~a" '\#444)
$158 = "#{\\#444}#"
--8<---------------cut here---------------end--------------->8---

And likewise

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> (symbol->string '\#444)
$159 = "\\#444"
--8<---------------cut here---------------end--------------->8---


Now I am tempted to case split (after (symbol->string ...) as above):

  if the resulting string starts with \\# then cut off the \\ part
  otherwise ...

but this seems overly complicated!? And is not really what I want! Is
there any other (readable) way to specify the hashmark in a symbol
(assuming \hashmark here, but this is wrong of course), so that

--8<---------------cut here---------------start------------->8---
(symbol->string '\hashmark444)
--8<---------------cut here---------------end--------------->8---

just works: results in "#444" (not "\\#444") ?

PS: I am experimenting with #\x0023, like so

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> #\x0023
$181 = #\#
--8<---------------cut here---------------end--------------->8---

but I still have no clue, how to write a simple symbol, that when
translated to a string, results in "#444".


Thanks in advance,
  -A



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

* Re: hashmark in symbols
  2023-01-02  2:27 hashmark in symbols Andreas Reuleaux
@ 2023-01-02  6:04 ` lloda
  2023-01-02  6:25   ` Andreas Reuleaux
  0 siblings, 1 reply; 5+ messages in thread
From: lloda @ 2023-01-02  6:04 UTC (permalink / raw)
  To: Andreas Reuleaux; +Cc: guile-user


> On 2 Jan 2023, at 03:27, Andreas Reuleaux <rx@a-rx.info> wrote:
> 
> ....

> but I still have no clue, how to write a simple symbol, that when
> translated to a string, results in "#444".

https://www.gnu.org/software/guile/manual/guile.html#Symbol-Read-Syntax <https://www.gnu.org/software/guile/manual/guile.html#Symbol-Read-Syntax> gives you either #{#444}# or |#444| with the r7rs read option.

regards

  Daniel




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

* Re: hashmark in symbols
  2023-01-02  6:04 ` lloda
@ 2023-01-02  6:25   ` Andreas Reuleaux
  2023-01-02  6:59     ` Taylan Kammer
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Reuleaux @ 2023-01-02  6:25 UTC (permalink / raw)
  To: lloda; +Cc: guile-user

Ah, OK, this helps indeed

--8<---------------cut here---------------start------------->8---
(read-enable  'r7rs-symbols)
--8<---------------cut here---------------end--------------->8---


Many thanks.
  -A




lloda <lloda@sarc.name> writes:

>> On 2 Jan 2023, at 03:27, Andreas Reuleaux <rx@a-rx.info> wrote:
>> 
>> ....
>
>> but I still have no clue, how to write a simple symbol, that when
>> translated to a string, results in "#444".
>
> https://www.gnu.org/software/guile/manual/guile.html#Symbol-Read-Syntax
> <https://www.gnu.org/software/guile/manual/guile.html#Symbol-Read-Syntax>
> gives you either #{#444}# or |#444| with the r7rs read option.
>
> regards
>
>   Daniel



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

* Re: hashmark in symbols
  2023-01-02  6:25   ` Andreas Reuleaux
@ 2023-01-02  6:59     ` Taylan Kammer
  2023-01-02 16:20       ` Andreas Reuleaux
  0 siblings, 1 reply; 5+ messages in thread
From: Taylan Kammer @ 2023-01-02  6:59 UTC (permalink / raw)
  To: Andreas Reuleaux, lloda; +Cc: guile-user

On 02.01.2023 07:25, Andreas Reuleaux wrote:
> Ah, OK, this helps indeed
> 
> --8<---------------cut here---------------start------------->8---
> (read-enable  'r7rs-symbols)
> --8<---------------cut here---------------end--------------->8---
> 
Another option would be to use string->symbol:

  (string->symbol "#444")

That being said, I wonder if it's not better to use strings for this.

Is there any particular reason you want to use symbols to represent CSS
color values?  I assume that your main requirements are:

- Easy to represent as literal values in code.

- Easy to splice into a bigger string (or write into an output stream) that
  will become an entire CSS code snippet or file.

Strings seem like the most straightforward choice.  All in all there's not
much difference though, given that symbols are basically just automatically
interned immutable strings.

-- 
Taylan




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

* Re: hashmark in symbols
  2023-01-02  6:59     ` Taylan Kammer
@ 2023-01-02 16:20       ` Andreas Reuleaux
  0 siblings, 0 replies; 5+ messages in thread
From: Andreas Reuleaux @ 2023-01-02 16:20 UTC (permalink / raw)
  To: guile-user

Hi, thanks for getting back to me in this regard, and yes, you are
right:

Basically my code is a translation of (common lisp)
https://github.com/Inaimathi/cl-css to guile.

So things like this work:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> (css '((body :margin 5px :padding 0px)))
$75 = "body { margin: 5px; padding: 0px; }"
--8<---------------cut here---------------end--------------->8---

And more rules, of course, (and compound selectors etc.) like so:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> (%display (css '((body :margin 5px :padding 0px)(".label, li p.desc" :font-size .8em :font-family sans-serif :color |#444|))))
body { margin: 5px; padding: 0px; }
.label, li p.desc { font-size: .8em; font-family: sans-serif; color: #444; }
scheme@(guile-user)>
--8<---------------cut here---------------end--------------->8---


with %display being defined as

--8<---------------cut here---------------start------------->8---
#!curly-infix

;; aka "after"
(define $. compose)

(define %display
{(lambda _ (newline)) $. display}
)
--8<---------------cut here---------------end--------------->8---


which brings me back to the hashmark in symbols issue. - I will shorten
the above example to just:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> (css '((body :margin 5px :padding 0px :color |#444|)))
$79 = "body { margin: 5px; padding: 0px; color: #444; }"
--8<---------------cut here---------------end--------------->8---

This works - thanks to

--8<---------------cut here---------------start------------->8---
(read-enable  'r7rs-symbols)
--8<---------------cut here---------------end--------------->8---

now. - Alternatively, as you suggested: just as a string:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> (css '((body :margin 5px :padding 0px :color "#444")))
$82 = "body { margin: 5px; padding: 0px; color: #444; }"
--8<---------------cut here---------------end--------------->8---

And (your second suggestion) - with string->symbol (but then I have to
interrupt the code with a quote - not sure if this is a win,
it does seem less readable to me:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> (css `((body :margin 5px :padding 0px :color ,(string->symbol "#444"))))
$84 = "body { margin: 5px; padding: 0px; color: #444; }"
--8<---------------cut here---------------end--------------->8---

Maybe I can make my code available some time. - It needs a little more
polishing though.

Thanks again.

  -A
  




Taylan Kammer <taylan.kammer@gmail.com> writes:

> On 02.01.2023 07:25, Andreas Reuleaux wrote:
>> Ah, OK, this helps indeed
>> 
>> --8<---------------cut here---------------start------------->8---
>> (read-enable  'r7rs-symbols)
>> --8<---------------cut here---------------end--------------->8---
>> 
> Another option would be to use string->symbol:
>
>   (string->symbol "#444")
>
> That being said, I wonder if it's not better to use strings for this.
>
> Is there any particular reason you want to use symbols to represent CSS
> color values?  I assume that your main requirements are:
>
> - Easy to represent as literal values in code.
>
> - Easy to splice into a bigger string (or write into an output stream) that
>   will become an entire CSS code snippet or file.
>
> Strings seem like the most straightforward choice.  All in all there's not
> much difference though, given that symbols are basically just automatically
> interned immutable strings.



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

end of thread, other threads:[~2023-01-02 16:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-02  2:27 hashmark in symbols Andreas Reuleaux
2023-01-02  6:04 ` lloda
2023-01-02  6:25   ` Andreas Reuleaux
2023-01-02  6:59     ` Taylan Kammer
2023-01-02 16:20       ` Andreas Reuleaux

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).