Message Boards Message Boards

The grey 'x' and Debugging WL code

Posted 2 years ago

I am still unexperienced in WL, but I have come to a point that I can create some programs that are getting a tiny bit more complex (still quite modest though) :-)

But I often run into very basic things I just can't figure out. So I hope someone can direct me a bit :

  1. Inside a Dynamic, I get the grey small 'x' if I do not 'close a line with the semicolon (;). That is annoying, because the script stops working as planned (as it interpretes the 'x' as a multiply sign) in an unintended way.

  2. In a Dynamic[ xxxxxx ], why does the last line have to be WITHOUT semicolon (;) ?

  3. How can I best view the values of the variables I use inside Dynamic? I did that by leaving out the semi-colon, as to output the result, but as I mentioned, that does not work inside a Dynamic script. Sometimes though this works and the annoying grey 'x' does not appear. can I switch off the automatic behavior of 'filling in a x' for me when the are spaces? I can myself put '*' if I want a multiplication to occur.

  4. I am used to a debugger, where I can set Breakpoints and a Variable Watcher. How is serious debugging being done in WL?

POSTED BY: B. Cornas
43 Replies
Posted 2 years ago

That was easy and clear. I get it :-)

f[a_,x_]
POSTED BY: B. Cornas
Posted 2 years ago

I'll check your link tomorrow. Thanks. It seems a learning curve on 'all levels' :-)

POSTED BY: B. Cornas
Posted 2 years ago

f[a, x] := Sin[a x]

I'm hoping there was some sort of copy error here. That definition is almost certainly not what you want. You probably want this:

f[a_, x_] := Sin[a x]
POSTED BY: Eric Rimbey
Posted 2 years ago

Of course, you're right. I failed to check my copying. Something went wrong in the pasting.

I see what is the problem : In the Reply cell it is pasted all right, but in the 'Reply Preview' underneath that (which determines what goes into the post) the underscores are lacking. Also if I put the function in quotes.

If I tye in a underscore like this a_ it works. But F[x,a] does not. I have typed the two underscores but they are missing in the 'Reply Preview'.

Quite strange. Also CR are sometimes not registered in the 'Reply Preview'.

See attached screenshot

Attachment

Attachments:
POSTED BY: B. Cornas
Posted 2 years ago

Ah, yeah, it's just part of markdown syntax. https://daringfireball.net/projects/markdown/syntax

POSTED BY: Eric Rimbey
Posted 2 years ago

If you look here, https://community.wolfram.com/groups/-/m/t/270507, starting at the Post Editor section, you'll see better ways to post code fragments.

POSTED BY: Eric Rimbey
Posted 2 years ago

If I want to see the value of a dynamic variable (aa) outside the Dynamic[], I have to use naother Dynamic[aa]

This also is not true. I'm honestly very confused about what you must be doing to be getting these results. Now, without Dynamic, you would have to evaluate an expression to see its results. But that's easy and it's what I do all...of...the...time. This is the beauty of notebook-style interfaces. This is why so many other languages are now adopting a notebook interface. It's like a super convenient REPL. If you want to know what aa is, just type aa into a cell and evaluate it.

But even more, if you want to have Dynamic[aa] somewhere, that's fine. It's great. No problem. But you don't need the other occurences of aa to also be inside a Dynamic. You can have just regular ol' expressions being evaluated using aa, and if aa ever changes, that place where you put the Dynamic[aa] will update automatically.

You can also sprinkle Print expressions inside of other expressions (so aa could get printed out during an evaluation). You can use Trace to see how an expression was evaluated. You can use Information (more useful for functions than simple variables).

POSTED BY: Eric Rimbey
Posted 2 years ago
POSTED BY: B. Cornas
Posted 2 years ago
POSTED BY: Eric Rimbey
Posted 2 years ago

Eric, I've been thinking the same. It would be good if we could mail privately. I don't know how to do that, so I'll post a mailadres I have :

If you please, contact me on that address. I am really thankfull for your help.

POSTED BY: B. Cornas
Posted 2 years ago

PS. I just read how to acces a function outside the Manipulate function :

f[a_, x_] := Sin[a x]
Manipulate[Plot[f[a, x], {x, 0, 10}], {a, 1, 5}]

If I understand this correctly, I have to send the current value of 'a' (inside the Manipulate), together with the value of 'x' to the function 'outside'.

