🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #896

Re: Proof that Prolog can be faster than C

#896
From: Peter Van Roy
Date: Fri, 15 Jun 1990 22:09
47 lines
1988 bytes
In article <1990Jun15.205242.16314@agate.berkeley.edu> dankg@volcano.Berkeley.EDU (Dan KoGai) writes:

>	But this C code is hardly optimum.  1st of all you don't need
>a1, a2, a3 to waste space and time. try the following.
>
>int tak(int x, int y, int z)
>{
>	return (x <= y) ? z : tak(tak(--x, y, z),tak(--y, z, x),tak(--z, x, y))
>
>}
>
>> [Prolog version omitted]
>
>____  __  __    + Dan The Walking C Obfscunator

Did you try to run this program?
It behaves very strangely:
(after adding a semicolon to the return statement)

	mammoth:~/Peter <20> cc -g taktak.c
	mammoth:~/Peter <21> dbx a.out
	dbx version 2.0
	Copyright 1988 MIPS Computer Systems Inc.
	Type 'help' for help.
	reading symbolic information ...
	main:  15  printf("%d\n", tak(24, 16, 8));
	(dbx) run
	^C				<- interrupted after ~10 seconds
	Interrupt [tak:10 +0x28,0x400220]
        	tak(--z, x, y));
	(dbx) print x,y,z
	-44896 -44897 -44898		<- strange values

From page 186 of K&R:
(note that predecrement does a side-effect)

	[Regarding function evaluation] The order of evaluation of arguments
	is undefined by the language; take note that the various compilers
	differ.

By the way, I did try a different version of tak.c without the temporary
variables a1, a2, and a3.  It ran *slower* unoptimized and at exactly the
same speed optimized.

Please think before you post.
Sincerely,
	Peter Van Roy
Technical Details
Message-ID: <37066@ucbvax.BERKELEY.EDU>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!aplcen!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!usc!ucsd!ucbvax!pisces!vanroy
References: <36986@ucbvax.BERKELEY.EDU> <1990Jun15.205242.16314@agate.berkeley.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!aplcen!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!usc!ucsd!ucbvax!pisces!vanroy
From: vanroy@pisces (Peter Van Roy)
Newsgroups: comp.lang.prolog,comp.lang.c
Subject: Re: Proof that Prolog can be faster than C
Keywords: Prolog, tak
Message-ID: <37066@ucbvax.BERKELEY.EDU>
Date: 15 Jun 90 22:09:22 GMT
References: <36986@ucbvax.BERKELEY.EDU> <1990Jun15.205242.16314@agate.berkeley.edu>
Sender: usenet@ucbvax.BERKELEY.EDU
Reply-To: vanroy@pisces (Peter Van Roy)
Organization: University of California at Berkeley
Lines: 47