Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
Questions on writing non-trivial programs in Mathematica. Do not use this tag for questions on plotting/graphics or for questions on doing mathematics with Mathematica, where the focus is more on the math than the program.
8
votes
Accepted
How can I use nested conditionals inside my functions?
I think the general notion here is that conditional patterns x_/;EvenQ[x] and conditional expressions If[EvenQ[x],a,b] are not the same thing. In your first example, you nest conditional patterns in t …
8
votes
Accepted
Dynamic lists as function arguments
You should try to just follow the flow of your replacements, then you clearly see what's going wrong. In you first definition everything goes as you expect:
g[point_] := Slider2D[point]
g[Dynamic[p]] …
3
votes
Is it possible to replicate the "magic" of OptionPatterns[] with DynamicModule's local varia...
If you want each component to have access to the entire scope, rather then pass it through as an argument to a function, you can also just not have any function at all:
Component1 := Button["Increas …
1
vote
Control over depth-first scan and breadth-first scan
The answer by Mr. Wizard that Daniel linked to is easily hacked to include a stop condition, you simply take the recursive function, but filter the next level depending on your stopping criterion.
st …
7
votes
Accepted
Equivalent of Python's "all" function in Mathematica
initial side note: As J.M. correctly points out this is not an efficient implementation and serves only to illustrate behavior similar to the Python function all.
If you are looking for a similar de …
11
votes
Accepted
Why is MapIndexed better than mapping over a range?
I believe I know exactly why jVincent chose MapIndexed rather then mapping over range. As rm-rf states, it does seem semantically simpler, however that's not the reason. It's due to habit and scaling. …
5
votes
Pure Functions with Lists as arguments
Mr. Wizard already linked to my previous answer on deconstruction, but I though I'd add a solution using it anyway, since it seems to translate almost directly from the function definition which might …
8
votes
Accepted
Scope within Context
I'm just going to go ahead an rephrase the answer. The problem as Leonid points out is akin to shadowing. Here is a very simple example of the behavoir:
Remove[test`x, x]
(
Begin["test`"];
x = 42;
En …
19
votes
How to implement dual numbers in Mathematica?
If you use the matrix representation, addition and multiplication works by default, but you need to use matrix multiplication and not just space (which is element-wise multiplication), for instance f[ …
17
votes
How to perform a breadth-first traversal of an expression?
Here is a simple implementation of a breadth first traversal. It simply maps the function onto each element on the current level and then collects all non-atomic entries into the next level, rinse and …
6
votes
How to ensure that Polygon[list] plots a simple polygon?
I'm assuming from your explanation that you aren't actually just interested in the convex hull, but simply inserting points into a polygon without creating self-intersecting lines. In this case, you c …
11
votes
Elegant manipulation of the variables list
Here's an approach similar to Simon Woods, but using Extract itself rather then following replacement rules:
setTo[val_] := Function[var, var = val, HoldAll]
mySymbolName = Function[var, ToString[U …
1
vote
How to leave function unevaluated programmatically?
I'm going to go out on a limb here and just assume that your problem is that you are nesting conditionals inside your code definitions, and that deeper levels are ignored. If that is the case, what yo …
7
votes
Accepted
How to leave function unevaluated programmatically?
Your posted code does not work because some of the code you want to evaluate is given as an argument to Condition which holds its arguments, you could make it work by changing this
f[x_] := Block[{an …
3
votes
More structure in Source Code/Notebooks
I typically go from prototyping some code to a structured functional interface through pretty much the steps you described. Starting out with
a=3;
b=a^2+3;
Sin[a]+Cos[b];
Or similar string of r …