POSTED BY: B. Cornas
Posted 2 years ago

It was a busy day for me today, so not much time.

About your answer 4.

I get the gist of it. I will need a manipulate / Dynamic for most of my applications, as they have to be interactive. I understand that I can paste my code, or parts of it into seperate cells, as to see how that part behaves. And I do that already.

In the next days, I will try to convert a more complex code I have working with Dynamic to Manipulate, to see if I can pull that off and if it works better for me.

One of the problems I forsee, is that functions ouside a manipulate cannot be called from inside the Manipulate itself, because of the variable scoping. That is also the problem I experience with Dynamic. If I want to see the value of a dynamic variable (aa) outside the Dynamic[], I have to use naother Dynamic[aa].

The way I used the Dynamic, was that I put it where I needed it and had 'normal' code in between. With Manipulate, as far as I see it (I might be wrong though), I need to do everything that is interactibve within the one Manipulate function.

I just tried to nest or combine two Manipulate[ ] , but that does not work. With Dynamic (and that was if I remember well, the reason I continued with Dynamic in stead of Manipulate) I can 'call back' on variables I have in an earlier Dynamic function. It gives me a better overview of my coding. One of the things I am still not used to is the extremely compact way of coding in WL. Proficient EWL coders put into one line of code, where I am accustomed to to the same with 10 lines. Of course I am more than willing to change my unelegant coding for a better one, I am totally not attached to my bad coding. But untill now it was the best I could do :-)

That Dynamic[ ] seems to keep it's variable values I discovered only later and gave me an additional bonus.

Anyway, I hope the weekend will bring me some free hours to experiment some more. I find it all very interesting (and frustrating all at times that I don't get it :-)

Thanks, Beat

POSTED BY: B. Cornas
Posted 2 years ago

functions ouside a manipulate cannot be called from inside the Manipulate itself

This is not true. Not sure what you're seeing to make you think that.

POSTED BY: Eric Rimbey
Posted 2 years ago

I jusr read that in a Nb by Lou D'Andria, Senior UI Developer, Wolfram Research which is from a webinar he did on Manipulate earlier this year I believe.

I must say, that some of the code in the Nb does not work, I found out, so my 'quoting' his work might be wrong.

POSTED BY: B. Cornas
Posted 2 years ago

I am most grateful for yopur extended help, Eric. I also start to feel a bit encumbered (I hope the translate app has provided me with the correct translation) taking so much of your time. Please know, that I won't be 'offended' or anything if you say "it has been enough". I do not always have the time to respond immediately, but your input really helps me a lot.

  1. I had found about setting deafsults : {{degree, 3}, 1, 10, 1, Appearance -> "Labeled"}

  2. That is great for making a Preset. So I can save settings I like, save the imgage that comes out of these settings, work on the image and if necessary go back to the Preset and tweak the settings.

    Hmm :-) I had tried with a ver simpel example, but now I made a Snapshot with your last corrections: I get a 'DynamicModule' with all the settings in it, as well as the associated image. What I don't get, unfortunately, are the controls to tweak my settings. So I wont be able to tweak my image later on revisiting.

  3. I do not notice any difference in behavior between 'Dynamic Module' and 'With'

  4. This does not work with me. I'll look into it some more.

After having played some time with Manuipulate for the little thingies I am making, I also came across 'Dynamic'. I read about both Manipulate and Dynamic and decided then, to continue (and even rewriting my Manipulate stuff) with Dynamic. I did reasonably well, that is, I managed to make some 20 little programs with Dynamic. One of the advantages of Dynamic is, that it seems to keep the values of my settings when running again. That is quite important for me. If I have a nice setting (nice image), and I want to load in new Random numbers (and to keep the nice settings), this works in Dynamic (for most settings).

I will study again the documentations on Manipulate and Dynamic, as soon as I have the opportunity to do so :-)

Thanks a million, Beat

POSTED BY: B. Cornas
Posted 2 years ago

(2) Right. To tweak things, you'd just change the variable initializations at the beginning of the DynamicModule. It's just another tool. I wasn't entirely clear what you meant by "retain settings", so I'm just giving you lots of things to play with.

(3) I don't really expect you to in this case. With will make the variables constant/unchangeable, so you would have a static snapshot. Maybe not worth worrying about.

