Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #7394 > unrolled thread
| Started by | Oliver Ruebenkoenig <ruebenko@wolfram.com> |
|---|---|
| First post | 2011-12-22 09:30 +0000 |
| Last post | 2011-12-22 09:30 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: NMinimize problem: fct minimized uses FindRoot Oliver Ruebenkoenig <ruebenko@wolfram.com> - 2011-12-22 09:30 +0000
| From | Oliver Ruebenkoenig <ruebenko@wolfram.com> |
|---|---|
| Date | 2011-12-22 09:30 +0000 |
| Subject | Re: NMinimize problem: fct minimized uses FindRoot |
| Message-ID | <jcutcf$dkf$1@smc.vnet.net> |
On Wed, 21 Dec 2011, DrMajorBob wrote:
>> So have you now changed your mind about Throw/Catch to consider it (or at
>> least its two-argument form) troublesome and/or leading to spaghetti
>> code?
>
> I didn't change my mind at all. I rarely do, as some may have noticed.
>
> Throw/Catch didn't Compile, did it? So the combination of Throw/Catch and
> Compile is troublesome. GoTo and Label encourage spaghetti code. My
> alternative avoids both.
>
> (Compile's success or failure seems unpredictable in general, so I don't
> use THAT very much, either. I rarely need anything to run in nanoseconds,
> when microseconds will do.)
>
That is not true in V8 since you can either inspect the output with
CompilePrint or use the options that report on various issues that may
come up during compile.
Oliver
> Bobby
>
> On Tue, 20 Dec 2011 02:05:03 -0600, Oleksandr Rasputinov
> <oleksandr_rasputinov@hmamail.com> wrote:
>
>> On Mon, 19 Dec 2011 12:17:22 -0000, DrMajorBob <btreat1@austin.rr.com>
>> wrote:
>>
>>> I see no reason not to write it THIS way:
>>>
>>> cf3 = Compile[{{n, _Integer}},
>>> Module[{sum = 0, i = 0}, While[i < n && sum <= 10, i++; sum += i];
>>> If[sum > 10, 0, sum]]]
>>
>> The point of the example is to demonstrate that the compiler can handle
>> arbitrary exprs when they appear as labels and thus that there is no
>> reason in principle the two-argument form of Throw/Catch could not be
>> compiled as long as the tag was not to be treated as a pattern. I thought
>> it would be helpful to demonstrate this with a program that actually does
>> something, albeit something trivial (i.e. squaring a number) accomplished
>> in a way that I sincerely hope nobody would use in practice. Perhaps this
>> makes the original intent clearer:
>>
>> With[{loop = Plot[Sin[x], {x, -Pi, Pi}]},
>> cf = Compile[{{x, _Integer, 0}},
>> Block[{i = x, n = 0}, Label[loop];
>> n += x;
>> If[--i > 0, Goto[loop]];
>> n
>> ]
>> ]
>> ]
>>
>>> It's not that I don't know how to write spaghetti code! I probably wrote
>>> more Fortran 5 in 1977-1982 than I've written in all other languages
>>> combined. (Demon, IBM Assembler, PL/1, Simscript, QGERT, SAS, MathCAD,
>>> Mathematica, and others I probably forget.)
>>>
>>> But, if there's no reason for a troublesome construct, I plan to avoid
>>> it.
>>
>> So have you now changed your mind about Throw/Catch to consider it (or at
>> least its two-argument form) troublesome and/or leading to spaghetti
>> code?
>> When the only viable alternative (as things stand) is Label/Goto, isn't
>> it
>> the lesser of two evils?
>>
>
>
> --
> DrMajorBob@yahoo.com
>
>
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web