🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.logo
Article #277

Re: um, maybe this is a silly question

#277
From: Matt Wright
Date: Fri, 16 Oct 1992 17:03
33 lines
1547 bytes
Ken Kahn writes:
>  To my way of thinking it is perhaps the
>most natural of the bunch.  Namely, write or use something that will generate
>a list of numbers and then multiply them together.  This is the APL-style of
>doing factorial.

In ISETL, another programming language that they use a lot in education, 
you say

	factorial := {x -> % * [1..x]}

E.g., "assign to the variable factorial the following value: a function that
maps x to the answer you get by reducing the list of numbers from 1 to x by
multiplying them all together."

You could do something like this in any language with first-class
functions.  (Or even LOGO, which merely has RUN and dynamic scope.)

TO ONETO :X
IF :X = 0 [OUTPUT []]
OUTPUT SE ONETO :X-1 :X
END

TO REDUCE :SENT :OP
IF EMPTYP BF :SENT [OP FIRST :SENT]
OUTPUT RUN (SE :OP FIRST :SENT REDUCE BF :SENT :OP)
END

TO FACTORIAL :N
OP REDUCE ONETO :N "PRODUCT
END

-Matt
Technical Details
Message-ID: <1992Oct16.170334.6412@pasteur.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!sparky!uunet!ukma!usenet.ins.cwru.edu!agate!pasteur!volga.Berkeley.EDU!matt
References: <1992Oct14.175140.12286@cbfsb.cb.att.com> <MAX.92Oct15085643@Kolmogorov.gac.edu> <1992Oct16.155921.16311@Csli.Stanford.EDU>

Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.logo
Path: arc1-ca.pugleaf.net!sparky!uunet!ukma!usenet.ins.cwru.edu!agate!pasteur!volga.Berkeley.EDU!matt
From: matt@volga.Berkeley.EDU (Matt Wright)
Subject: Re: um, maybe this is a silly question
Message-ID: <1992Oct16.170334.6412@pasteur.Berkeley.EDU>
Sender: nntp@pasteur.Berkeley.EDU (NNTP Poster)
Nntp-Posting-Host: volga.berkeley.edu
Organization: University of California, at Berkeley
References: <1992Oct14.175140.12286@cbfsb.cb.att.com> <MAX.92Oct15085643@Kolmogorov.gac.edu> <1992Oct16.155921.16311@Csli.Stanford.EDU>
Distribution: usa
Date: Fri, 16 Oct 1992 17:03:34 GMT
Lines: 33