git.iko.soy/rowtype-yoga/purescm
on bytevector help sign in
Fix self recursive single let binding (#143)
commit14ab2636b23b6208decf72a01a43a553dab6832b authorAntti Holvikari <antti@anttih.com> dateWed 12 Jul 2023, 17:06 (3 years ago) parent06e7b08
3 files changed+13−7
src/PureScript/Backend/Chez/Printer.purs+4−1 test-snapshots/src/snapshots-input/Snapshot.Let.purs+4−3 test-snapshots/src/snapshots-output/Snapshot.Let.ss+5−3
src/PureScript/Backend/Chez/Printer.purs+4−1
@@ -293,12 +293,15 @@ printLet recursive bindings' expr = do
293293 multiLetKeyword
294294 | recursive = D.text $ scmPrefixed "letrec*"
295295 | otherwise = D.text $ scmPrefixed "let*"
296+ singleLetKeyword
297+ | recursive = D.text $ scmPrefixed "letrec"
298+ | otherwise = D.text $ scmPrefixed "let"
296299 printBinding (Tuple b e) = printBrackets $ D.words [ D.text b, printChezExpr e ]
297300
298301 case NEA.uncons bindings' of
299302 { head, tail: [] } ->
300303 D.lines
301− [ D.text "(" <> D.words [ D.text (scmPrefixed "let"), printList $ printBinding head ]
304+ [ D.text "(" <> D.words [ singleLetKeyword, printList $ printBinding head ]
302305 , D.indent $ printChezExpr expr <> D.text ")"
303306 ]
304307 { head, tail } ->
test-snapshots/src/snapshots-input/Snapshot.Let.purs+4−3
@@ -13,9 +13,10 @@ letChain x =
1313 a + b + c + d
1414
1515letRecursive :: Int -> Int
16−letRecursive x
17− | x == 0 = 0
18− | otherwise = letRecursive (x - 1)
16+letRecursive x = go x
17+ where
18+ go 0 = 0
19+ go x' = go (x' - 1)
1920
2021isEven :: Int -> Boolean
2122isEven x
test-snapshots/src/snapshots-output/Snapshot.Let.ss+5−3
@@ -13,9 +13,11 @@
1313
1414 (scm:define letRecursive
1515 (scm:lambda (x0)
16− (scm:cond
17− [(scm:fx=? x0 0) 0]
18− [scm:else (letRecursive (scm:fx- x0 1))])))
16+ (scm:letrec ([go1 (scm:lambda (v2)
17+ (scm:cond
18+ [(scm:fx=? v2 0) 0]
19+ [scm:else (go1 (scm:fx- v2 1))]))])
20+ (go1 x0))))
1921
2022 (scm:define letChain
2123 (scm:lambda (x0)