defrecord recur method head target object

Description

The docstring for defrecord indicates "recur calls to the method head should *not* pass the target object", but in ClojureScript an argument in this position is evidently required, resulting in a discrepancy relative to Clojure.

Example code:

And its use:

yield 1 and nil respectively in Clojure.

If you attempt to compile the Search defrecord in ClojureScript, you will get "recur argument count mismatch at line 7".

It appears that this can be fixed in the example code by simply adding a dummy value for the first argument to recur (it can even be nil and doesn't have to be this).

This ticket requests that this be fixed to match Clojure. Since this would be a breaking change, perhaps legacy code could be accepted while simultaneously emitting a warning diagnostic.

Environment

None

Attachments

1

Activity

Show:

Mike Fikes June 15, 2017 at 8:07 PM

The attached patch should allow any code implementing protocol methods, via defrecord, extend-type, reify, etc. that passes a target object to be accepted with a warning diagnostic. It also accepts code that omits the target object (i.e., the way the Clojure compiler does). This should eliminate this difference from Clojure without being a breaking change for existing ClojureScript code that recurs to protocol method heads.

An example warning (taken from the tests) looks like this:

where the target object indicated in quotes is actually the form for the first expression being passed to recur.

David Nolen June 14, 2017 at 2:18 PM

Yes warning diagnostic desirable in this case.

Completed

Details

Assignee

Reporter

Patch

Code and Test

Priority

Created June 14, 2017 at 3:15 AM
Updated June 15, 2017 at 10:31 PM
Resolved June 15, 2017 at 10:31 PM