# Why can I edit only one character of the output of a Dynamic expression?

Try this:

DynamicModule[{foo = \[Placeholder]}, foo]


Note how we're able to edit the placeholder in the output, e.g. replace it with 42:

Now, try this:

DynamicModule[{foo = \[Placeholder]}, Dynamic@foo]


This time, I'm only able to edit one character:

What's going on internally, that explains this behavior?

At first, I thought maybe upon the first "touching" of a Dynamic portion of an output expression, the entire expression somehow "locks up." But, that can't be the case—I can edit that "4" as much as I'd like—I just can't remove or add any characters.

Next, I compared the two expressions' FullForms, keeping in mind that the very act of typing the first / in the output cell might have an effect on the expression:

But I'm not sure what to make of the difference. Does it have something to do with ImageSizeCache? Still, why and how would something enforce the presence of a strictly one-character atom?

I'm on $Mathematica$ 9.0.1.0.

-
Because once you change the place holder to 4, it is no longer a place holder. The behaviour is the same as DynamicModule[{foo = 4}, Dynamic@foo] –  The Toad Mar 19 '14 at 4:31
@rm-rf—I'm afraid I'm still missing something. In both cases, I click on the placeholder and begin typing. If you're saying changing the placeholder to 4 is what restricts my input, then why does this not happen in the first case? (Is there some special meaning of the placeholder in the context of Dynamic? I was simply using it because it looked like a box.) –  Andrew Cheong Mar 19 '14 at 6:08
I'm afraid I don't know the answer... I thought it had to do with the place holder, but I didn't have time to test it out extensively. I certainly didn't expect this behaviour, but I'm not sure if it is reasonable or a bug. Perhaps someone more knowledgable can chime in. –  The Toad Mar 19 '14 at 6:16
You are attempting to edit an output cell. As soon as you enter 4 the cell becomes an input cell. If you want to enter values into sections of an output cell you need to use InputField –  Mike Honeychurch Mar 19 '14 at 6:48
MWE is Dynamic[1], you can't edit DynamicBox. (But you can add characters next to it and create a RowBox) So I think you interpretation is correct. Placeholder allows you to do this but once Placeholder is replaced you are loosing this ability. So @rm-rf is right however details are desired. It seems to be logical but not expected. –  Kuba Mar 19 '14 at 7:43

Ah, the answer was preempted by @rm-rf and more technically confirmed by @Kuba, but I didn't quite understand in the way that they worded things. So allow me to rehash their comments—

You can't edit anything within Dynamic. Any appearance of editing, is only that: an appearance.

To see this for yourself, input

Dynamic[bar]


and highlight the a in the output, then try to type anything:

You'll find that you won't be able to. Same if you attempt to highlight ar. But when you attempt to highlight bar, you'll find that sometimes you're able to edit the expression! But you can guess why: Instead of highlighting what's inside Dynamic, you've accidentally selected the invisible Dynamic too—therefore you've replaced Dynamic[bar], thereby removing the editing restriction. What I've learned is that—just as with most textfields and word processors—when you highlight slightly past the r in bar, you end up highlighting the whole Dynamic entity (analogous to highlighting the whole "word" or "paragraph" or "line"), but the highlighting is indistinguishable from having highlighted only bar.

Now, carry this to the case of

Dynamic[4]


It's the same thing, but somewhat more misleading when you try to edit it and deduce what happened, because you can't tell whether you've highlighted just the 4 or the whole Dynamic[4].

So, here's the kicker—

Dynamic[\[Placeholder]]


Apparently, as, again, @Kuba pointed out, a placeholder allows you to "cheat" and replace it once. And you can tell $Mathematica$ isn't "happy" with you doing this because it "dings" (sounds the bell, \a) on replacing the placeholder—just as it does when you attempt to replace the ar in bar! It allows it once, and after that you don't get to "cheat" anymore—you're back to the default behavior, in which you can't edit anything within Dynamic.

So, this one-time "allowance" of editing fooled me into believing there was a 1-character limit.

-
Thanks for writing it down. I was reasonably confident in my guess that it was only the place holder that was deceiving you, but large parts of dynamic functionality are still mysterious to me... I've been burned by other similar guesses I've made before, so I didn't feel like posting an answer :) –  The Toad Mar 23 '14 at 6:17