Group Abstract Group Abstract

Message Boards Message Boards

2
|
16.2K Views
|
15 Replies
|
34 Total Likes
View groups...
Share
Share this post:

[feature req] GUI-item for showing parentheses of grouping

POSTED BY: Raspi Rascal
15 Replies

Just my two cents on this. When I first started transitioning to functional programming within wolfram language, I had some habits from the procedural and also legacy languages like Ada that I like to keep and Wolfram Language has the flexibility to allow for it. But as I started to code more and more in functional programming style, I suddenly realize that there simple work arounds that is already available.

If you write codes that are to complicated in terms of brackets. Try break it up by naming items

Use TreeForm to see structure

Use RightComposition if you don’t like the inside first of composite functions

Etc.

Being able to work with the brackets of Wolfram Language is one of the key skills. But after three years now programming in functional programming paradigm I have found the above to take care most of my brackets debugging needs

POSTED BY: Jack I Houng
POSTED BY: Daniel Lichtblau
Posted 3 years ago

Raspi,

  1. Wolfram Research cares deeply about our customers' feedback and aims to take it into consideration as much as possible.

  2. Any estimate on when any suggestion may get picked up or not will be next to impossible to make, be it now or in a year, given the volume and diversity of suggestions we get as well as the number of either long-term and quickly developing high-priority projects the development teams are working on in the interest of our customers.

Considering point 1., customer-facing teams do reach out to our development teams for comment whenever the interest in particular issues and ideas arises, but given point 2. that information may often not be available at a given point in time.

Best, Peter

POSTED BY: Peter Fleck
Posted 3 years ago

Hi Raspi,

the developers have not rejected this suggestion, but unfortunately I do not have any information whether or when it may be implemented.

It may be advisable to meanwhile limit the use of pre-, post- and in-fix notations for Wolfram Language functions to a certain extent and use other common best coding practices that improve code clarity.

Best, Peter

POSTED BY: Peter Fleck

Thanks Peter for your reply! I conclude that the status of my suggestion/request/idea is then "suspended" for the time being, which is a neutral word for saying that a decision/discussion hasn't been made about the suggestion or has been put on hold (for unknown reasons, maybe lack of manhours/time/urgency/priority) and, once it gets seriously discussed among them with the aim to finally take a decision (to adopt vs. to reject), there could still be a chance of rejection, in the end.

Lemme wait another year (time flies!), but next year I'd surely love to hear a clear status change. Chatting with the developers (phone, lunch, fair, camp, assembly, conference, party, pub, etc), one should be able to get some word/half-baked information out, e.g. if they are fond of the suggestion in principle, and if they could ballpark what the odds are that the feature gets implemented at all.

@Peter Maybe you get a chance to produce the desired bit of information after all … , thanks in advance for your help re this matter. As you could imagine, I would be elated to hear something like "raspi, in favor of just you, I did manage to get a word … and they believe the odds are only 20% that your nice idea gets implemented within the next 5 years, meaning that it's definitely not off the table, it actually made it on the to-do-list schedule (congrats raspi!), flagged with the lowest priority imaginable. So it'll come, but you shouldn't hold your breath since nobody knows what the world, or the team/company for that matter, will look like in 5 years."

POSTED BY: Raspi Rascal

@Peter Fleck Exactly 1.0yr has passed. We, the readers/the public, never learned what happened after your forwarding, e.g. whether the developers had rejected the idea, or not.

Please could someone tell us clearly if the feature request was indeed accepted for future implementation, i.e. my idea landed on the to-do-list schedule and developers have started working on it yet?

Imho, work on improving the User Interface be more important/more urgent in upcoming major Mathematica releases than work on adding more and more uberspecialized functions. Having "three tons" (3879+) of built-in Mathematica functions may be cool and fun but please let's improve the user experience (UX, User Interface, GUI) first. Thanks for your attention, appreciated, Andrews, Germany.

POSTED BY: Raspi Rascal

Thanks for thanking, the prospect (let me have some hopes up for this proposed new feature - your team might decide against it eventually, haha) and your attention @Peter, @Arnoud, @Karl, appreciated ymmd!

Crossing fingers, I would really enjoy and profit from such a feature in the GUI of Mathematica! And not only me, I am sure ::))

I will use your linked Product Feedback Form in future, too. Good to know, thank you.

POSTED BY: Raspi Rascal
Posted 4 years ago

Hi Raspi,

Thank you for your suggestion. I would just like to confirm to you that it has been forwarded to the appropriate developers.

In order to make our technical teams aware of your ideas for improvements, please use our Online Feedback Form so they can learn about it without delay.

Thank you very much!

POSTED BY: Peter Fleck

Hi Raspi,

not really what you want, but here is at least a simple function for examining expressions:

