Skip to content

Adding new brackets to Julia - ideas wanted #8934

@tonyhffong

Description

@tonyhffong

Related issue: #7128
A proof-of-concept PR: #8892 (more technical discussions inside)

Currently, we have (), [], {}. We could introduce more bracket types to Julia so oft-used functionalities are more convenient to use, such as non-concatenating array/matrix construction, perhaps even with some "leftovers" that modules can use to enable terser and more readable code (the latter is much motivated by my selfish reasons).

The PR proposes three new bracket types: ⟨⟩,⟦⟧,⦃⦄ (which can be entered by latex symbols \langle,\rangle, \lBrack, \rBrack, \lBrace, \rBrace). ⟦⟧ and ⦃⦄ also have ASCII equivalents [| |] and {| |}, respectively.

They are mapped according to whether there's something in front of the brackets. For example, (some_expression)⟦args...⟧ is mapped to @Brack_call( (some_expression), args... ), and ⟦args...⟧ is mapped to @Brack_enclose( args... ). The macro definition is in base and is currently defaulted to Brack_call and Brack_enclose generic functions in these examples. These can be stagedfunction, obviously, and it is part of the discussion below. Type signatures would provide the customization on actual behavior.

The key question is what kinds of functionalities should these new brackets be used for? Note that:

  • The parsing rule inside these brackets can be different from one another. And they have to be decided for all users. For examples,
    • if we want to use ⟦⟧ for matrix construction, there are decisions on treatment on space, commas, semicolons, or perhaps even newlines, and how to make higher dimensional construction "easier", etc.
    • if we want g{| a, b, c |} to mean some kind of "lifted" function call, we may want to parse the list as argument list.
  • Similar to the interior parsing rule, whether or not these bracket constructs would lower to a staged function, and what this staged function actually do are also a universal decision.

With respect to the PR, let's use this issue to keep track of design/usage ideas (my lisp code ugliness 😄, unicode issues etc. can be done in the PR ).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions