From: Grant Henderson
Subject: Prime Numbers Program
Date: 
Message-ID: <SKH46.418$293.40379@news3.cableinet.net>
Hi,
Are there any programs that can output prime numbers from a set of given
integers.

I've done it in c++ but non-procedural programming requires a different way
of thinking :-)

Cheers

From: Colin Walters
Subject: Re: Prime Numbers Program
Date: 
Message-ID: <87ofxok25w.church.of.emacs@meta.verbum.org>
"Grant Henderson" <·········@cableinet.co.uk> writes:

> I've done it in c++ but non-procedural programming requires a
> different way of thinking :-)

Well, you can program "procedurally" in Lisp.  This is my favorite
thing about it; you don't have to subscribe to one particular
philosophy of programming - you are free to choose whatever suits your
taste (and the problem at hand).
From: Barry Margolin
Subject: Re: Prime Numbers Program
Date: 
Message-ID: <RNI46.43$YQ2.607@burlma1-snr2>
In article <···················@news3.cableinet.net>,
Grant Henderson <·········@cableinet.co.uk> wrote:
>Hi,
>Are there any programs that can output prime numbers from a set of given
>integers.
>
>I've done it in c++ but non-procedural programming requires a different way
>of thinking :-)

Since Lisp can be used as a procedural programming language, what's your
problem?  I expect I would write this program in Lisp much the same way as
I would in C.

-- 
Barry Margolin, ······@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Lieven Marchand
Subject: Re: Prime Numbers Program
Date: 
Message-ID: <m3elykd1ra.fsf@localhost.localdomain>
"Grant Henderson" <·········@cableinet.co.uk> writes:

> Hi,
> Are there any programs that can output prime numbers from a set of given
> integers.
> 
> I've done it in c++ but non-procedural programming requires a different way
> of thinking :-)
> 

Heh?

CL supports procedural programming just fine. The following should map
fairly directly to an STL based C++ solution.


