Clojure

State function's unmunged full name in compiled function's toString()

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: Release 1.5
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Patch:
    Code and Test
  • Approval:
    Triaged

Description

Currently function instances print their toString() with the munged Java name:

user=> (ns proj.util-fns)
nil
proj.util-fns=> (defn a->b [a] (inc a))
#'proj.util-fns/a->b
proj.util-fns=> a->b
#object[proj.util_fns$a__GT_b 0x141ba1f1 "proj.util_fns$a__GT_b@141ba1f1"]

For debugging purposes, it would be useful to have the function toString() describe the Clojure-oriented fn name.

Approach: Store the original name in the function instance and use it in the toString() rather than returning the class name.

proj.util-fns=> a->b
#object[proj.util_fns$a__GT_b 0x47d1a507 "proj.util-fns/a->b(NO_SOURCE_FILE:2)"]

Tradeoffs: Increased function instance size for the function name.

Patch: CLJ-1278-2.patch

  1. CLJ-1278-2.patch
    11/Oct/13 6:26 PM
    5 kB
    Howard Lewis Ship
  2. CLJ-1528--function-tostring.patch
    10/Oct/13 8:39 PM
    6 kB
    Howard Lewis Ship

Activity

Howard Lewis Ship made changes -
Field Original Value New Value
Attachment CLJ-1528--function-tostring.patch [ 12311 ]
Howard Lewis Ship made changes -
Attachment CLJ-1278-2.patch [ 12317 ]
Andy Fingerhut made changes -
Patch Code and Test [ 10002 ]
Howard Lewis Ship made changes -
Description Clojure functions do not provide a useful override of the default Java Object.toString() method.

Because of this, any time a Clojure function is printed out, it places a load on the develop to mentally reverse the necessary name mangling to get back to the namespace and function name.

I would vastly prefer better information here: the non-mangled name of the function, including namespace and, ideally, a little bit of the available meta-data: the file name and line number.

In other words, instead of {{novate.core.processing.async$locate_destination@2690d691}} something more like {{novate.core.processing.async/locate-destination(async.clj:231)}}.

Ideally, anything that is code generated as a class should implement a useful {{toString()}}. It would be nice if reified types could identify the containing namespace and function (and file/line number) as part of their default {{toString()}}.

I suspect this would need to be controlled by a compiler option as it would slightly increase the generated bytecode size, and (imperceptably?) affect compilation speed.
For debugging purposes, it would be useful to have Clojure-oriented toString() for functions.

{noformat}
novate.core.processing.async/locate-destination(async.clj:231)
{noformat}
instead of:
{noformat}
novate.core.processing.async$locate_destination@2690d691
{noformat}

This would remove the frustration of mentally de-mangling the function name from the Java class name.

This will have a relatively insignificant change to the generated code: An implementation of the toString() method. This will add a few dozen bytes to the size of a compiled Clojure function (for the additional bytecodes, and the constant string).
Howard Lewis Ship made changes -
Summary Provide a useful implementation of toString() for Clojure functions Identify Clojure namespace and function name in a compiled function's toString()
Alex Miller made changes -
Approval Triaged [ 10120 ]
Priority Minor [ 4 ] Major [ 3 ]
Alex Miller made changes -
Description For debugging purposes, it would be useful to have Clojure-oriented toString() for functions.

{noformat}
novate.core.processing.async/locate-destination(async.clj:231)
{noformat}
instead of:
{noformat}
novate.core.processing.async$locate_destination@2690d691
{noformat}

This would remove the frustration of mentally de-mangling the function name from the Java class name.

This will have a relatively insignificant change to the generated code: An implementation of the toString() method. This will add a few dozen bytes to the size of a compiled Clojure function (for the additional bytecodes, and the constant string).
Currently function instances print their toString() with the munged Java name:

{code}
user=> (ns proj.util-fns)
nil
proj.util-fns=> (defn a->b [a] (inc a))
#'proj.util-fns/a->b
proj.util-fns=> a->b
#object[proj.util_fns$a__GT_b 0x141ba1f1 "proj.util_fns$a__GT_b@141ba1f1"]
{code}

For debugging purposes, it would be useful to have the function toString() describe the Clojure-oriented fn name.

*Approach:* Store the original name in the function instance and use it in the toString() rather than returning the class name.

*Tradeoffs:* Increased function instance size for the function name.

*Patch:* CLJ-1278-2.patch
Summary Identify Clojure namespace and function name in a compiled function's toString() State function's unmunged full name in compiled function's toString()
Alex Miller made changes -
Description Currently function instances print their toString() with the munged Java name:

{code}
user=> (ns proj.util-fns)
nil
proj.util-fns=> (defn a->b [a] (inc a))
#'proj.util-fns/a->b
proj.util-fns=> a->b
#object[proj.util_fns$a__GT_b 0x141ba1f1 "proj.util_fns$a__GT_b@141ba1f1"]
{code}

For debugging purposes, it would be useful to have the function toString() describe the Clojure-oriented fn name.

*Approach:* Store the original name in the function instance and use it in the toString() rather than returning the class name.

*Tradeoffs:* Increased function instance size for the function name.

*Patch:* CLJ-1278-2.patch
Currently function instances print their toString() with the munged Java name:

{code}
user=> (ns proj.util-fns)
nil
proj.util-fns=> (defn a->b [a] (inc a))
#'proj.util-fns/a->b
proj.util-fns=> a->b
#object[proj.util_fns$a__GT_b 0x141ba1f1 "proj.util_fns$a__GT_b@141ba1f1"]
{code}

For debugging purposes, it would be useful to have the function toString() describe the Clojure-oriented fn name.

*Approach:* Store the original name in the function instance and use it in the toString() rather than returning the class name.

{code}
proj.util-fns=> a->b
#object[proj.util_fns$a__GT_b 0x47d1a507 "proj.util-fns/a->b(NO_SOURCE_FILE:2)"]
{code}

*Tradeoffs:* Increased function instance size for the function name.

*Patch:* CLJ-1278-2.patch

People

Vote (9)
Watch (1)

Dates

  • Created:
    Updated: