4 ms·
Why are atoms that start with numbers accepted as symbols? Is there any usecase for that?
by grugagag 6y ago
Why are atoms that start with numbers accepted as symbols? Is there any usecase for that?
- gumby 6y agoThe use case is someone wanted to name a symbol that way. What’s wrong with that?
- grugagag 6y agoNothing wrong, was just wondering in case I missed something, in most languages by convention variables and functions cannot start with a number. I'm learning lisp and ran into this at some point just had the chance to ask someone experienced why.
- deleted 6y ago[deleted]
- timonoko 6y agoI had floating point implemented like that in Nokolisp. If the item contains anything except number characters, it is a symbol. Stupid, but very transparent eventually, because modified arithmetic operators test if a symbol can be interpreted as a floating point number.
- aidenn0 6y agoCommon Lisp has a concept of a "potential number" number which is a token that looks numberish, and it permits implementations to have custom numeric literals that are potential numbers. Even then though, if you have e.g. an asterisk or a percent or something it will not be a potential number. http://www.lispworks.com/documentation/HyperSpec/Body/02_caa.htm http://www.lispworks.com/documentation/HyperSpec/Body/02_caa...
- brendyn 6y agoI don't know about lumen, but i think in Scheme a symbol is "just" an immutable string, except that is used in a different ways for different purposes than strings which are for text. Here is Guile Scheme (not sure if this is standard or Guile specific): scheme@(guile-user)> 1e9 $2 = 1.0e9 scheme@(guile-user)> (string->symbol "1e9") $3 = #{1e9}# ;; This the double quote equivalent for symbols. scheme@(guile-user)> (define #{1e9}# "foo") scheme@(guile-user)> #{1e9}# $4 = "foo" As you can see, 1e9 is read as a number, but that does not mean it cannot also be a symbol, it just requires us sneaking around the reader or using the quoting construct.
- jhgb 6y agoLots of things you might want to name have natural names starting with numbers. If you're writing, say, a TSP solver, some of your procedures may be called 2-opt or 3-opt, for example.
- grugagag 6y agoI like that about lisp and surprisingly I came to like the kebab case, i find it quite easy to read at a glance. Before toying with scheme that and the parentheses seemed a bit dated but I came to like them quite a bit