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

User-defined indexing operator without array indexing #622

Closed
wants to merge 12 commits into from

Commits on Jun 19, 2016

  1. Add a special syntax for index operators

    This commit introduces a new syntax for index operators.
    Five core parenthesis operator are added:
    .[], .{}, .{,}, .{,,}, .{,..,}.
    The .{,}/.{,,}/.{,,,} operators are defined for compatibility with the
    Bigarray syntax extension.
    Each core index operator is available in a access and assignement
    versions. For instance, .[] is declined in
    * .[] : index operator
    * .[]<- : indexed assignment operator
    The general syntax for these index operators as implemented in the
    parser is index_operator::= index_operator_core [<-].
    Octachron committed Jun 19, 2016
    Configuration menu
    Copy the full SHA
    e1a6add View commit details
    Browse the repository at this point in the history
  2. User-defined indexing operator (.[])

    This commit modifies the parser to use the newly defined (.[]) and
    (.[]<-) operators. It also moves the definition of the .[] operators for
    String/Bytes to the pervasives module.
    
    Before this commit, expressions of the form `string.[index]` where
    desugared to String.get[_unsafe] string index. The safe or unsafe
    version were chosen depending on the presence of the "-unsafe" compiler
    option. Such expression are now desugared to `( .[] ) string index`.
    The same desugar operation is applied to `string.[index] <- value`
    which is translated to `( .[]<- ) array index value`.
    
    In order to keep the standard semantic for string index operations,
    these new index operators are defined in the pervasives module using
    new compiler primitives, e.g. ` let .[] = "%string_opt_get"`.
    
    These new primitives are then mapped to safe or unsafe version
    depending on the the "-unsafe" compiler option. Consequently, these
    modifications should have no impact on existing code.
    
    With these modifications, defining custom `.[]` operators should be
    easier, at the cost of losing access to the standard index operator
    for string.
    Octachron committed Jun 19, 2016
    Configuration menu
    Copy the full SHA
    a46f696 View commit details
    Browse the repository at this point in the history
  3. User-defined indexing operator (.{})

    This commits modify the Bigarray syntax extension in order to facilitate
    the use of custom (.{}) operators. The compatibility with the existing
    Bigarray syntax has been preserved as much as possible. However, this
    commit will break code which use the Bigarray (.{}) syntax without opening
    the Bigarray module first!
    
    Like the previous commit, this commit modifies the parser to desugar
    bigarray1.{index} to ( .{} ) bigarray1 index. Following the bigarray
    syntax, the index operator used in the desugaring changes if the index
    is a n-tuple:
    
    1-tuple ⟹ `.{}`
    2-tuple ⟹ `.{,}`
    3-tuple ⟹ `.{,,}`
    4 and more tuples ⟹ `.{,..,}`
    
    The bigarray modules has been modified to use this new index operators.
    Note that this means that these index operators are not anymore
    accessible without opening the bigarray module.
    Octachron committed Jun 19, 2016
    Configuration menu
    Copy the full SHA
    6c17c78 View commit details
    Browse the repository at this point in the history
  4. PR#6885: documentation for index operators

    This commit documents the new syntax for index operators ( .[], .{})
    and updates the documentation of the bigarray specific syntax:
    
      * A new section "Customizable index operators" (7.28) describes the
      index operator syntax. Within this section, two subsections details
      respectively the particularities of the multidimensional index
      operator (.{}) and some potential source compatibility problem with
      the previous  bigarray specific syntax.
    
      * The "Syntax for bigarray access" section (7.21) has been partially
      removed and only mention that this extension has been superseded by
      the new extension and deprecated, with forward references to the new
      section 7.28 and compatibility subsection
    
      TODO:
      * The documentation would have to be updated again when/if the
      mantis issue ocaml#6765 is integrated in trunk : for now, the
      documentation only mention that using the ( .{} ) syntax without
      opening the Bigarray module is "deprecated".
    Octachron committed Jun 19, 2016
    Configuration menu
    Copy the full SHA
    dd15146 View commit details
    Browse the repository at this point in the history
  5. Update printing of custom index operators

    Jeremie Dimino authored and Octachron committed Jun 19, 2016
    Configuration menu
    Copy the full SHA
    99651a2 View commit details
    Browse the repository at this point in the history
  6. Indexing submodule for bigarray

    The objective of this commit is to introduce a short notation for
    bringing in scope the bigarray index operators and only them. For
    that purpose, the bigarray index operators are regrouped in a single
    submodule. This submodule is also included inside the global bigarray
    module to preserve compatibility and ease of use of the bigarray
    module.
    Octachron committed Jun 19, 2016
    Configuration menu
    Copy the full SHA
    42e07e8 View commit details
    Browse the repository at this point in the history
  7. Bigarray index operators deprecated warning

    With the simplification of index operators, the expressions a.{..} are
    no longer automatically resolved to Bigarray.Array[n].[g|s]et. To use
    these operators, it is now necessary to bring them in scope, for
    instance by opening either the Bigarray or Bigarray.Operators module.
    To ease the transition period, this patch add an hack in
    `typing/typetexp.ml` to catch the cases where the index operators
    `.{}/.{,}..` are used without being bound in the current scope
    and tranlate then to Bigarray.(..)  with a deprecated warning.
    Octachron committed Jun 19, 2016
    Configuration menu
    Copy the full SHA
    ddc86c5 View commit details
    Browse the repository at this point in the history
  8. Manual: Document bigarray compatibility warning

    This commit update the documentation on the compatibility problems
    between the deprecated bigarray specific syntax extension and the new
    user-defined index operators extension. In particular, this commit
    describes the new deprecated warning for implicit use of the
    `Bigarray(.{...})` operators and states that this warning might be
    turned into an error in the undetermined futures. This commits also
    amend the documentation to mention the new `Bigarray.Operators`
    submodule when useful.
    Octachron committed Jun 19, 2016
    Configuration menu
    Copy the full SHA
    a1eb9c1 View commit details
    Browse the repository at this point in the history
  9. Manual: Fix user-defined index operators

    Change the name from customizable to user-defined index operators and
    fix the alignment of the latex tables for better readability.
    Octachron committed Jun 19, 2016
    Configuration menu
    Copy the full SHA
    18e299a View commit details
    Browse the repository at this point in the history
  10. Extended syntax for indexing operator

    Enable module path prefix for indexing operator:
    * `a.M.[i]` ≡ `M.(.[]) a i`
    * `a.M.[i]<-v` ≡ `M.(.[]<-) a i v`
    * `a.M.{i}` ≡ `M.(.{}) a i`
    * `a.M.{i}<-v` ≡ `M.(.{}<-) a i v`
    Octachron committed Jun 19, 2016
    Configuration menu
    Copy the full SHA
    298071a View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    f14a4ef View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    9c9ee63 View commit details
    Browse the repository at this point in the history