Is this a 9.3.1 multiple dispatch problem?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Is this a 9.3.1 multiple dispatch problem?

Ari Najarian
Hi all,

  Once I got 9.3.1 working on my machine, I started going through a few of my projects and seeing if there were any problems with them. Most of the code worked fine, but some of my more tangled OO code is giving me this error:

Definition Not Found: CouchCMS_field->oncreate(-key=string, -options=map) Candidates were: null->oncreate(), CouchCMS_field->oncreate(-key::string, -options::map)

I read through the conversation in this issue: http://www.lassosoft.com/rhinotrac?id=7945
And looked at this thread: http://www.lassotalk.com/Re-Multiple-Dispatch-in-9-3.lasso?277782
And read through http://lassoguide.com/language/methods.html#multiple-dispatch

My use case that generated the error above is similar to Steve Piercy’s in the linked thread: I’m trying to fall back to the parent type’s ->onCreate method, so the child type’s ->onCreate is simply passing parameters to its parent (an ‘alias’).

Here are the relevant code blocks:

// The offending call:
CouchCMS_field_calculation( -key="slug")


// The (abridged) parent type:
define CouchCMS_field => type {

  data public key
  data public options::map=map
  ...
  public onCreate(-key::string, -options::map=map) => {
    with i in #options->keys do {.options->insert(#i = #options->find(#i))}
      .key = #key;
      ...
  }
}

// The (abridged) child type
define CouchCMS_field_calculation => type {

  parent CouchCMS_field
  ...
  public onCreate(-key::string, -options::map=map("options"=array)) => inherited->onCreate(-key=#key, -options=#options)
}

This code was never tested on 9.2, but was written for 9.3.0 and has worked in production for months. CouchCMS_field has, like, 30 different children, some of which override the onCreate method entirely, some of which do some preprocessing before delegating up and some which are purely pass-through. Does this error (or others similar to it) look familiar to anybody? Does something about my code immediately jump out as the culprit regarding multiple dispatch?

Any insight would be much appreciated!




#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Is this a 9.3.1 multiple dispatch problem?

Ke Carlton-3
These signatures conflict:

public oncreate() => {}
public oncreate(-keywordparam = '') => {}

Keyword parameters are not used when it comes to signature matching, from
the docs:

"Keyword parameters are never considered during the method selection
process until the end where the single remaining method’s keyword
parameters (if any) are validated. Two methods cannot differentiate
themselves based on accepting a different set of keyword parameters.
Methods must be distinguished based solely on their required or optional
parameters."

So remove the oncreate() method and handle no parameters within the named
parameter version.

I think you need to restart Lasso in order to replace the type — this is a
bug.

Ke






On Thu, Jan 21, 2016 at 5:51 AM Ari Najarian <[hidden email]> wrote:

> Hi all,
>
>   Once I got 9.3.1 working on my machine, I started going through a few of
> my projects and seeing if there were any problems with them. Most of the
> code worked fine, but some of my more tangled OO code is giving me this
> error:
>
> Definition Not Found: CouchCMS_field->oncreate(-key=string, -options=map)
> Candidates were: null->oncreate(), CouchCMS_field->oncreate(-key::string,
> -options::map)
>
> I read through the conversation in this issue:
> http://www.lassosoft.com/rhinotrac?id=7945
> And looked at this thread:
> http://www.lassotalk.com/Re-Multiple-Dispatch-in-9-3.lasso?277782
> And read through
> http://lassoguide.com/language/methods.html#multiple-dispatch
>
> My use case that generated the error above is similar to Steve Piercy’s in
> the linked thread: I’m trying to fall back to the parent type’s ->onCreate
> method, so the child type’s ->onCreate is simply passing parameters to its
> parent (an ‘alias’).
>
> Here are the relevant code blocks:
>
> // The offending call:
> CouchCMS_field_calculation( -key="slug")
>
>
> // The (abridged) parent type:
> define CouchCMS_field => type {
>
>   data public key
>   data public options::map=map
>   ...
>   public onCreate(-key::string, -options::map=map) => {
>     with i in #options->keys do {.options->insert(#i = #options->find(#i))}
>       .key = #key;
>       ...
>   }
> }
>
> // The (abridged) child type
> define CouchCMS_field_calculation => type {
>
>   parent CouchCMS_field
>   ...
>   public onCreate(-key::string, -options::map=map("options"=array)) =>
> inherited->onCreate(-key=#key, -options=#options)
> }
>
> This code was never tested on 9.2, but was written for 9.3.0 and has
> worked in production for months. CouchCMS_field has, like, 30 different
> children, some of which override the onCreate method entirely, some of
> which do some preprocessing before delegating up and some which are purely
> pass-through. Does this error (or others similar to it) look familiar to
> anybody? Does something about my code immediately jump out as the culprit
> regarding multiple dispatch?
>
> Any insight would be much appreciated!
>
>
>
>
> #############################################################
>
> This message is sent to you because you are subscribed to
>   the mailing list Lasso [hidden email]
> Official list archives available at http://www.lassotalk.com
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Is this a 9.3.1 multiple dispatch problem?

Ari Najarian
In reply to this post by Ari Najarian
So, on a whim (and with no expectation that it might work), I did a find-and-replace-all on my whole codebase, changing all instances of:

  public onCreate(-key::string, -options::map=map) => {

  to

  public onCreate(key::string, -options::map=map) => {

  and then changed all function calls to omit the first keyword name, passing a string parameter, e.g.: CouchCMS_field_calculation("slug”)

  Lo and behold, the app is functioning again. I guess whatever changes to multiple dispatch were introduced in 9.3.1 changed the way that candidate methods are rated, and put keyword-only parameters on-par with an empty parameter list. Hence, null->onCreate was a legitimate competitor to ->onCreate(-x,-y).

  I *did* like the fact that I could pass all named keyword parameters to my methods, since it made my code much more readable and accessible to newcomers. While it’s not a huge deal, this was a feature that I used deliberately.

  I see in Rhinotrac that Kyle reverted (regressed?) the multiple dispatch behaviour in 9.3.1. Reading the discussion, it’s unclear to me whether the ambiguous behaviour of 9.2 is more desirable than 9.3.0. It’s also unclear whether the issue has been resolved permanently or not. In the meantime, I’ll ensure that my methods always include at least one non-keyword parameter or an empty ->onCreate method.

  Thanks for the help!




#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Is this a 9.3.1 multiple dispatch problem?

Tim Taplin
You can still use named parameters, just keyword named parameters are not used in multiple dispatch comparisons, since by definition they can be anywhere in the signature.

so, if your concern is readability, use named parameters in your usage.

Tim Taplin

> On Jan 21, 2016, at 8:52 AM, Ari Najarian <[hidden email]> wrote:
>
> So, on a whim (and with no expectation that it might work), I did a find-and-replace-all on my whole codebase, changing all instances of:
>
>  public onCreate(-key::string, -options::map=map) => {
>
>  to
>
>  public onCreate(key::string, -options::map=map) => {
>
>  and then changed all function calls to omit the first keyword name, passing a string parameter, e.g.: CouchCMS_field_calculation("slug”)
>
>  Lo and behold, the app is functioning again. I guess whatever changes to multiple dispatch were introduced in 9.3.1 changed the way that candidate methods are rated, and put keyword-only parameters on-par with an empty parameter list. Hence, null->onCreate was a legitimate competitor to ->onCreate(-x,-y).
>
>  I *did* like the fact that I could pass all named keyword parameters to my methods, since it made my code much more readable and accessible to newcomers. While it’s not a huge deal, this was a feature that I used deliberately.
>
>  I see in Rhinotrac that Kyle reverted (regressed?) the multiple dispatch behaviour in 9.3.1. Reading the discussion, it’s unclear to me whether the ambiguous behaviour of 9.2 is more desirable than 9.3.0. It’s also unclear whether the issue has been resolved permanently or not. In the meantime, I’ll ensure that my methods always include at least one non-keyword parameter or an empty ->onCreate method.
>
>  Thanks for the help!
>
>
>
>
> #############################################################
>
> This message is sent to you because you are subscribed to
>  the mailing list Lasso [hidden email]
> Official list archives available at http://www.lassotalk.com
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>


#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>