Article View: comp.lang.logo
Article #241Re: um, maybe this is a silly question
From: Brian Harvey
Date: Fri, 09 Oct 1992 14:20
Date: Fri, 09 Oct 1992 14:20
46 lines
2178 bytes
2178 bytes
The answer
make "x 12
is correct but really only answers part of the question.
In languages like BASIC and C, there is a heavy emphasis on the style of
programming in which instructions are executed in sequence, and most of
those instructions change the values of variables. (In BASIC this is
because the language is not capable of any alternative; in C, it's because
the can't-teach-an-old-dog programmers aren't.)
In Logo it's not very common to use MAKE at all, or to change the value
of a variable in any other way. Instead, Logo emphasizes functional
programming, in which the computation progresses when a function calls
another function. (The function can call itself; that's recursion, which
Logo uses instead of conventional looping structures like WHILE.)
Example: Euclid's GCD algorithm, both ways:
------------------------------ C ------------------------------
int gcd(int a, int b)
{
while (b != 0) {
int temp = b;
b = a % b;
a = temp;
}
return a;
}
------------------------------ Logo ------------------------------
to gcd :a :b
if :b = 0 [output :a]
output gcd :b (remainder :a :b)
end
======================================================================
The point to notice is the complete absence of assignment instructions
in the Logo (recursive) version. (Also, along with that, there's no
need for the extra variable temp.) It would be possible to write it
the same way in C, but most C programmers wouldn't.
I hope I'm not insulting you by telling you things you knew already;
the original message didn't make that clear.
Technical Details
Message-ID:
<1b44g5INNqq1@agate.berkeley.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!agate!anarres.CS.Berkeley.EDU!bhReferences:
<1992Oct9.065708.25074@muddcs.claremont.edu> <1992Oct9.123626.15852@cbfsb.cb.att.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!agate!anarres.CS.Berkeley.EDU!bh From: bh@anarres.CS.Berkeley.EDU (Brian Harvey) Newsgroups: comp.lang.logo Subject: Re: um, maybe this is a silly question Date: 9 Oct 1992 14:20:53 GMT Organization: University of California, Berkeley Lines: 46 Distribution: usa Message-ID: <1b44g5INNqq1@agate.berkeley.edu> References: <1992Oct9.065708.25074@muddcs.claremont.edu> <1992Oct9.123626.15852@cbfsb.cb.att.com> NNTP-Posting-Host: anarres.cs.berkeley.edu