Coder Social home page Coder Social logo

Comments (8)

mario-tux avatar mario-tux commented on May 14, 2024

On first glance I would say that the second option would be acceptable and less intrusive but I see the same problem with variants: there the return value type is not constant and you can't exploit such coincidence.
Looking at the GMP naming you should even use get_str/set_str but this would be a further complication...

from mlib.

P-p-H-d avatar P-p-H-d commented on May 14, 2024

True...

I propose then to have for both tuple & variant:

  • T * _get_at_##field
  • T const * _cget_at_##field

It may be good to have also:

  • T * _get(tuple, enum field)
  • T const * _cget(tuple, enum field)
    with the enum field defining which version of the field we want.
    (this will give a good symmetry with an array / dict _get & _cget).

from mlib.

mario-tux avatar mario-tux commented on May 14, 2024

This proposal looks reasonable with a safer naming.

I'm still looking at the strange naming of the _set_str/_parse_str methods. I understand that the _parse_str is one of the methods of an OPLIST and that it gets a third parameter to make possible the step-by-step parsing. On the other side I look at the string_set_str specific method and to the mpz_set_str one of GMP. I'm wondering if would be more congruent to keep the _parse_str methods with three params but to make standard a _set_str method for all the containers that get only two params and, maybe using _parse_str, parse the full string in order to reconstruct the container content. Does it make sense?

from mlib.

P-p-H-d avatar P-p-H-d commented on May 14, 2024

Thanks.

The parse_str interface is based on the strtol interface, whereas set_str is based on atol. In fact, I think a method like parse_str is missing in GMP (MPFR has added mpfr_strtofr). The method _set_str is too limited for its designed usage. Moreover, there is the strict equivalence:
_set\_str(Object, str) == _parse_str(Object, str, NULL)
(_parse_str accepts NULL as final argument).

This different interface is why I chose a different naming for this function. Moreover, it reflects more what it does since for non-trivial types, it performs a parsing of the string. _set_str is suitable only for simple and controlled cases.

Note that string_set_str != string_parse_str: string_set_str sets the string to the exact array of char string_parse_str parses the string that shall be in the form "THIS \"IS\" A STRING" into THIS "IS" A STRING (this is needed for proper serialization of objects within other objects).

Therefore, I don't see the needs for adding _set_str.

from mlib.

mario-tux avatar mario-tux commented on May 14, 2024

Ok, I can see the difference. Now it is more clear.

I've just tried the latest version in master and maybe something went wrong. Now my main code raises a warning like:

 warning: passing 'const symbol_list_t' (aka 'struct symbol_list_s const[1]') to parameter of type 'struct symbol_list_s *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
TUPLE_DEF2(record, (name, string_t), (key, symbol_t),

on a tuple of mine:

TUPLE_DEF2(record, (name, string_t), (key, symbol_t), (fields, symbol_list_t))

If you tests say that all is ok, I can try to isolate the exact case.

from mlib.

P-p-H-d avatar P-p-H-d commented on May 14, 2024

I cannot reproduce the issue. Could you open a bug report (with the function that raises the warning)?

from mlib.

P-p-H-d avatar P-p-H-d commented on May 14, 2024

Methods have been renamed into _get_at and new methods _cget_at have been added.

from mlib.

P-p-H-d avatar P-p-H-d commented on May 14, 2024

I don't see any way to implement the T * _get(tuple, enum field) method, as this method should be able to return different type depending on the fields.

from mlib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.