Skip to content

Commit

Permalink
Issue #41 - partial solution, simplify nested pairs. EG: (1 . (2 . 3)…
Browse files Browse the repository at this point in the history
… should become (1 2 . 3)
  • Loading branch information
justinethier committed Aug 28, 2011
1 parent be623d5 commit 4c6e152
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 12 additions & 1 deletion hs-src/Language/Scheme/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,18 @@ parseDottedList :: Parser LispVal
parseDottedList = do
phead <- endBy parseExpr whiteSpace
ptail <- dot >> parseExpr --char '.' >> whiteSpace >> parseExpr
return $ DottedList phead ptail
-- return $ DottedList phead ptail
case ptail of
DottedList ls l -> return $ DottedList (phead ++ ls) l
-- TODO: Issue #41 - List l -> return $ List $ phead ++ l
{- Regarding above, see http://community.schemewiki.org/?scheme-faq-language#dottedapp
Note, however, that most Schemes expand literal lists occurring in function applications,
e.g. (foo bar . (1 2 3)) is expanded into (foo bar 1 2 3) by the reader. It is not entirely
clear whether this is a consequence of the standard - the notation is not part of the R5RS
grammar but there is strong evidence to suggest a Scheme implementation cannot comply with
all of R5RS without performing this transformation. -}
_ -> return $ DottedList phead ptail

parseQuoted :: Parser LispVal
parseQuoted = do
Expand Down
4 changes: 4 additions & 0 deletions scm-unit-tests/t-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ a
'(a . 4)
'(a . 4) )

; Cases related to issue #41
(assert/equal '(1 2 . 3) '(1 . (2 . 3)))
(assert/equal '(1 2 . ()) '(1 . (2 . ())))

(unit-test-handler-results)

0 comments on commit 4c6e152

Please sign in to comment.