core.match

recur detection logic is too naive

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Critical Critical
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

The following explodes because of the presence of recur:

(defn rec [expr]
  (match expr
         [:global] 'GLOBAL
         [:constant x] x
         [:variable x] x
         [:lazy-variable x] `(deref ~x)
         [:if test if-true if-false] `(if ~(rec test)
                                        ~(rec if-true)
                                        ~(rec if-false))
         [:delist list index] `(get ~(rec list) ~(rec index))
         [:depair pair key] `(get ~(rec pair) ~(match key :first 0 :second 1))
         [:list elements] (map rec elements)
         [:fold-recur index-arg list-sym] `(recur (+ 1 ~index-arg) (rest ~list-sym))
         [:zip left right] `(map vector ~(rec left) ~(rec right))
         [:filter list arg body] `(filter (fn [~arg] ~(rec body) ~(rec list)))
         [:len list] `(count ~(rec list))
         [:pair first second] [(rec first) (rec second)]
         [:block arg body] `(fn [~arg] ~(rec body))
         [:app f arg] `(~(rec f) ~(rec arg))
         [:query e annotations] `(QUERY ~(rec e) ~annotations)
         [:lookup key] `(LOOKUP ~key)
         [:let name value expr] `(let [~name ~value] expr)
         ; ... about 15 more
         ))

Activity

David Nolen made changes -
Field Original Value New Value
Description The following explodes because of the presence of {{recur}}:

{{code}}
(defn rec [expr]
  (match expr
         [:global] 'GLOBAL
         [:constant x] x
         [:variable x] x
         [:lazy-variable x] `(deref ~x)
         [:if test if-true if-false] `(if ~(rec test)
                                        ~(rec if-true)
                                        ~(rec if-false))
         [:delist list index] `(get ~(rec list) ~(rec index))
         [:depair pair key] `(get ~(rec pair) ~(match key :first 0 :second 1))
         [:list elements] (map rec elements)
         [:fold-recur index-arg list-sym] `(recur (+ 1 ~index-arg) (rest ~list-sym))
         [:zip left right] `(map vector ~(rec left) ~(rec right))
         [:filter list arg body] `(filter (fn [~arg] ~(rec body) ~(rec list)))
         [:len list] `(count ~(rec list))
         [:pair first second] [(rec first) (rec second)]
         [:block arg body] `(fn [~arg] ~(rec body))
         [:app f arg] `(~(rec f) ~(rec arg))
         [:query e annotations] `(QUERY ~(rec e) ~annotations)
         [:lookup key] `(LOOKUP ~key)
         [:let name value expr] `(let [~name ~value] expr)
         ; ... about 15 more
         ))
{{code}}
The following explodes because of the presence of {{recur}}:

{code}
(defn rec [expr]
  (match expr
         [:global] 'GLOBAL
         [:constant x] x
         [:variable x] x
         [:lazy-variable x] `(deref ~x)
         [:if test if-true if-false] `(if ~(rec test)
                                        ~(rec if-true)
                                        ~(rec if-false))
         [:delist list index] `(get ~(rec list) ~(rec index))
         [:depair pair key] `(get ~(rec pair) ~(match key :first 0 :second 1))
         [:list elements] (map rec elements)
         [:fold-recur index-arg list-sym] `(recur (+ 1 ~index-arg) (rest ~list-sym))
         [:zip left right] `(map vector ~(rec left) ~(rec right))
         [:filter list arg body] `(filter (fn [~arg] ~(rec body) ~(rec list)))
         [:len list] `(count ~(rec list))
         [:pair first second] [(rec first) (rec second)]
         [:block arg body] `(fn [~arg] ~(rec body))
         [:app f arg] `(~(rec f) ~(rec arg))
         [:query e annotations] `(QUERY ~(rec e) ~annotations)
         [:lookup key] `(LOOKUP ~key)
         [:let name value expr] `(let [~name ~value] expr)
         ; ... about 15 more
         ))
{code}
David Nolen made changes -
Priority Major [ 3 ] Critical [ 2 ]

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated: