Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser: implement fn name using keyword #22501

Merged
merged 1 commit into from
Oct 12, 2024

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Oct 12, 2024

This PR implement fn name using keyword.

  • Implement fn name using keyword.
  • Add test.
struct Foo {}

fn (f Foo) lock() int {
	return 22
}

fn (f Foo) mut() bool {
	return true
}

fn select() bool {
	return true
}

fn lock[T](t T) T {
	return t
}

fn match() bool {
	return true
}

fn main() {
	f := Foo{}
	assert select()
	assert match()

	assert lock[int](22) == 22
	assert lock(22) == 22
	assert lock[string]('hello') == 'hello'
	assert lock('hello') == 'hello'

	assert f.lock() == 22
	assert f.mut()
}

PS D:\Test\v\tt1> v run .  

@spytheman
Copy link
Member

Why though?

That is introducing more context sensitivity in the parser.

It will make all tooling harder to make, and the parsing potentially slower.

Is the benefit of being able to fn mut() {} for example, worth it?

@yuyi98
Copy link
Member Author

yuyi98 commented Oct 12, 2024

Sorry, I just don't like the following

	cb.mutex.@lock()
        ...
fn (mut s UdpSocket) @select(test Select, timeout time.Duration) !bool {
	return @select(s.handle, test, timeout)
}

I think it should be more user-friendly.

@spytheman
Copy link
Member

I think it should be more user-friendly.

I understand, but I see positives and negatives to both viewpoints, so I can not decide :-| .

@medvednikov what do you think?

@medvednikov
Copy link
Member

I agree with both of you.

I hate mutex.@lock and @select.

I also don't like the possible confusion it can introduce.

I'm going to merge it however. Great job!

@medvednikov medvednikov merged commit e1e44e3 into vlang:master Oct 12, 2024
78 checks passed
@yuyi98 yuyi98 deleted the implement_fn_name_same_as_keyword branch October 12, 2024 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants