Git Product home page Git Product logo

Comments (4)

BenjaminLawson avatar BenjaminLawson commented on July 28, 2024

Should Ok() also fail if the value of the field is not the default/fixed value? In the case of commands with op codes, the view should be invalid if it is not the specified value.

from emboss.

reventlov avatar reventlov commented on July 28, 2024

Ok() falls under the (existing) feature, [requires].

However, ideally, [default_value] (or whatever it gets called) would be inferred from annotations like [requires: this == 10], without a human having to explicitly add it.

from emboss.

fsareshwala avatar fsareshwala commented on July 28, 2024

Just to make sure, I think we can infer the default value from the requires annotation if it's there and only a scalar value. AFAIK, the requires annotation allows for ranges as well and we can't infer much there. We also need to be able to set a default value which can be overridden to something else if necessary. Just want to make sure the implementation captures all these use cases.

from emboss.

reventlov avatar reventlov commented on July 28, 2024

That is correct. The exact rules I am thinking are:

  1. If the field is a structure (struct or bits type), its default value is the compound of the default values of its fields.
  2. Otherwise, if there is a [default_value: n] annotation on the field, the default value is n.
  3. Otherwise, if there is a [requires] annotation of the form [requires: this == n] or [requires: n == this], where n is a compile-time constant (including an expression that evaluates to a compile-time constant, like 2 * Type.some_constant), then the default value is n.
  4. Otherwise, if the field is a boolean and there is a [requires] annotation of the form [requires: this], the default value is true.
  5. Otherwise, use the default default value for the field's type, which should be 0 for numeric types and false for booleans.

I am open to other inference forms, but I cannot think of any that would be useful and seem likely in real code.

from emboss.

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.