Tagged Questions
1
vote
2answers
120 views
Write a function that returns the logarithmic derivative
How can we write a function that if we input an expression f, it returns the log derivative $\frac{1}{f} \frac{df}{dx}$. We have to use a conditional or pattern test so that the function accepts any ...
3
votes
1answer
111 views
Downvalues vs. Scoping for Functions
Regarding my recent question on using a default value for a function argument when a pattern was not met yielded some interesting answers, but the general consensus was "Yes this can be done, but ...
2
votes
2answers
111 views
How to achieve Set+Part like behaviour in custom Set function?
So I've been toiling away on my DataFrame package. I've been trying to get Set to work with it, but it seems it either can't be done (ie via ...
6
votes
4answers
170 views
Function argument to default under certain condition
Inspired by this and this question (and how I handle this in practice), what is the best way to default a function value when a certain condition is met?
For example, if a function is defined as:
...
4
votes
2answers
153 views
Pattern matching repeated structures with named subexpression components
I am trying to write a function with a pattern that tests its arguments for a particular structure. But in that pattern I'd like to name a subpattern to make it easier to exract and operate on.
The ...
1
vote
2answers
95 views
A function that only evaluates on lists of pairs [duplicate]
Possible Duplicate:
Why doesn’t PatternTest work with Composition?
I'd like my function to only evaluate when the argument is a list of pairs. It seems like ...
12
votes
2answers
181 views
Pattern that matches colors
Suppose I'm writing a function that takes a color as a parameter; for example:
drawShape[color_] := Graphics[{Style[Disk[], color]}];
But if the caller inputs an ...
11
votes
4answers
283 views
Assessing argument type in set delayed function definitions
I'm wondering how to properly assess the type of arguments passed to functions defined with :=. I want my functions to be the most efficient, unambiguous and clear ...
14
votes
5answers
760 views
The difference between 0. and 0
I have a function for which 0 is a special case:
f[A___, 0, B___] := 0
But since I am doing numerics, sometimes in the course ...
14
votes
3answers
210 views
What's wrong with this pattern of the form Except[Repeated[…]]?
I'm trying to build a head that recognizes molecules. Here's the code
...
9
votes
1answer
333 views
How to Combine Pattern Constraints and Default Values for Function Arguments
EDIT: As several respondents have noted in the answers and comments below, the original example had a default value that would never be used because of the way patterns and default values are ...
4
votes
1answer
182 views
14
votes
6answers
562 views
Using patterns in pure functions
Pure functions may be handy if you don't want to assign your function a name. For example I would calculate $x(x-1)$ for some numbers $x$ by
...
10
votes
3answers
463 views
Passing down arguments
In R, one can use ... to pass arguments down to another function. For example
...

