ClojureScript

Simplify the dot access special form.

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

Currently ClojureScript provides the following dot access syntaxes:

(.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:

(.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. This ticket would shorten the gap between Clojure and ClojureScript in the following way (ClojureScript proposal below):

(.m o)           ;=> a method call

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

(. o m)          ;=> a method call

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

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

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

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

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

This would be a breaking change, but would shorten the divergence between Clojure and ClojureScript.

Activity

Chas Emerick made changes -
Field Original Value New Value
Comment [ You probably already know, but Clojure already has a {{(. o :p)}} form for field access:

{code}
=> (. (java.awt.GridBagConstraints.) :gridx)
-1
{code}

I don't think it has ever been documented anywhere, but it was added (IIRC) to disambiguate a field access from a call of a no-arg method of the same name as the field — not so different as the proposed syntax here.

Perhaps this is a separate issue, but will {{(. o :p)}} emit {{o['p']}} or {{o.p}}? Right now, {{(.p o)}} emits the latter, which ends up being "optimized" (broken) by gclosure advanced, so {{aget}} ends up being necessary in many scenarios. ]
Fogus made changes -
Description Currently ClojureScript provides the following dot access syntaxes:

{noformat}
(.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
{noformat}


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

{noformat}
(.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
{noformat}

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. This ticket would shorten the gap between Clojure and ClojureScript in the following way (ClojureScript proposal below):

{noformat}
(.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
{noformat}

This would be a breaking change, but would shorten the divergence between Clojure and ClojureScript.
Currently ClojureScript provides the following dot access syntaxes:

{noformat}
(.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
{noformat}


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

{noformat}
(.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
{noformat}

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. This ticket would shorten the gap between Clojure and ClojureScript in the following way (ClojureScript proposal below):

{noformat}
(.m o) ;=> a method call

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

(. o m) ;=> a method call

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

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

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

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

(. o -p) ;=> a property access
{noformat}

This would be a breaking change, but would shorten the divergence between Clojure and ClojureScript.
David Nolen made changes -
Resolution Completed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
David Nolen made changes -
Status Resolved [ 5 ] Closed [ 6 ]

People

Vote (2)
Watch (4)

Dates

  • Created:
    Updated:
    Resolved: