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

add @something! for updating the first arg to something #45586

Closed

Conversation

IanButterworth
Copy link
Member

I find that most of the time I use @something is like

x = @something x y z

This adds @something! so you can just do this, and the first arg value is updated

@something! x y z

Original PR for @something #40729

@IanButterworth IanButterworth requested a review from omus June 5, 2022 02:47
@jakobnissen
Copy link
Contributor

Are there situations where this makes a problem easier to solve? I'm not entirely convinced it's worth it to save 2 ASCII characters.

@fredrikekre
Copy link
Member

I don't like implicit variables like this, and current tooling (at least the LanguageServer stack) can't understand it since it doesn't expand macros.

@IanButterworth
Copy link
Member Author

Are there situations where this makes a problem easier to solve? I'm not entirely convinced it's worth it to save 2 ASCII characters.

It's more of a formatting bother if the first arg has a long name, which means more than 2 chars.

I hoped this would be considered reasonably standard behavior to understand/expect, indicated by the !, but I guess the issue is that reassignment isn't the same as mutation.

The point about tooling is fair, but alone I think it would be a shame to limit language features based on current tooling limitations. But if the concept isn't popular that point is moot.

Copy link
Member

@omus omus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also unconvinced that this addition is worth including in Base

"""
macro something!(args...)
length(args) < 2 && return :(throw(ArgumentError("Two or more arguments must be provided")))
first(args) isa Symbol || return :(throw(ArgumentError("The first argument must be a variable")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs tests for this case

@IanButterworth
Copy link
Member Author

Ok, happy to let this pass given it's not popular

@IanButterworth IanButterworth deleted the ib/something_reassign branch June 10, 2022 21:02
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.

4 participants