8000 new constructor from instance method · Issue #123 · zetzit/zz · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jun 17, 2022. It is now read-only.
This repository was archived by the owner on Jun 17, 2022. It is now read-only.

new constructor from instance method #123

Open

Description

@aep

this doesn't work, but it should

struct A{};
struct B{};
fn to(A mut*self, B mut new*nu) {}
fn main() {
   A a;
   new b = a.to();
}

the reason it's currently broken is actually generated tail arguments make argument ordering a mess.
I want to get rid of auto-generated tail arguments anyway in favor of generic call-site assigns.

Activity

  1. aep commented on Sep 15, 2020

    @aep
    CollaboratorAuthor

    @jwerle

    opinions on syntax for callsite assigns?

    fn foh(int a, int b, char * other)
       where a > 2
       with b = 2 * a
    {
       
    }
    fn foh(int a, int b, char * other)
       where a > 2
       where b = 2 * a
    {
       
    }
    fn foh(int a, int b = 2 * a, char * other)
       where a > 2
    {
       
    }

    all of these are used by skipping the callsite arg:

    fn main() {
      foh(2, "boh");
    }

    and i feel like the last version makes that more obvious, although long expressions can look hard to read

    fn foh(int a, int b = if constrained(typeof(vec::itema))) { vec::item(a) } else { u8 } , char * other)
       where a > 2
    {
       
    }
  2. jwerle commented on Sep 15, 2020

    @jwerle
    Member
    fn foh(int a, int b, char * other)
       where a > 2
       with b = 2 * a
    {
       
    }

    I like with

    fn foh(int a, int b, char * other)
       where a > 2
       where b = 2 * a
    {
       
    }

    but I also like where...

    fn foh(int a, int b = 2 * a, char * other)
       where a > 2
    {
       
    }

    This is very easy to understand

    fn main() {
      foh(2, "boh");
    }

    but I can see a reader having to come back to understand how it is used. Is there a keyword we could introduce in the argument signature the denotes the variable as a callsite argument?

    fn foh(int a, int b = if constrained(typeof(vec::itema))) { vec::item(a) } else { u8 } , char * other)
       where a > 2
    {
       
    }

    oof! yeah that is hard to read ;)

  3. aep commented on Sep 15, 2020

    @aep
    CollaboratorAuthor

    Is there a keyword we could introduce in the argument signature the denotes the variable as a callsite argument?

    yeah. probably we want that plus the full expression in the smt section, since its an smt expression, so...

    fn foh(int a, callsite int b, char * other)
       where a > 2
       where b = 2 * a
    {
       
    }

    or something. not sure about the keyword. this is too long

  4. jwerle commented on Sep 15, 2020

    @jwerle
    Member

    yeah something short and sweet

  5. aep commented on Sep 16, 2020

    @aep
    CollaboratorAuthor

    actually skipping arguments in the middle is weird anyway. I'm going to require callsite arguments be at the end, which makes them very similar to default arguments in other languages, so we're also going with that familiar syntax

  6. jwerle commented on Sep 16, 2020

    @jwerle
    Member

    yep that makes a lot more sense and we can avoid the extra keyword for the reader!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0