[Date Index]
[Thread Index]
[Author Index]
Prefix Notation
*To*: mathgroup at smc.vnet.net
*Subject*: [mg51654] Prefix Notation
*From*: DrBob <drbob at bigfoot.com>
*Date*: Wed, 27 Oct 2004 23:43:34 -0400 (EDT)
*References*: <200410270554.BAA24573@smc.vnet.net> <opsgir6amviz9bcq@monster.cox-internet.com> <9BB7BB28-282E-11D9-B7B7-000D9350C9C2@videotron.ca>
*Reply-to*: drbob at bigfoot.com
*Sender*: owner-wri-mathgroup at wolfram.com
> May I ask a naive question? What's the difference between @ and []
> when calling a built-in function, for example, Length@theSeries cf.
> Length@theSeries?
f@x takes one less keystroke than f[x], and it thins the forest of brackets that can make code so unreadable. I typically use @ whenever f has only one argument, if the argument doesn't need anything to separate it from everything else. I'd usually use f[x+y], for instance, not f@(x+y), though both are equivalent.
(It doesn't matter whether f is built-in or not.)
Look up Prefix in Help, and you'll also see Infix and Postfix notations mentioned.
There are times when a combination of all three may be more understandable, as in:
f[x ~g~ y ~g~ z // h, options]
rather than
f[h[g[x,y,z]],options]
I rarely use Infix except for "+", "*", ".", "&&", and "||" which are shorthand for "~Plus~", "~Times~", "~Dot~", "~And~", and "~Or~". There are symbols for ~Union~, ~Intersection~, and a few others, too.
Bobby
On Wed, 27 Oct 2004 11:41:03 -0400, Gregory Lypny <gregory.lypny at videotron.ca> wrote:
> Thanks once again, Bobby. It's fixed.
>
> I think my problems with defining functions have to do with using "="
> rather than ":=". I used the constant 1,000 because I thought
> Length[theSeries] might have been the source of the problem.
>
> May I ask a naive question? What's the difference between @ and []
> when calling a built-in function, for example, Length@theSeries cf.
> Length@theSeries?
>
> Regards,
>
> Greg
>
> On Oct 27, 2004, at 4:21 AM, DrBob wrote:
>
>> MA[theSeries_,theWindowSize_]:
>> =PadLeft[MovingAverage[theSeries,theWindowSize],
>> Length@theSeries];
>> Range@10
>> MA[Range@10,3]
>>
>> {1,2,3,4,5,6,7,8,9,10}
>>
>> {0,0,2,3,4,5,6,7,8,9}
>>
>> That seems to do what you asked for.
>>
>> Why did you have the constant 1000 hardwired in your version?
>>
>> Bobby
>>
>> On Wed, 27 Oct 2004 01:54:37 -0400 (EDT), Gregory Lypny
>> <gregory.lypny at videotron.ca> wrote:
>>
>>> Hello Everyone,
>>>
>>> I'd like to create some custom moving average functions that retain
>>> the
>>> same length as the original series by padding the lost observations
>>> with zeros. I can get the moving average part of the function to work
>>> but not the padding part.
>>>
>>> This part without padding works:
>>>
>>> MA[theSeries_, theWindowSize_] = MovingAverage[theSeries,
>>> theWindowSize];
>>>
>>> But adding the padding causes it to fail:
>>>
>>> MA[theSeries_, theWindowSize_] = PadLeft[MovingAverage[theSeries,
>>> theWindowSize], 1000];
>>>
>>> Any suggestions would be most appreciated.
>>>
>>> Greg
>>>
>>>
>>>
>>>
>>
>
>
>
>
--
DrBob at bigfoot.com
www.eclecticdreams.net
Prev by Date:
**Re: Another bizarre phenomenon**
Next by Date:
**Re: cross-product in cylindrical problem**
Previous by thread:
**Re: Creating a Moving Average Function**
Next by thread:
**Re: Creating a Moving Average Function**
| |