This page is no longer maintained — Please continue to the home page at www.scala-lang.org

trait Dynamic - why not declare applyDynamic here?

3 replies
H-star Development
Joined: 2010-04-14,
User offline. Last seen 2 years 26 weeks ago.

i've played a bit with the dynamic marker, and wondered: why is it
empty? the doc says

/** A marker trait that enables dynamic invocations. Instances `x` of
this trait
* allow calls `x.meth(args)` for arbitrary method names `meth` and
argument lists
* `args`. If a call is not natively supported by `x`, it is rewritten to
* `x.applyDynamic("meth", args)`.

so i'd say applydynamic should be declared in the dynamic-trait.

odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
Re: trait Dynamic - why not declare applyDynamic here?


On Tue, Sep 6, 2011 at 6:54 AM, HamsterofDeath <h-star [at] gmx [dot] de> wrote:
i've played a bit with the dynamic marker, and wondered: why is it
empty? the doc says

/** A marker trait that enables dynamic invocations. Instances `x` of
this trait
 *  allow calls `x.meth(args)` for arbitrary method names `meth` and
argument lists
 *  `args`.  If a call is not natively supported by `x`, it is rewritten to
 *  `x.applyDynamic("meth", args)`.

so i'd say applydynamic should be declared in the dynamic-trait.

The reason we took it out there was that we did not want to specify a type signature for applyDynamic.

 -- Martin

H-star Development
Joined: 2010-04-14,
User offline. Last seen 2 years 26 weeks ago.
Re: trait Dynamic - why not declare applyDynamic here?
in my case the arguments were wrapped in a List, so i assumed it would always be List[Any]

Am 06.09.2011 21:22, schrieb martin odersky:
CAENVNkYCNb8iRf9dLDuv0X1K4diVbjZEPkWTFsbYXqXVC3pLFg [at] mail [dot] gmail [dot] com" type="cite">

On Tue, Sep 6, 2011 at 6:54 AM, HamsterofDeath <h-star [at] gmx [dot] de" rel="nofollow">h-star [at] gmx [dot] de> wrote:
i've played a bit with the dynamic marker, and wondered: why is it
empty? the doc says

/** A marker trait that enables dynamic invocations. Instances `x` of
this trait
 *  allow calls `x.meth(args)` for arbitrary method names `meth` and
argument lists
 *  `args`.  If a call is not natively supported by `x`, it is rewritten to
 *  `x.applyDynamic("meth", args)`.

so i'd say applydynamic should be declared in the dynamic-trait.

The reason we took it out there was that we did not want to specify a type signature for applyDynamic.

 -- Martin


adriaanm
Joined: 2010-02-08,
User offline. Last seen 31 weeks 4 days ago.
Re: trait Dynamic - why not declare applyDynamic here?
the advantage of not defining applyDynamic explicitly in that trait is that it is thus truly "dynamic": your version may require implicit arguments, type parameters, ... as long as the application (which is spec'ed) type checks, it's all good!
once you put a definition in there, all that freedom is gone, since we don't have polymorphism to abstract over implicit argument *lists* or type parameter lists
cheersadriaan

On Tue, Sep 6, 2011 at 10:35 PM, HamsterofDeath <h-star [at] gmx [dot] de> wrote:
in my case the arguments were wrapped in a List, so i assumed it would always be List[Any]

Am 06.09.2011 21:22, schrieb martin odersky:


On Tue, Sep 6, 2011 at 6:54 AM, HamsterofDeath <h-star [at] gmx [dot] de> wrote:
i've played a bit with the dynamic marker, and wondered: why is it
empty? the doc says

/** A marker trait that enables dynamic invocations. Instances `x` of
this trait
 *  allow calls `x.meth(args)` for arbitrary method names `meth` and
argument lists
 *  `args`.  If a call is not natively supported by `x`, it is rewritten to
 *  `x.applyDynamic("meth", args)`.

so i'd say applydynamic should be declared in the dynamic-trait.

The reason we took it out there was that we did not want to specify a type signature for applyDynamic.

 -- Martin



Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland