Re: string->symbol escaping numbers
"Lawrence Woodman" <[email protected]>
| Newsgroups | gmane.lisp.scheme.chicken |
|---|---|
| Message-ID | <D2THG5W282IN.Z6BY18RL2L32@thinky> |
On Fri Jul 19, 2024 at 12:02 PM BST, Thomas Christian Chust wrote:
> the symbol is escaped to distinguish it from a number! Note that both
> symbols and numbers are atoms, but numbers are not symbols, nor vice
> versa:
>
> (atom? 3) ;=> #t
> (atom? '|3|) ;=> #t
> (symbol? 3) ;=> #f
> (symbol? '|3|) ;=> #t
> (number? 3) ;=> #t
> (number? '|3|) ;=> #f
>
> (memv 3 '(foo 3)) ;=> '(3)
> (memv '|3| '(foo 3)) ;=> #f
>
> (memv 3 '(foo |3|)) ;=> #f
> (memv '|3| '(foo |3|)) ;=> '(|3|)
Thanks Thomas that was really helpful and has allowed me to resolve my
problem by simply escaping the numbers in the list I was checkiing for
membership against.
Have a great day!
Lorry
> 19.07.2024 12:44:58 Lawrence Woodman <[email protected]>:
>
> > Hello,
> >
> > I'm confused by string->symbol escaping the symbol when used with a string
> > consisting soley of a number:
> >
> > (string->symbol "3") => |3|
> > (eq? (string->symbol "3") 3) => #f
> >
> > I've looked but can't find a reason for its being escaped. It would be
> > great if someone could explain or point my in the direction of
> > somewhere that explains what is happening here.
> >
> > The reason this is important to me is because I want to use memq in a
> > cond to handle various inputs a bit like this with itemtype as a symbol:
> >
> > (cond ((memq itemtype '(text 0))
> > (list "0" username selector hostname port))
> > ((memq itemtype '(menu 1))
> > (list "1" username selector hostname port))
> > ((memq itemtype '(error 3))
> > (list "3" username selector hostname port)))
> >
> > There are workarounds I could make such as comparing against strings but
> > ideally I would like to pass itemtype around as a symbol. Is there an
> > idiomatic way of handling this situtation?
> >
> >
> > Best wishes
> >
> >
> > Lorry