fez icon indicating copy to clipboard operation
fez copied to clipboard

Functions returning objects or records

Open rascala opened this issue 7 years ago • 10 comments

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?

rascala avatar Jun 22 '17 21:06 rascala

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

kjnilsson avatar Jun 22 '17 21:06 kjnilsson

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.

kjnilsson avatar Jun 23 '17 08:06 kjnilsson

Thanks, will give it a try

rascala avatar Jun 23 '17 10:06 rascala

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?

rascala avatar Jun 30 '17 16:06 rascala

Yes you need to implement the function as generated as an erlang module in src On Fri, 30 Jun 2017 at 17:59, rascala [email protected] wrote:

Sorry, been a bit busy!

Still having some trouble with this. The core file seems to generate a get_ 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?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/kjnilsson/fez/issues/18#issuecomment-312320363, or mute the thread https://github.com/notifications/unsubscribe-auth/ABIDlIAZSYNIR3GU8QFnaMVnLqeOAlm0ks5sJSmFgaJpZM4OC2jf .

kjnilsson avatar Jun 30 '17 19:06 kjnilsson

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

kjnilsson avatar Jun 30 '17 19:06 kjnilsson

See this as an example.

https://github.com/kjnilsson/fez/blob/master/src/System.Lazy_1.erl

kjnilsson avatar Jun 30 '17 19:06 kjnilsson

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?

rascala avatar Jul 02 '17 14:07 rascala

Cool. It's fine to have them all in src. It's typical of erlang. Subdirectories add very little IMO. On Sun, 2 Jul 2017 at 15:18, rascala [email protected] wrote:

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_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?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/kjnilsson/fez/issues/18#issuecomment-312494496, or mute the thread https://github.com/notifications/unsubscribe-auth/ABIDlCmYHP9NXCuysqC8pZjGoQuQtmm8ks5sJ6abgaJpZM4OC2jf .

kjnilsson avatar Jul 02 '17 14:07 kjnilsson

@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.

kjnilsson avatar Jul 11 '17 22:07 kjnilsson