(4) Okay, if this isn't working for you, this may be the source of all of your troubles. I suspect this is why you started using Dynamic. What I'm suggesting here is what folks are probably doing 99% of the time. The notebook itself is the "playground". You don't need Dynamic, DynamicModule, Manipulate, etc to just start playing around with expressions in a notebook. I probably should have added more instructions. The body of the Manipulate will have variables in it, and those variables are sort of declared/initialized with all of those bracket expressions at the end (after what I'm calling "the body"). If you paste just the body into a separate cell, all of those variables will now be undefined (they're now in the Global scope instead of localized to the Manipulate). So, you'll also need to provide values for those variables (presumably in more cells that get executed before the "body"). Maybe I'll put together a whole notebook to demonstrate. But probably not today.

POSTED BY: Eric Rimbey
Posted 2 years ago

[I] would like to retain the settings.

There are a few options.

  • You can set defaults in the Manipulate (see the documentation).
  • You can also dump out a snapshot of the state of the Manipulate when you have it the way you want it. There is a very subtle "+" symbol in the upper right corner of the Manipulate output. If you click on that, it'll show you some options. If you choose "Paste Snapshot" you'll get a new Input cell that has a DynamicModule expression in it. If you evaluate that cell, you should get the exact same result that your Manipulate is currently displaying, and you'll see that DynamicModule has initialized all of its variables to the values they currently have in the Manipulate. You can now use that DynamicModule expression as a template going forward. You can change the random points and re-evaluate the DynamicModule using those same parameter values.
  • You can switch the DynamicModule to With (just change the head), and your parameters will be "fixed".
  • You can make the parameters global, just assign them in a different (previous) cell. Extract the body of the Manipulate into its own cell and evaluate it.
POSTED BY: Eric Rimbey
Posted 2 years ago

Another thing is, how can I get the Graphics outside the Grid.

The body of the Manipulate can be any Mathematica expression, so it could be a CompoundExpression. So, you could just do something like

Grid[<debug stuff>];Graphics[<graphics stuff>]

This will suppress the debug stuff. When you want the debug stuff, you'll need to comment out the ;Graphics[...] bit (including the semi-colon). You could also add another Manipulate variable, like debug and then wrap the whole body in an If (showing whatever you want if debug is True and just the Graphics if debug is False). Or, you could wrap the debug stuff in Print. Or... <there's no end to how you might want to handle this>.

POSTED BY: Eric Rimbey
Posted 2 years ago

I have tried to seperate the Grid[Debug stuff] and the Graphics[graphics stuff], but I get errors again, although the code looks quite all right and logical to me.

I've taken the Graphics from here and put it outuside the Grid but that does not work

But If I comment out the whole Grid[ . . . ], then it works.

I cannot wrap my mind around that. I kept the GHrid[...] the same as when the Graphics part is inside the Grid and the thing works all right. Maybe I messed up with : SpanFromLeft}

I get the idea that I miss something with WL on a very basic level, as many things are totally against my intuition and logic. Some things make perfect sense, some things just don't. I am getting quite sad about that and do not really what to do. I feel bad about taking so much time from you and others before.

I'll look into your other answer tomorrow. I am too frustrated right now :-(

Beat

Attached my try with taking the Graphic part out

Attachments:
POSTED BY: B. Cornas
Posted 2 years ago

You used a comma instead of a semi-colon. Also, you left the Grid in an invalid structure, so if you got rid of the graphics part the grid part wouldn't display correctly.

POSTED BY: Eric Rimbey
Posted 2 years ago

I replaced the comma with the semi colon and that works. I suppose the semicolon is to 'close off' the Grid[ ] function.

I do not see the values now anymore, but I will look into that tomorrow. It's quite late already where I reside.

Thanks

POSTED BY: B. Cornas
Posted 2 years ago

I got it working now. I put the Graphics again inside the Grid[ ] which is ok. I can now comment out the variables and values. Quite neat :-)

I did not manage do get the Grid with variables with the Graphics ouside the Grid[]. But all right. Sometimes I find it hard to put the different brackets in the right place.

I will now see what I can do with your advice on retaining the Settings when I run the script again.

POSTED BY: B. Cornas
Posted 2 years ago

You previously said that you were able to get the Graphics outside of the grid by replacing the comma with a semi-colon. Eventually I think you'll want to get this bit working, because Grid will add unecessary padding, I think.

POSTED BY: Eric Rimbey
Posted 2 years ago

Yes I did :-) I got the Graphics ouside he Grid[] working, but could not see the stuff inside the Grid anymore.

So now I have put the Graphics inside the Grid[] again and can comment out the values if I want to.

I could not figure out so far, how to seperate the two (Grid[] and Graphics) and have BOTH of them working. I seem to get trapped in little snags all the time. As I am quite persistent, so I will eventually get there. But sometimes it feels a bit like leaning Finnish. Anyway, thanks so much for all your wonderful help, Eric. I really appreciate it.

POSTED BY: B. Cornas
Posted 2 years ago

Gotcha. Yeah the semi-colon means you have a CompoundExpression, and only the last part of a compound expression gets "returned". I would just put in an If expression and just copy-paste the Graphics bit (actually, it'd be better to assign it to a variable, but whatever). You could even add a debug variable to the Manipulate. Like this:

With[{xCoords = {28, 39, 48, 1, 4, 70, 86, 83, 14, 23}, 
  yCoords = {36, 76, 41, 56, 39, 6, 83, 7, 59, 33}}, 
 With[{pts = Transpose[{xCoords, yCoords}]},
  Manipulate[
   If[debugQ, 
    Grid[{{"pointSubRange", pointSubRange}, {"pointCount", 
       Abs[Subtract @@ pointSubRange]}, {"allPts", 
       pts}, {"selectedPts", 
       Take[pts, pointSubRange]}, {"splineDegree", 
       splineDegree}, {"groupedPoints", 
       Partition[pts, UpTo[groupSize]]}, {"lineThickness", 
       lineThickness}, {"aspectRatio", aspectRatio}, {"curveType", 
       curveType}, {"splineClosedQ", splineClosedQ}, {"showPointsQ", 
       showPointsQ}, {Graphics[{Thickness[lineThickness], 
         curveType[
          Partition[Take[pts, pointSubRange], UpTo[groupSize]], 
          SplineDegree -> splineDegree, 
          SplineClosed -> splineClosedQ], Red, 
         If[showPointsQ, Point[pts], Nothing]}], SpanFromLeft}}],
    Graphics[{Thickness[lineThickness], 
      curveType[Partition[Take[pts, pointSubRange], UpTo[groupSize]], 
       SplineDegree -> splineDegree, SplineClosed -> splineClosedQ], 
      Red, If[showPointsQ, Point[pts], Nothing]}]], {pointSubRange, 1,
     Length@pts, 1, ControlType -> IntervalSlider}, {splineDegree, 1, 
    Length@pts, 1}, {groupSize, 2, Length@pts, 1}, {lineThickness, 
    0.005, 0.05}, {aspectRatio, .1, 
    10, .1}, {curveType, {BSplineCurve, 
     BezierCurve}}, {splineClosedQ, {True, 
     False}}, {showPointsQ, {True, False}},
   {debugQ, {False, True}}]]]
POSTED BY: Eric Rimbey
Posted 2 years ago

Eric, thank you for your extended effort.

I like the way you have implemented a kind of Debugger (in the Grid form). I was missing that and the way I tried to do it, to erase the semicolon on lines I wanted to check the output, which in a Dynamic wrapper does not work well.

I had never used With, which is useful and clear to me. Great.

I played a bit with your example and I understood it. I also made the showPoints working and beautified the thing a bit. Just playing around to see if I get it.

Still I have some questions :

The values I set with the sliders and buttons are not retained, the next time I run the script. As I am working with RandomIntegers[100] instead of in the example fixed xCoords & yCoords, I need to run the script often, but would like to retain the settings. This I have working with the script using Dynamic.

Another thing is, how can I get the Graphics outside the Grid. I tried in several ways, but get either warnings in my script or when I run the script, like this :

Manipulate::vsform: Manipulate argument {} does not have the correct form for a variable specification.

I would like to have the Graphics outside the Grid, so I can comment out the Grid entirely when things are working.

I attached my ‘work’.

Thanks again :-)

Attachments:
POSTED BY: B. Cornas
Posted 2 years ago

