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

new constructor from instance method #123

Open
aep opened this issue Sep 15, 2020 · 6 comments
Open

new constructor from instance method #123

aep opened this issue Sep 15, 2020 · 6 comments
Labels
enhancement New feature or request

Comments

@aep
Copy link
Collaborator

aep commented Sep 15, 2020

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.

@aep aep mentioned this issue Sep 15, 2020
@jwerle jwerle added the enhancement New feature or request label Sep 15, 2020
@aep
Copy link
Collaborator Author

aep commented Sep 15, 2020

@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
{
   
}

@jwerle
Copy link
Member

jwerle commented Sep 15, 2020

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 ;)

@aep
Copy link
Collaborator Author

aep commented Sep 15, 2020

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

@jwerle
Copy link
Member

jwerle commented Sep 15, 2020

yeah something short and sweet

@aep
Copy link
Collaborator Author

aep commented Sep 16, 2020

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

@jwerle
Copy link
Member

jwerle commented Sep 16, 2020

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants