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 support for equivalent of C's ptr->field #39

Closed
densh opened this issue May 5, 2016 · 3 comments
Closed

Add support for equivalent of C's ptr->field #39

densh opened this issue May 5, 2016 · 3 comments

Comments

@densh
Copy link
Member

densh commented May 5, 2016

Finding an equivalent for this in Scala is complicated:

  1. We could use a combination of Dynamic and whitebox macros but that would make it unusable in IDEs and not portable to dotty. The syntax would be ptr.field which is not the same but close enough.
  2. If we try to use exactly the same syntax as in C ptr->field, it gets parsed as ptr.->(field), meaning that field has to be in scope, defined somewhere else. I don't really see how can one make it happen without some dark arcane magic (untyped macros?).

Workaround: (!ptr).field. This will load a whole struct and then extract a field from it.

@densh densh added this to the M3 milestone May 5, 2016
@densh
Copy link
Member Author

densh commented May 15, 2016

I've chatted with IntelliJ guys on Scala Days and they say it might be possible to add support for derivation of field types through an official extension mechanism they have. So using a whitebox macro for this seems to be the best way to go so far.

@densh densh modified the milestones: Backlog, M3 May 21, 2016
@densh densh modified the milestones: M4, Backlog Jun 6, 2016
@densh densh added the critical label Jul 15, 2016
@nafg
Copy link

nafg commented Nov 9, 2016

@densh instead of Dynamic, for one extra character how about use Symbols: ptr -> 'field

BTW I don't know C++ so I can only guess what it does

@densh
Copy link
Member Author

densh commented Jan 3, 2017

The eventual solution to this one landed in #472. We make structs anonymous by default and one can access fields via ptr._N where N is the index of the field.

@densh densh closed this as completed Jan 3, 2017
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

2 participants