Okay, here is a start on what you seem to be trying to do. I've shown the values of the Manipulate variables explicitly just to demonstrate a sort of validate as you go strategy. I built up each part of the Grid bit by bit, adding each new Manipulate variable only after getting the previous ones to work as I wanted. Once the graphic part of the display was to my liking, then I'd remove (or maybe just comment out) these pseudo-debugging elements.

With[
 {xCoords = {28, 39, 48, 1, 4, 70, 86, 83, 14, 23},
  yCoords = {36, 76, 41, 56, 39, 6, 83, 7, 59, 33}},
 With[
  {pts = Transpose[{xCoords, yCoords}]},
  Manipulate[
   Grid[
    {{"pointSubRange", pointSubRange},
     {"pointCount", Abs[Subtract @@ pointSubRange]},
     {"allPts", pts},
     {"selectedPts", Take[pts, pointSubRange]},
     {"splineDegree", splineDegree},
     {"groupedPoints", Partition[pts, UpTo[groupSize]]},
     {"lineThickness", lineThickness},
     {"aspectRatio", aspectRatio},
     {"curveType", curveType},
     {"splineClosedQ", splineClosedQ},
     {"showPointsQ", showPointsQ},
     {Graphics[{Thickness[lineThickness], 
        curveType[
         Partition[Take[pts, pointSubRange], UpTo[groupSize]], 
         SplineDegree -> splineDegree, SplineClosed -> splineClosedQ],
         Red, If[showPointsQ, Point[pts], Nothing]}], 
      SpanFromLeft}}],
   {pointSubRange, 1, Length@pts, 1, ControlType -> IntervalSlider},
   {splineDegree, 1, Length@pts, 1},
   {groupSize, 2, Length@pts, 1},
   {lineThickness, 0.005, 0.05},
   {aspectRatio, .1, 10, .1},
   {curveType, {BSplineCurve, BezierCurve}},
   {splineClosedQ, {True, False}},
   {showPointsQ, {True, False}}]]]
POSTED BY: Eric Rimbey
Posted 2 years ago

Wonderfull,Eric. I am studying your example at this moment. It might take a little while to answer. I first want to understand your code completely. Also, I will again read again about Manipulate versus Dynamic :-)

POSTED BY: B. Cornas
Posted 2 years ago

So, For is a special form. In its documentation you'll find this:

Unless an explicit Return is used, the value returned by For is Null.

And for that specific example, I personally wouldn't have gravitated toward a For loop but instead toward some List restructuring/combining strategy like Riffle.

POSTED BY: Eric Rimbey
Posted 2 years ago

I understand that now, but something like that is Not to found in the Help. I have been breaking my head over it, as it is not consistent with WL behavior in other cases.

And for that specific example, I personally wouldn't have gravitated toward a For loop but instead toward some List restructuring/combining strategy like Riffle.

I agree, but sometimes I do and sometimes I don't manage to make the code in the "Mathematica-way". Here I just didn't succeed and also wanted to at least master the For function. You know, I am an artist and the programming is to get new ideas into my work. So for me it is more important to have some code running properly than that it will win a beauty- or efficiency price. I like to learn and make better code, but in the meantime I produce some real ugly, but at least working code :-)

Thanks again for your help.

POSTED BY: B. Cornas
Posted 2 years ago

I find it sometimes very hard to pose a question coherently, because I experience part of WL behavior as errartic and hard to pinpoint where the trouble or unclearness is.

Yes, I have a lot of sympathy for you. It takes quite a bit of practice with Mathematica to get familiar with these things, especially if your previous programming experience was with more imperative languages. Wolfam Language is more similar to Lisp than anything else (as far as my experience goes). You need to try to think more in terms of expressions and transformation rules and less in terms of sequential execution of instructions.

Also, a common pattern I see in this forum is notebooks with all of the code in one gigantic cell. This really does make it difficult to debug. My suggestion would be to build up larger expressions from smaller ones. Do some small things in their own cells until you get those working. Then compose them together into a larger expression in another cell. And so on. Maybe people think they're making it easier to read their code if they have one gigantic cell, but the only practical way to start understanding where things go wrong is to start deconstructing that huge cell into smaller chunks. Then the error messages appear close to the offending expression (and maybe you could have figured out for yourself where the problem with Protected was happening).

Anyway, I think you've dug yourself in too far with your current situation. It would be easier to help if we knew what you were trying to do.

