Make buttons that append a value to a list

image

I would like to make a list of buttons and then be able to press certain buttons to append a number to a list. Here is a very simple example.



If I now press buttons 5 and 7, for example, I would like the list nn to contain 5 and 7 instead when I evaluate the list I just get:



How do I make this work?

In my application each button has a ListPlot of measured data as its lable and I wish to select those of intirest.

You can use With to force evaluation of n:



Use Manipulate with a TogglerBar control



This is just a clarification in response to the comment,

...With replaces symbols with a value.

The reason why

works is simply because With holds all of its contents unevaluated while it does lexical replacements. Also, there's no magic to using n = n, and it's actually kinda confusing. You could also do

But while this idiom is given in the documentation, it's not the only way. All you need is a way to get the evaluation order to be what you want. Since Function also holds all of its contents unevaluated until the formal arguments are replaced with the called values, you could do this:

I find that a bit cleaner.

Ask AI
#1 #2 #3 #4 #5 #6 #7 #8 #9 #10 #11 #12 #13 #14 #15 #16 #17 #18 #19 #20 #21 #22 #23 #24 #25 #26 #27 #28 #29 #30 #31 #32 #33 #34 #35 #36 #37 #38 #39 #40 #41 #42 #43 #44 #45 #46 #47 #48 #49 #50 #51 #52 #53 #54 #55 #56 #57 #58 #59 #60 #61 #62 #63 #64 #65 #66 #67 #68 #69 #70