Error formatting macro: pagetree: java.lang.NullPointerException

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Problem

There is currently no unified field access syntax between Clojure and ClojureScript.

(covered by ticket CLJS-89)

Currently ClojureScript provides the following dot access syntaxes:

No Format
(.p o)           ;=> a property access

(.m o <args>)    ;=> a method call

(. o p)          ;=> a property access

(. o p <args>)   ;=> a method call

(. o (m))        ;=> a method call

(. o (m <args>)) ;=> a method call

This is potentially confusing. Especially considering that Clojure looks as follows:

No Format
(.p o)           ;=> a property access if p is a property

(.p o)           ;=> a method call if p is a method

(.m o <args>)    ;=> a method call

(. o p)          ;=> a property access if p is a property

(. o p)          ;=> a method call if p is a method

(. o p <args>)   ;=> a method call

(. o (m))        ;=> a method call

(. o (m <args>)) ;=> a method call

The divergence between the Clojure and ClojureScript way is due to first-class functions. That is, in JavaScript a property can be a field or a function or a method. There is currently no way to distinguish between the desire to call a method and retrieve a function as a property except through syntax.

Potential Solution

A way to shorten the gap between Clojure and ClojureScript is to use the following syntax for ClojureScript:

No Format
(.p o)           ;=> a method call

(.m o <args>)    ;=> a method call

(. o p)          ;=> a method call

(. o p <args>)   ;=> a method call

(. o (m))        ;=> a method call

(. o (m <args>)) ;=> a method call

(. o :p)         ;=> a property access

Thus reserving the single keyword form for property access.  This functionality should also be enhanced in Clojure (as it currently exists, but not optimally so).  This would require a breaking change in ClojureScript and an enhancement to Clojure.