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

Тип "ссылка" #159

Open
impworks opened this issue May 27, 2014 · 2 comments
Open

Тип "ссылка" #159

impworks opened this issue May 27, 2014 · 2 comments
Assignees
Milestone

Comments

@impworks
Copy link
Owner

Бывают моменты, когда хочется передать свойство по ссылке, и компилятор логично не дает этого сделать. Или же, нужно написать код наподобие этого:

if(...)
    SomeType.SomeData += var.Field;
else if (...)
    SomeType.SomeOtherData += var.Field;
else if (...)
    SomeType.YetAnotherData += var.Field;

Для решения обоих вопросов можно было бы добавить стандартный тип, например Ref<T>, хранящий геттер и сеттер с помощью замыканий.

Например, следующий код:

var x = refto SomeType::Value
x = x + 1

Транслировался бы в:

var x = new Ref<int> (-> SomeType::Value) (v -> SomeType::Value = v)
x.Set (x.Get () + 1)
@impworks impworks added this to the Backlog milestone May 27, 2014
@impworks impworks added the task label May 27, 2014
@impworks impworks self-assigned this May 27, 2014
@impworks impworks modified the milestones: Minor 4.1, Backlog Jan 17, 2015
@impworks
Copy link
Owner Author

Вариант с сокращенным присваиванием не годится: непонятно, как отличать x от x.Get () - например, при передаче в функцию. Так что оставляет только короткую запись с авто-лямбдами, а методы Get и Set оставляем как есть.

Нужно другое ключевое слово вместо refto - оно слишком близко к ref.

@impworks
Copy link
Owner Author

impworks commented Oct 3, 2017

Кстати говоря, в Scala эта концепция называется Lens :)

http://julien-truffaut.github.io/Monocle/

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

No branches or pull requests

1 participant