Re: string->symbol escaping numbers

Thomas Christian Chust <[email protected]>
Newsgroups gmane.lisp.scheme.chicken
Message-ID <[email protected]>
Hello Lorry,

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

Ciao,
Thomas

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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.