~technomancy/fennel

3da46828ca548797300e57e928185f6815fe7956 — Phil Hagelberg 2 months ago 797bee6
Collapse multiple values in non-tail positions in arithmetic specials.

In the tail position, multiple values can all be considered. But when
multiple values are in a non-tail position, the behavior with specials
should match that of functions.

    (and true (values true false) true) ; -> true

See https://todo.sr.ht/~technomancy/fennel/83
2 files changed, 5 insertions(+), 2 deletions(-)

M src/fennel/specials.fnl
M test/core.fnl
M src/fennel/specials.fnl => src/fennel/specials.fnl +2 -1
@@ 781,7 781,8 @@ Method name doesn't have to be known at compile-time; if it is, use
  (let [len (length ast) operands []
        padded-op (.. " " name " ")]
    (for [i 2 len]
      (let [subexprs (compiler.compile1 (. ast i) scope parent {: nval})]
      (let [subexprs (compiler.compile1 (. ast i) scope parent
                                        {:nval (if (< i len) 1)})]
        (utils.map subexprs tostring operands)))
    (match (length operands)
      0 (utils.expr (doto zero-arity

M test/core.fnl => test/core.fnl +3 -1
@@ 28,7 28,9 @@
               "(or false nil true 12 false)" true
               "(or)" false
               "(and (values))" true
               "(and true true (values))" true}]
               "(and true true (values))" true
               "(and true (values true false) true)" true
               "(and true (values true false))" false}]
    (each [code expected (pairs cases)]
      (l.assertEquals (fennel.eval code {:correlate true}) expected code))))