(remove-if-not #'prime sequence-of-given-integers)

with e.g.

(defun prime (n)
  (loop for i from 2 to (isqrt n)
	when (zerop (mod n i)) (return nil)
	finally (return t)))

Note that there are more efficient prime testing algorithms.

-- 
Lieven Marchand <···@village.uunet.be>
Gla�r ok reifr skyli gumna hverr, unz sinn b��r bana.
From: Knut Arild Erstad
Subject: Re: Prime Numbers Program
Date: 
Message-ID: <slrn9570il.4l7.knute+news@tjeld.ii.uib.no>
[Grant Henderson]
: Hi,
: Are there any programs that can output prime numbers from a set of given
: integers.

This function is a possible starting point, it works by "filtering out"
non-primes from a bit vector.

(defun primes-upto (n)
  "Returns a bit vector B of size n+1, where (bit B i) = 1 iff i is a 
prime number."
  (let ((b (make-array (1+ n) :element-type 'bit :initial-element 1)))
    (setf (bit b 0) 0
	  (bit b 1) 0)
    (let ((i 2)
	  (sqrt-n (floor (sqrt n))))
      (loop while (<= i sqrt-n) do
	    ;; Find i = next prime number = next nonzero element of vector
	    (loop while (zerop (bit b i)) do (incf i))
	    ;; Remove multiples of i (by setting them to 0)
	    (loop for j from (* i 2) by i to n do
		  (setf (bit b j) 0))
	    (incf i)))
    b))

-- 
Knut Arild Erstad
From: Geoffrey Summerhayes
Subject: Re: Prime Numbers Program
Date: 
Message-ID: <bVT46.22557$n%.1147037@news20.bellglobal.com>
----- Original Message -----
From: "Grant Henderson" <·········@cableinet.co.uk>
Newsgroups: comp.lang.prolog,comp.lang.lisp
Sent: January 3, 2001 10:41 AM
Subject: Prime Numbers Program


| Hi,
| Are there any programs that can output prime numbers from a set of given
| integers.
|
| I've done it in c++ but non-procedural programming requires a different
way
| of thinking :-)
|
| Cheers

Since all your responses are from the lisp side, I thought I'd answer from
the prolog side. Yes, there are. (prolog is Turing-complete. Dumb call,
anyone know of a computer language that isn't?)

Geoff
From: Colin Walters
Subject: Re: Prime Numbers Program
Date: 
Message-ID: <877l4bkdtd.church.of.emacs@meta.verbum.org>
"Geoffrey Summerhayes" <·············@hNoOtSmPAaMil.com> writes:

> Since all your responses are from the lisp side, I thought I'd
> answer from the prolog side. Yes, there are. (prolog is
> Turing-complete. Dumb call, anyone know of a computer language that
> isn't?)

I've heard Charity isn't.
From: Joe Marshall
Subject: Re: Prime Numbers Program
Date: 
Message-ID: <ae97ntx4.fsf@content-integrity.com>
"Geoffrey Summerhayes" <·············@hNoOtSmPAaMil.com> writes:

> (prolog is Turing-complete. Dumb call, anyone know of a computer
> language that isn't?)

I haven't been fortunate enough to find a language implementation that
was more powerful than a sufficiently large finite-state machine.


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----
From: ········@let.rug.nl
Subject: Re: Prime Numbers Program
Date: 
Message-ID: <932gi0$l1b$1@syn.let.rug.nl>
In comp.lang.prolog Joe Marshall <···@content-integrity.com> wrote:
> "Geoffrey Summerhayes" <·············@hNoOtSmPAaMil.com> writes:

>> (prolog is Turing-complete. Dumb call, anyone know of a computer
>> language that isn't?)

> I haven't been fortunate enough to find a language implementation that
> was more powerful than a sufficiently large finite-state machine.

what else can you expect on finite hardware?

-- 
Gertjan van Noord Alfa-informatica, RUG,  Postbus 716, 9700 AS Groningen
vannoord at let dot rug dot nl            http://www.let.rug.nl/~vannoord
From: Geoffrey Summerhayes
Subject: Re: Prime Numbers Program
Date: 
Message-ID: <5De56.56084$f36.2678553@news20.bellglobal.com>
"Joe Marshall" <···@content-integrity.com> wrote in message
·················@content-integrity.com...

> I haven't been fortunate enough to find a language implementation that
> was more powerful than a sufficiently large finite-state machine.

ROTFL--that's BRILLIANT, I can't wait to share this(Damn, nobody will get
it)!

Geoff
From: ········@hex.net
Subject: Re: Prime Numbers Program
Date: 
Message-ID: <gTe56.167100$IP1.5946988@news1.giganews.com>
"Geoffrey Summerhayes" <·············@hNoOtSmPAaMil.com> writes:
> "Joe Marshall" <···@content-integrity.com> wrote in message
> ·················@content-integrity.com...
> > I haven't been fortunate enough to find a language implementation that
> > was more powerful than a sufficiently large finite-state machine.
> 
> ROTFL--that's BRILLIANT, I can't wait to share this(Damn, nobody will get
> it)!

.. And that was more or less the conclusion I came to at the end of
my computing theory course.  _Basically_ all our computers are all
FSMs as opposed to being Turing Machines.  

It's just that they've got so vastly many states that people make the
mistake of thinking they're TMs.
-- 
(reverse (concatenate 'string ····················@" "454aa"))
<http://www.ntlug.org/~cbbrowne/>
"...Roxanne falls in love with Christian, a chevalier in Cyrano's
regiment who hasn't got the brains God gave an eclair..."
-- reviewer on NPR
From: Andrew Bromage
Subject: Re: Prime Numbers Program
Date: 
Message-ID: <933uao$726@goaway.cc.monash.edu.au>
G'day all.

Joe Marshall <···@content-integrity.com> writes:

>I haven't been fortunate enough to find a language implementation that
>was more powerful than a sufficiently large finite-state machine.

Technical nit: Your hypothetical finite-state machine in question would
need to have different start states depending on the program input,
which is not really covered in any text on FSM analysis that I've seen.

I think you meant to say "linear bounded automaton".

Cheers,
Andrew Bromage
From: Rob Warnock
Subject: Re: Prime Numbers Program
Date: 
Message-ID: <934d0v$lfgs8$1@fido.engr.sgi.com>
Andrew Bromage <·······@goaway.cc.monash.edu.au> wrote:
+---------------
| Joe Marshall <···@content-integrity.com> writes:
| >I haven't been fortunate enough to find a language implementation that
| >was more powerful than a sufficiently large finite-state machine.
| 
| Technical nit: Your hypothetical finite-state machine in question would
| need to have different start states depending on the program input...
+---------------

Not necessarily so. The FSM in question is usually called
"the CPU's instruction set", including the "cold boot" sequence.  ;-}  ;-}

What you're calling "the program input" could be viewed as just
more input data...


-Rob

-----
Rob Warnock, 31-2-510		····@sgi.com
SGI Network Engineering		http://reality.sgi.com/rpw3/
1600 Amphitheatre Pkwy.		Phone: 650-933-1673
Mountain View, CA  94043	PP-ASEL-IA
From: Thomas Charles CONWAY
Subject: Re: Prime Numbers Program
Date: 
Message-ID: <9313vo$5sd$1@ender.cs.mu.OZ.AU>
"Geoffrey Summerhayes" <·············@hNoOtSmPAaMil.com> writes:

>Since all your responses are from the lisp side, I thought I'd answer from
>the prolog side. Yes, there are. (prolog is Turing-complete. Dumb call,
>anyone know of a computer language that isn't?)

IIRC, SQL isn't.

-- 
 Thomas Conway              Mercurian )O+  
 <······@cs.mu.oz.au>       Every sword has two edges.
From: Geoffrey Summerhayes
Subject: Re: Prime Numbers Program
Date: 
Message-ID: <aYd56.55903$f36.2675026@news20.bellglobal.com>
"Thomas Charles CONWAY" <······@ender.cs.mu.OZ.AU> wrote in message
·················@ender.cs.mu.OZ.AU...
> "Geoffrey Summerhayes" <·············@hNoOtSmPAaMil.com> writes:
>
> >Dumb call,
> >anyone know of a computer language that isn't?)
>
> IIRC, SQL isn't.

Damn. I forgot about SQL, although all the talk about OODBMS and the
proposed upgrading of SQL might just fix this? ROTFL Now that I think about
it, is it possible to use HTML plus CSS to build a Turing machine? (not
sure, I spent too much time LOL at people who were convinced they were
programmers because they could produce a web page.(HTM(L stands for
language, right?)))

still here,
Geoff

"I write the occasional snark, the boojums come from what's-her-face's
code"--Me
From: Geoff Summerhayes
Subject: Re: Prime Numbers Program
Date: 
Message-ID: <t5bqkf61u0re89@corp.supernews.com>
"Geoffrey Summerhayes" <·············@hNoOtSmPAaMil.com> wrote in message
····························@news20.bellglobal.com...
>
<SNIP the HTML stuff>

Sorry about that really dumb thought. Was at a millenium party last night,
obviously too long. :-)
From: Thomas Charles CONWAY
Subject: Re: Prime Numbers Program
Date: 
Message-ID: <933rai$c7c$1@ender.cs.mu.OZ.AU>
"Geoffrey Summerhayes" <·············@hNoOtSmPAaMil.com> writes:

>Damn. I forgot about SQL, although all the talk about OODBMS and the
>proposed upgrading of SQL might just fix this? ROTFL Now that I think about
>it, is it possible to use HTML plus CSS to build a Turing machine? (not
>sure, I spent too much time LOL at people who were convinced they were
>programmers because they could produce a web page.(HTM(L stands for
>language, right?)))

XSLT is definitely turing complete.
Not sure about CSS.

-- 
 Thomas Conway              Mercurian )O+  
 <······@cs.mu.oz.au>       Every sword has two edges.
From: Klaas
Subject: Re: Prime Numbers Program
Date: 
Message-ID: <cIx66.115694$Z2.1370155@nnrp1.uunet.ca>
Geoffrey Summerhayes <·············@hNoOtSmPAaMil.com> wrote in
message ····························@news20.bellglobal.com...
>
> "Thomas Charles CONWAY" <······@ender.cs.mu.OZ.AU> wrote in message
> ·················@ender.cs.mu.OZ.AU...
> > "Geoffrey Summerhayes" <·············@hNoOtSmPAaMil.com> writes:
> >
> > >Dumb call,
> > >anyone know of a computer language that isn't?)
> >
> > IIRC, SQL isn't.
>
> Damn. I forgot about SQL, although all the talk about OODBMS and the
> proposed upgrading of SQL might just fix this? ROTFL Now that I
think about
> it, is it possible to use HTML plus CSS to build a Turing machine?
(not
> sure, I spent too much time LOL at people who were convinced they
were
> programmers because they could produce a web page.(HTM(L stands for
> language, right?)))

But not necessarily a programming language.  Wordperfect formatting
characters are a computer language, and one might argue that the only
difference between that and HTML is that the latter is human readable.

-Mike
From: Paul Rudin
Subject: Re: Prime Numbers Program
Date: 
Message-ID: <m33dez9ral.fsf@cara.scientia.com>
>>>>> "Geoffrey" == Geoffrey Summerhayes <·············@hNoOtSmPAaMil.com> writes:

 Geoffrey> Since all your responses are from the lisp side, I thought
 Geoffrey> I'd answer from the prolog side. Yes, there are. (prolog is
 Geoffrey> Turing-complete. Dumb call, anyone know of a computer
 Geoffrey> language that isn't?)

 ISTR that the language Charity isn't. The language isn't capable of
 expressing non-terminating algorithms.

 My recollection is hazy, so I'd do a web search if you're interested.
From: Geoffrey Summerhayes
Subject: Re: Prime Numbers Program
Date: 
Message-ID: <BZe56.56153$f36.2679962@news20.bellglobal.com>
"Erik Naggum" <····@naggum.net> wrote in message
·····················@naggum.net...

>   Well, any computer language that doesn't have computational ability at
>   all would be such a language, but I guess you don't include languages
>   such as SGML in "computer languages" in this context for precisely that
>   reason.

Bang on the money Erik, one of my favorite Lincoln stories is the one about
tails and legs.

(Of course, how much we can get out of a 'language' may depend on the
implementation. Eww, ick, not portable, forget I said that)

Geoff
From: Jan Klunder
Subject: Re: Prime Numbers Program
Date: 
Message-ID: <9375jn$i58$1@nnrp1.deja.com>
In Elisa I supplied the following example of generating primes:

The prime function optionally returns a prime. It uses an external list
of already found primes to compute the next prime.

prime (list (integer), integer) -> optional (integer);
prime (L, I) = [ if mod (I, items (L)) == 0 then return;
                 add (L, I); I];
Examples of its use are:

L = alist (integer);
prime (L, 2..100)?

More information can be found at:
http://www.xs4all.nl/~jklunder/elisa/part02/doc020.html#2.3.3 Primes

 Jan Klunder

 More about Elisa:    http://www.xs4all.nl/~jklunder/


In article <···················@news3.cableinet.net>,
  "Grant Henderson" <·········@cableinet.co.uk> wrote:
> Hi,
> Are there any programs that can output prime numbers from a set of
given
> integers.
>
> I've done it in c++ but non-procedural programming requires a
different way
> of thinking :-)
>
> Cheers
>
>


Sent via Deja.com
http://www.deja.com/