guile-user
[Top][All Lists]
Advanced

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

Re: hashmark in symbols


From: Andreas Reuleaux
Subject: Re: hashmark in symbols
Date: Mon, 02 Jan 2023 16:20:36 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)

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.



reply via email to

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