Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

What's it called

Name: Anonymous 2011-01-10 10:24

Is there a term for a type of program that is guaranteed to always produce the same output?  For example, it never accepts keyboard input, never reads a timer, etc, so it must always follow the same execution path.

The only term that comes to mind is "deterministic" but that's not quite right.

Name: Anonymous 2011-01-10 10:25

Read SICP

Name: Anonymous 2011-01-10 10:31

Highly optimisable.

Name: Anonymous 2011-01-10 10:33

>>3
lol'd

Name: Anonymous 2011-01-10 10:40

IDEMPOTENT
REENTRANT

Name: Anonymous 2011-01-10 10:44

IDEMPOTENT
A WinZip is you

Name: Anonymous 2011-01-10 10:49

No such thing exist.

Name: Anonymous 2011-01-10 10:53

WHAT IF this same program was modified to output only how long it took to run?

Name: Anonymous 2011-01-10 11:04

>>8
Define "how long it takes". The running time (O) is the same across different machines, whereas time probably isn't.

Name: Anonymous 2011-01-10 11:37

>>8,9
Well, the running time is pretty much just the number of instructions multiplied by the average time for each instruction. So you could just forego any calculation for that and output a constant.
Overall, a slightly pointless 'what if'.

Name: Anonymous 2011-01-10 12:08

>>3
nice.

Name: Anonymous 2011-01-10 12:49

>>3
I lol'd

Name: Anonymous 2011-01-10 13:30

>>7
int main(int, char**) { return 17; }

Name: Anonymous 2011-01-10 15:10

>>13
_start: mov eax,17
        ret

Name: Anonymous 2011-01-10 16:02

>>14
import sys;sys.exit(17)

Name: Anonymous 2011-01-10 16:18

(exit 17)

Name: Anonymous 2011-01-10 17:16

return new int(17);

Name: Anonymous 2011-01-10 18:27

>>13
>>14
>>15
>>16
>>17

None of which are guaranteed to produce the same output every time.

Name: Anonymous 2011-01-10 18:29

>>18
I think your compiler might have a bug.

Name: Anonymous 2011-01-10 18:31

>>1
A functional function.

Name: Anonymous 2011-01-10 18:32

>>3
Funny you should say that...  My motivation for asking was thinking about writing a compiler that let you declare certain sections of your code as "idempotent" (now that I know the term) and having it actually execute these sections of code at build time.

Name: Darkr 2011-01-10 18:32

It's called purity.  A pure function is one which will always produce the same output given a particular input.  Any function which isn't pure is said to have side effects.  Purely functional languages such as Haskell try to be as pure as possible.  It's obviously not possible for everything, but the idea is to limit the side effects to only where it's necessary.

Name: Darkr 2011-01-10 19:16

>>21

That feature exists in the D programming language.  It's called Compile-Time Function Evaluation (CTFE).  It can also be done with C++ templates.

Name: Anonymous 2011-01-10 20:14

>>22
This is inaccurate -- in addition to having no side effects, a pure function must also not depend on external state or be non-deterministic. Thus being impure is not sufficient to have side effects.

Name: Anonymous 2011-02-03 5:17

Name: Anonymous 2011-02-04 15:40

Don't change these.
Name: Email:
Entire Thread Thread List