POSTED BY: Eric Rimbey
Posted 2 years ago

I only know very little about Lisp and the concept of symbolic langauges is quite different from where I lived :-) It takes quite a rethinking. Thanks for the advice. As many people come from a procedural programming experience, it might be usefull to add some more in the way of How to go from Procedural to Symbolic/Functional programmimng in the documentation.

I have spent almost a week figuring out how to get a result out of a For loop. I looed up the help and all the examples were with Print. I needed the result in a variable and none of the examples gave me that. Same with While loop.

Example :

bb  = Range[20];
endpoint = 9;
dd = {};
For[i = 1, i < 4, i = i + 2,
 dd = Join[dd, 
   List[bb[[i]], bb[[endPoint - i ]], bb[[endPoint - (i + 1)]]]]]   (*  Kind of  rhythmic figur ABB  *)

I did not get a result. Only if I explicitly added the code 'dd' at the end, I get the result of what was inside dd.
That took me a week, as it is completely contrary to normal WL behavior, like :

Times[3,4] which gives me an output. So all the time I was fiddling with the code inside the For loop, thinking there was something wrong there. And this is an example of that I often do not know what to search for. How can you know what you don't know? :-)

Thanks a million for your help, Eric

POSTED BY: B. Cornas
Posted 2 years ago

As to the last part of your answer :

I agree. I often try things out in separate modules. The putting it together, especially with the Dynamic wrappers, can still cause problems. And then it is hard to see to which line of code the error message refers, as WL does not show variable names.

It is always a choice as to ask an abstraction of the problem, or as you suggets, a wider view as to what actually should happen. In the latter case, the code I'd need to post would be quite some larger :-)

POSTED BY: B. Cornas
Posted 2 years ago

Set::write: Tag First in First[numPoints] is Protected.

Set::write: Tag Last in Last[numPoints] is Protected.

As for these errors, they're actually pretty self-explanator, although you do need to understand Mathematica's computation model. You have this line:

First[numPoints] = 1

This is trying to set DownValues for First. But First has the Attribute Protected (as is typical for built-in functions/symbols). So, to avoid the error, you'd either need to Unset that Attribute (bad idea) or set UpValues for numPoints (won't do what you actually want) or initialize numPoints as a List before you start setting its elements using syntax like this: numPoints[[1]] = 1 (but this also doesn't seem to be what you want just based on what I can infer from your variable names).

POSTED BY: Eric Rimbey
Posted 2 years ago

It might be self explonatory for seasoned users, but alas not for me.

I already am wondering what means : Set::write

I just read about "Down Values" this afternoon, otherwise I would not have understood.

With initiating : numPoints = {1, 6}; the error is gone.

Thanks, this was enlightning :-)

POSTED BY: B. Cornas
Posted 2 years ago

For 1.

If my memory serves, this was the way things behaved many versions ago if had adjacent expressions in a cell with no semicolon separating them. I believe that at some point a feature was added so that Mathematica was "smart" about interpreting what otherwise looks like a product to actually be a compound expression. I guess the intention was to be more user friendly, but it's not really some sort of deep thing that requires careful consideration--probably best to just always add the semicolons. Maybe this feature just can't be easily implemented within a Dynamic. That being said, I don't understand why, if you're using a compound expression semantically, you wouldn't be happy with the actual syntax of CompoundExpression. How could just adding in the proper semicolon break anything?

For 2

I don't believe there is any constraint about terminating the expression wrapped in Dynamic with semicolon. It might not be behaving the way you expect, but I suspect that you're expectations are just not aligned with how Dynamic works.

For 3

I really think your understanding of Dynamic is far out of alignment with its actual design. There is no "Dynamic script". There is simply a Dynamic expression. Dynamic is basically just a wrapper that tells the UI to automatically update at that location when relevant variables are changed elsewhere in the notebook without needing to re-evaluate the cell. It's actually more of a presentation thing than a "script[ing]" thing (although it does have special uses in conjunction with other structures, like controls). You've used Dynamic to wrap a rather large expression with many separate variables, and I can't quite figure out why you'd want to do that. I suspect that Manipulate may be more appropriate (although I didn't didn't take the time to reverse engineer your objective, so I could be wrong). There are scoping constructs if that's what you need: Module, DynamicModule, With, etc.