Attributes[makeObvious] = HoldAll;
(* makeObvious[expr_]:=Framed//@HoldForm[expr] *)
makeObvious[expr_] := Map[Framed, HoldForm[expr], {2, Depth[expr] - 1}]

With this we get e.g.:

enter image description here

POSTED BY: Henrik Schachner

Hi Henrik, thank you! Very cool, seems to work well with (smaller?) expressions (e.g. not with the NestWhile[] expression from my earlier post).

Imho it should be feasible to implement the idea, if the Wolfram GUI team likes it. Hope you'd like it!

POSTED BY: Raspi Rascal

Hi Hans, thanks for participating in the discussion. I am fully aware of that functionality: we can leap around with the mouse pointer and then click around (or use your keyboard shortcut) to get an idea of 'the next bigger balanced compound expression'. Even in your example there's quite some clicking (and memorization) involved and once the selection is gone, the information/clarity about the grouping is lost.

My ultrashort algebraic example wasn't a good example anyway. Better examples involve a combination of pure functions, patterns, Boolean operators, conditionals, summation/integration symbols, rules, and alike; there we learn that we must place parentheses! Usually for conciseness and elegance we do not write down superfluous parentheses or we simply forget to write them, when they're needed. Seeing parentheses, even if they are indeed superfluous, can help intelligibility and provides unambiguousness to the reader.

So, your "Ctrl + ." comes first, yes, and for some users/uses it might be enough. It selects a balanced expression and the selection expands to compound expressions depending on the position of the mouse pointer (poor mouse pointer placement shown hehe):

enter image description here

Then my "Show Groupings" comes next, it makes all (or all relevant) groupings within that pre-selected compound expression readily visible to any reader, not just to the person with the keyboard/mouse ;-)

Mind you, on a print-out (paper, book, screenshot) one cannot click around anymore. In such a case, unambiguous code like a+((b/c)*(d^e)) proves to be a good alternative to the reader/debugging user. In summary, "your" and "my" features go well together/belong together/complement each other, yes, but in terms of practical usage they are different enough.

POSTED BY: Raspi Rascal
Posted 4 years ago

Raspi, the feature you request may, in a way, already exist. It is the keyboard shortcut Ctrl + . (That last charcter is a period)

Documentation

enter image description here

enter image description here

enter image description here

enter image description here

POSTED BY: Hans Milton

Yes Sir ! Loving it . That's a primitive yet still good example , thank you . A more involved "input" for the new menu item to process would be:

NestWhile[
  Join @@ Table[
     Table[ReplacePart[s, #1 -> n], {n, #2}] & @@ 
      First@SortBy[{#, 
           Complement[Range@9, s[[First@#]], s[[;; , Last@#]], 
            Catenate@
             Extract[Partition[s, {3, 3}], Quotient[#, 3, -2]]]} & /@ 
         Position[s, 0, {2}], 
        Length@Last@# &], {s, #}] &, {sudoku}, ! FreeQ[#, 0] &]

That is a nesting of five pure functions. The most basic (and trivial) example would be an algebraic code line:

a + b / c * d ^ e

Selecting this code snippet with my mouse, then right-click context menu item "Show Grouping" should transform/expand the selected code snippet in situ ("in-line") to:

a + ((b / c) * (d ^ e)) (*smart transformation*)
(a + ((b / c) * (d ^ e))) (*brute silly transformation*)

Thus making the code snippet more intelligible and debuggable to the reader, if the code is hard to review or doesn't deliver the desired output. Using FullForm[] for understanding in-line code or for debugging purposes is not always the way to go, imho.

POSTED BY: Raspi Rascal

Just so I understand, for something like this:

f /@ g /@ {1,2,3}

You want a keystroke or menu item which adds parentheses, e.g. like so:

f /@ ( g /@ {1,2,3} )

To make the grouping more clear?

POSTED BY: Arnoud Buzing

A basic implementation to parenthesize a selection would be as follows:

b1 = Button["Parenthesize selection", Module[{x},
  x = CurrentValue["SelectionData"];
  NotebookWrite[ButtonNotebook[], RowBox[{"(", x, ")"}]]]]

And this is the inverse (assumes the selection includes the parentheses):

b2 = Button["Unparenthesize selection", Module[{x},
  x = CurrentValue["SelectionData"];
  NotebookWrite[ButtonNotebook[], Part[x, 1, 2]]]]

You can add these buttons to a docked cell to make available for all notebooks:

SetOptions[$FrontEndSession, 
 DockedCells -> {Cell[BoxData[ToBoxes@Row[{b1, b2}]]]}]

Change \ $FrontEndSession to \$FrontEnd to have it persist between restarts of the frontend.

Change things back with:

SetOptions[$FrontEndSession, DockedCells -> {}]

DISCLAIMER: This is just a simple prototype I wrote for you to experiment with. Implementing something like this that is production-grade is quite complicated because it needs to support large amount of edge cases (which this does not do). I won't be able to make improvements upon this, but you are welcome to (and anyone reading this is welcome to). This is not functionality I would use myself, because I prefer to write Wolfram Language code that is human readable in the first place (by limiting the amount of syntactic shortcuts).

POSTED BY: Arnoud Buzing
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard