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

Functions returning objects or records #18

Open
rascala opened this issue Jun 22, 2017 · 10 comments
Open

Functions returning objects or records #18

rascala opened this issue Jun 22, 2017 · 10 comments

Comments

@rascala
Copy link
Contributor

rascala commented Jun 22, 2017

Hi,

I have been looking at implementing the Regex module.
How would I go about returning objects?
(ex: Match object, with .Success, .Groups, .Captures etc.)

Do I just return a map or a record?

@kjnilsson
Copy link
Owner

A record might work. Depends on what data you need.

@kjnilsson
Copy link
Owner

The type you return is effectively opaque to the caller as it will be passed to the member function as it's first parameter. I'd suggest you write a simple example. compile it and look at the .core file to see what it is doing.

@rascala
Copy link
Contributor Author

rascala commented Jun 23, 2017

Thanks, will give it a try

@rascala
Copy link
Contributor Author

rascala commented Jun 30, 2017

Sorry, been a bit busy!

Still having some trouble with this.
The core file seems to generate a get_<field-name> function.
So using var.Groups in f# seems to generate

'System.Text.RegularExpressions.Match':get_Groups(#{'Captures' => [],'Groups' => [],'Length' => 0,'Success' => false,
  'Value' => ''})

which does not exist

Using a record also results in a get_Groups({some, tuple, here})

Any pointers?

@kjnilsson
Copy link
Owner

kjnilsson commented Jun 30, 2017 via email

@kjnilsson
Copy link
Owner

You probably want to pull the latest changes As there are potential changes to how objects are constructed.

@kjnilsson
Copy link
Owner

@rascala
Copy link
Contributor Author

rascala commented Jul 2, 2017

Thanks,

I have a very basic regex working(without global-match etc.), but its very ugly with different files for Capture/CaptureCollection/Group/GroupCollection/Match/Regex types and respective get_<field>s all over.
But it works! And returns captured groups and their values etc.

I will try to clean them up a bit, add more tests and add the match-options.

Wouldn't it be cleaner if all System.Text.RegularExpressions/* files were grouped into a separate directory?
And maybe all these should be grouped into a lib/stdlib directory? So that src does not get cluttered?

@kjnilsson
Copy link
Owner

kjnilsson commented Jul 2, 2017 via email

@kjnilsson
Copy link
Owner

@rascala I just made some significant changes to how functions and modules are generated which may affect the work you have in progress. I'd recommend you pull and check the .core files to see what modules and names are required.

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

No branches or pull requests

2 participants