POSTED BY: Eric Rimbey
Posted 2 years ago

Thanks Eric for your answers, I appreciate.

  1. The reason I wanted to sometimes take out the semicolon, was to see what the value(s) at that point was. So to Debug. Now I have been shown that there is a built in debugger, I will study that and hopefully be able to use it, as it looks very different from the debuggers I know - at least at first sight. I will look into that.

  2. and 3. You are probably right about my conceptions of Dynamic and certainly about how I've expressed it. I know though that Dynamic is a wrapper. I started of with using Manipulate, but soon got stuck by my scripts becoming too long to make them understandable in a Manipulate wrapper. I could not subdivide my script and lost control in the woods of different kinds of brackets and functions. And I could not test my variables (= intermidiate steps) to see where it fell apart. The error messages are quite cryptic at times :-) So I read the docs about Manipulate and Dynamic and decided to go for Dynamic. If I remember correctly, the Manipulate is a wrapper around a Dynamic script part that is being created by Manipulate. But I'm not totally sure that I say this correctly.

Almost all my scripts are being done with Dynamic and I am sure not in the most effective way. But then again, I am still learning and already glad a script is working :-)

I use many separate variables so I can see (debug) where I go wrong. If I do much in 1 compound function, I have no idea where I mess up. When a script works, I try tyo compact it, but it has not top priority for me. And of course I want to learn better as well.

POSTED BY: B. Cornas
Posted 2 years ago

Yes, now it is ok. I hope I remember for next time :-)

POSTED BY: B. Cornas
Posted 2 years ago

Thanks, your explanation makes sense. As opposed to the directions on screen :-) I will see if I can Edit my previous post as to 'Attach' the Nb

POSTED BY: B. Cornas
Posted 2 years ago

I attached a Notebook as example, but now I see my response, it looks very strange. The code is inline and the Nb is not as an attachment. Sorry, I have done it right I thought : I used the button "Add Notebook" and browsed to my Nb and clicked 'Add' whatever was asked.

I found the Debugger. Looks very unfamiliar to me, but I will study it first, before asking more :-)

I tried again to attach the Nb. Again the same strange effect. The code is inline in the message and at the end is a very long pink rectangle (error output), which is not in my Nb.

I don't get it. How do attach a Nb properly?

POSTED BY: B. Cornas
Posted 2 years ago

How to attach a Nb properly?

Agree that it is a bit confusing. "Add" versus "Attach". My experience:

  • If you want the notebook contents to appear directly in the post, use the editors menu button "Add Notebook". Which you obviously did.

enter image description here

  • If you do not want the notebook to appear directly in the post, use the button "Add a file to this post" at the bottom. That will insert a reference to the notebook which can then be downloaded by the viewer. And opened in Mathematica.

enter image description here

POSTED BY: Hans Milton
Posted 2 years ago

As an example of my question 1 :

I attached an example. I dumbed it down to show what I mean With the semicolon in place (See the annotement in the code (* Annotemen *) it is fine. Deleting the semicolon (there or anywheren inside the Dynamic[ .... ] gives similar results) : a grey 'x' appears, and I get a red output + the following error in the Messages window :

Error message : Set::write: Tag Times in {28,39,48,1,4,70,86,83,14,23} {36,76,41,56,39,6,83,7,59,33} is Protected.

Also at the end of the code I get following warnings :

Set::write: Tag First in First[numPoints] is Protected.

Set::write: Tag Last in Last[numPoints] is Protected.

This behavior does not occur ouside the Dynamic[ ....]

What is the matter here.?

On question 2 : here the last semicolon in Dynamic[ ... ] is there and it works. If I delete the semicolon, I get the output for that line : (pts3 = ), which is not the case for earlier lines inside Dynamic. On eartlier lines, I get what I described under 1.

In other scripts, which I have to search, the last line in a Dynamic script cannot have the semicolon.

I find it sometimes very hard to pose a question coherently, because I experience part of WL behavior as errartic and hard to pinpoint where the trouble or unclearness is.

Thanks for your help.

Attachments:
POSTED BY: B. Cornas
Posted 2 years ago

For 1., 2., 3. can you provide a specific example? Is this what you are trying to do?

Row@{Dynamic[x], " ", Slider[Dynamic[x]]}

For 4. have you tried the built-in debugger?

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

Group Abstract Group Abstract