register can't register symbols that start with numerals
to reproduce:
(register 1Foo Int "1Foo")
I think this is because it’s parsed as (register 1 Foo Int "1Foo").
See also:
> (+ 1x)
Can't find symbol 'x' at REPL:3:5.
Traceback:
(+ 1 x) at REPL:3:1.
> (defdynamic x 1)
> (+ 1x)
=> 2
ahhh good catch--we probably shouldn't inject the whitespace right? Or is there good reason to keep that behavior?
I think this an outcome of
https://github.com/carp-lang/Carp/blob/3522b0ad982006cd3ea577d1f23d8f033a0cad96/src/Parsing.hs#L590-L593
which is the only occurrence of whitespaceOrNothing. So it’s definitely intentional. My guess is that this is to allow for things such as (define x 1)(+ x 1) (notice that there is no space between the two forms). Some forms, like arrays and lists do not need them to be logically separated. Some do. I’m not sure how to best resolve this; maybe switch to two classes of parse expressions like this?
needsWhitespace :: Parsec.Parsec String ParseState XObj
needsWhitespace = do
x <- Parsec.choice [ref, deref, copy, quote, quasiquote, unquoteSplicing, unquote, atom]
_ <- whitespace
pure x
selfClosing :: Parsec.Parsec String ParseState XObj
selfClosing = do
x <- Parsec.choice [list, staticArray, array, dictionary]
_ <- whitespaceOrNothing
pure x
sexpr :: Parsec.Parsec String ParseState XObj
sexpr = Parsec.choice [selfClosing, needsWhitespace]
That makes sense, could we solve it with lookahead? if the next char is not any of ()[], parse it as a symbol?
Or rather the rule for symbols could just be any number of chars until whitespace occurs.