From: arnuld
Subject: sorting the input
Date: 
Message-ID: <pan.2008.09.11.10.57.09.8448@invalid.address>
Hi all,


I want to write a program in CL which will ask the use to input at stdin
and then when user will press EOF (Ctrl-D in my BASH shell on Linux
system) it will print the words in sorted order, each on a new line. I
have done that in C++, you can see it here:


http://groups.google.com/group/comp.lang.c++/browse_thread/thread/0488e58b666d0eb1#


Now I don't have any clue on how to do it in C++ but I am interested in
doing it in Lisp. I will welcome any hints, views and pointers of
information. Right now I am searching the archives of CLL





-- 
www.lispmachine.wordpress.com
my email is @ the above blog.
Google Groups is Blocked. Reason: Excessive Spamming

From: ················@gmail.com
Subject: Re: sorting the input
Date: 
Message-ID: <c87833cc-96f9-4cb7-a5e4-ef7a4ab769ff@f36g2000hsa.googlegroups.com>
Here are some of the url's of ebooks / lisp-help pages that I am
struggling with right now. You're welcome to use these for your
sorting program.

http://cl-cookbook.sourceforge.net/emacs-ide.html
http://www.gnu.org/software/emacs/emacs-lisp-intro/html_node/index.html
http://www.n-a-n-o.com/lisp/cmucl-tutorials/LISP-tutorial.html#toc17
http://www.gigamonkeys.com/book/
http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/html/cltl/cltl2.html
http://www.lispworks.com/documentation/HyperSpec/Front/index.htm
http://clisp.cons.org/

Good luck.
From: Kenny
Subject: Re: sorting the input
Date: 
Message-ID: <48c9512f$0$7359$607ed4bc@cv.net>
················@gmail.com wrote:
> Here are some of the url's of ebooks / lisp-help pages that I am
> struggling with right now. You're welcome to use these for your
> sorting program.
> 
> http://cl-cookbook.sourceforge.net/emacs-ide.html
> http://www.gnu.org/software/emacs/emacs-lisp-intro/html_node/index.html
> http://www.n-a-n-o.com/lisp/cmucl-tutorials/LISP-tutorial.html#toc17
> http://www.gigamonkeys.com/book/
> http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/html/cltl/cltl2.html
> http://www.lispworks.com/documentation/HyperSpec/Front/index.htm
> http://clisp.cons.org/
> 
> Good luck.

Bah! Forget Lisp, time to move on, last one out leave the Lisp Machine 
on the curb for recycling:

   http://www.javascript.com/
   http://en.wikipedia.org/wiki/JavaScript
   http://www.w3schools.com/js/default.asp
   http://jquery.com/

And my new stomping grounds:

   comp.lang.javascript

hth,kt
From: Thomas F. Burdick
Subject: Re: sorting the input
Date: 
Message-ID: <c38c2182-b06f-4bfb-968e-a56a84392af9@l42g2000hsc.googlegroups.com>
On 11 sep, 19:09, Kenny <·········@gmail.com> wrote:

> And my new stomping grounds:
>
>    comp.lang.javascript

Speaking of which, now that we're in A Brave New World of compiled JS,
who's going to make a Lisp implementation that compiles everything to
JS, to get that good native code love? I need one volunteer to do easy
cross-calling, and another to make a world unto themselves. Bonus
points if the former makes a bastard-child Scheme, and the other does
ILISP-plus-continuations.
From: Bakul Shah
Subject: Re: sorting the input
Date: 
Message-ID: <48C98181.40900@bitblocks.com>
Thomas F. Burdick wrote:
> On 11 sep, 19:09, Kenny <·········@gmail.com> wrote:
> 
>> And my new stomping grounds:
>>
>>    comp.lang.javascript
> 
> Speaking of which, now that we're in A Brave New World of compiled JS,
> who's going to make a Lisp implementation that compiles everything to
> JS, to get that good native code love? I need one volunteer to do easy
> cross-calling, and another to make a world unto themselves. Bonus
> points if the former makes a bastard-child Scheme, and the other does
> ILISP-plus-continuations.

http://hop.inria.fr/usr/local/share/hop/weblets/home/articles/scheme2js/article.html

[From the paper's abstract:]
This paper presents Scm2Js a compiler that translates a variant of the 
Scheme programming language into JavaScript. On the one hand, some 
Scheme features are missing, amongst which the most important are the 
lack of support for continuations, the absence of exact numbers, and a 
partial treatment of tail recursions. On the other hand, some extensions 
are added for improving the connection between Scheme and JavaScript.
From: Kenny
Subject: Re: sorting the input
Date: 
Message-ID: <48c9874a$0$26957$607ed4bc@cv.net>
Bakul Shah wrote:
> Thomas F. Burdick wrote:
> 
>> On 11 sep, 19:09, Kenny <·········@gmail.com> wrote:
>>
>>> And my new stomping grounds:
>>>
>>>    comp.lang.javascript
>>
>>
>> Speaking of which, now that we're in A Brave New World of compiled JS,

Ah, just installed Chrome. Damn, that is fast. Do they have a ChromeBug?

kt
From: Kenny
Subject: Re: sorting the input
Date: 
Message-ID: <48c9a72f$0$7329$607ed4bc@cv.net>
Kenny wrote:
> Bakul Shah wrote:
> 
>> Thomas F. Burdick wrote:
>>
>>> On 11 sep, 19:09, Kenny <·········@gmail.com> wrote:
>>>
>>>> And my new stomping grounds:
>>>>
>>>>    comp.lang.javascript
>>>
>>>
>>>
>>> Speaking of which, now that we're in A Brave New World of compiled JS,
> 
> 
> Ah, just installed Chrome. Damn, that is fast. Do they have a ChromeBug?
> 


Of course you know what this means for TYA. <sigh> Two more years... 
unless of course Chrome plans to support MathML. Nobody supports MathML. 
Cool that they used WebKit.

Didn't there used to be a software company in Washington somewhere?

I wonder if Carla knows Javascript...

kzo
From: arnuld
Subject: Re: sorting the input
Date: 
Message-ID: <pan.2008.09.12.07.40.14.118899@invalid.address>
okay, half of the replies are totally OT :( 
From: Lars Rune Nøstdal
Subject: Re: sorting the input
Date: 
Message-ID: <1221327175.10480.134.camel@blackbox>
On Thu, 2008-09-11 at 19:16 -0400, Kenny wrote:
> Kenny wrote:
> > Bakul Shah wrote:
> > 
> >> Thomas F. Burdick wrote:
> >>
> >>> On 11 sep, 19:09, Kenny <·········@gmail.com> wrote:
> >>>
> >>>> And my new stomping grounds:
> >>>>
> >>>>    comp.lang.javascript
> >>>
> >>>
> >>>
> >>> Speaking of which, now that we're in A Brave New World of compiled JS,
> > 
> > 
> > Ah, just installed Chrome. Damn, that is fast. Do they have a ChromeBug?
> > 
> 
> 
> Of course you know what this means for TYA. <sigh> Two more years... 
> unless of course Chrome plans to support MathML. Nobody supports MathML. 
> Cool that they used WebKit.

Firefox-3.x handles it pretty well:
  http://www.mozilla.org/projects/mathml/demo/


..some direct links:
  http://www.mozilla.org/projects/mathml/start.xhtml
  http://www.mozilla.org/projects/mathml/demo/basics.xhtml
  http://www.mozilla.org/projects/mathml/demo/texvsmml.xhtml
  http://www.mozilla.org/projects/mathml/demo/extras.xhtml


..and the W3C test suite (MathML2 seems to work best):
  http://www.w3.org/Math/testsuite/


Things have changed since Firefox-1.x I guess.

(..I tested this on Linux with no extra plugins or fancy math-fonts
installed..)

-- 
Lars Rune Nøstdal   || AJAX/Comet GUI type stuff for Common Lisp
http://nostdal.org/ || http://groups.google.com/group/symbolicweb
From: Thomas F. Burdick
Subject: Re: sorting the input
Date: 
Message-ID: <2de50235-169c-45cb-9812-8c3b2352217c@f63g2000hsf.googlegroups.com>
On Sep 13, 7:32 pm, Lars Rune Nøstdal <···········@gmail.com> wrote:
> On Thu, 2008-09-11 at 19:16 -0400, Kenny wrote:
> > Kenny wrote:
> > > Bakul Shah wrote:
>
> > >> Thomas F. Burdick wrote:
>
> > >>> On 11 sep, 19:09, Kenny <·········@gmail.com> wrote:
>
> > >>>> And my new stomping grounds:
>
> > >>>>    comp.lang.javascript
>
> > >>> Speaking of which, now that we're in A Brave New World of compiled JS,
>
> > > Ah, just installed Chrome. Damn, that is fast. Do they have a ChromeBug?
>
> > Of course you know what this means for TYA. <sigh> Two more years...
> > unless of course Chrome plans to support MathML. Nobody supports MathML.
> > Cool that they used WebKit.
>
> Firefox-3.x handles it pretty well

Which doesn't negate the point that nobody supports MathML. "Nobody"
was obviously hyperbole, there's that weird W3C browser that probably
supported it for 10 years, but that doesn't mean you can use MathML
with any hope of anyone being able to view it. But eventually FF users
will upgrade, and if IE and/or WebKit pick it up, there's hope for the
future at least.

I have a hard time believing that no one has implemented something to
render mathml using the canvas tag, but google turns up nothing. Maybe
it's that anoying to implement.
From: Kenny
Subject: Re: sorting the input
Date: 
Message-ID: <48cc3a60$0$7334$607ed4bc@cv.net>
Thomas F. Burdick wrote:
> On Sep 13, 7:32 pm, Lars Rune N�stdal <···········@gmail.com> wrote:
> 
>>On Thu, 2008-09-11 at 19:16 -0400, Kenny wrote:
>>
>>>Kenny wrote:
>>>
>>>>Bakul Shah wrote:
>>
>>>>>Thomas F. Burdick wrote:
>>
>>>>>>On 11 sep, 19:09, Kenny <·········@gmail.com> wrote:
>>
>>>>>>>And my new stomping grounds:
>>
>>>>>>>   comp.lang.javascript
>>
>>>>>>Speaking of which, now that we're in A Brave New World of compiled JS,
>>
>>>>Ah, just installed Chrome. Damn, that is fast. Do they have a ChromeBug?
>>
>>>Of course you know what this means for TYA. <sigh> Two more years...
>>>unless of course Chrome plans to support MathML. Nobody supports MathML.
>>>Cool that they used WebKit.
>>
>>Firefox-3.x handles it pretty well
> 
> 
> Which doesn't negate the point that nobody supports MathML. "Nobody"
> was obviously hyperbole, there's that weird W3C browser that probably
> supported it for 10 years, but that doesn't mean you can use MathML
> with any hope of anyone being able to view it. But eventually FF users
> will upgrade, and if IE and/or WebKit pick it up, there's hope for the
> future at least.
> 
> I have a hard time believing that no one has implemented something to
> render mathml using the canvas tag,

The one supported by 90% of the browser audience?

<sigh> Does Himself have to do /everything/?

Hey, someone should wise up and do a <3d> tag.  Too easy? I'll send a 
note to Google, maybe I can land a contract. I'd really miss OpenGL.

kzo
From: Kenny
Subject: Re: sorting the input
Date: 
Message-ID: <48cc2142$0$7347$607ed4bc@cv.net>
Lars Rune Nøstdal wrote:
> On Thu, 2008-09-11 at 19:16 -0400, Kenny wrote:
> 
>>Kenny wrote:
>>
>>>Bakul Shah wrote:
>>>
>>>
>>>>Thomas F. Burdick wrote:
>>>>
>>>>
>>>>>On 11 sep, 19:09, Kenny <·········@gmail.com> wrote:
>>>>>
>>>>>
>>>>>>And my new stomping grounds:
>>>>>>
>>>>>>   comp.lang.javascript
>>>>>
>>>>>
>>>>>
>>>>>Speaking of which, now that we're in A Brave New World of compiled JS,
>>>
>>>
>>>Ah, just installed Chrome. Damn, that is fast. Do they have a ChromeBug?
>>>
>>
>>
>>Of course you know what this means for TYA. <sigh> Two more years... 
>>unless of course Chrome plans to support MathML. Nobody supports MathML. 
>>Cool that they used WebKit.
> 
> 
> Firefox-3.x handles it pretty well:
>   http://www.mozilla.org/projects/mathml/demo/
> 
> 
> ..some direct links:
>   http://www.mozilla.org/projects/mathml/start.xhtml
>   http://www.mozilla.org/projects/mathml/demo/basics.xhtml
>   http://www.mozilla.org/projects/mathml/demo/texvsmml.xhtml
>   http://www.mozilla.org/projects/mathml/demo/extras.xhtml
> 
> 
> ..and the W3C test suite (MathML2 seems to work best):
>   http://www.w3.org/Math/testsuite/
> 
> 
> Things have changed since Firefox-1.x I guess.
> 
> (..I tested this on Linux with no extra plugins or fancy math-fonts
> installed..)
> 

Oh, golly, sorry for all your trouble.

Yes, I knew FF supported MathML, by "nobody" I meant "so few (er, one) 
with so few signs of anybody else even caring that I have to pretend it 
is not there".

Well, I already have my own layout computation:

    http://www.theoryyalgebra.com/demo-23.html

Maybe that and the Dimensions package for JQuery are the way to go anyway.

kxo
From: William James
Subject: Re: sorting the input
Date: 
Message-ID: <4f8a4127-09c0-4c78-947b-102271139005@z66g2000hsc.googlegroups.com>
On Sep 11, 5:57 am, arnuld <·······@invalid.address> wrote:
> Hi all,
>
> I want to write a program in CL which will ask the use to input at stdin
> and then when user will press EOF (Ctrl-D in my BASH shell on Linux
> system) it will print the words in sorted order, each on a new line. I
> have done that in C++, you can see it here:
>
> http://groups.google.com/group/comp.lang.c++/browse_thread/thread/048...
>
> Now I don't have any clue on how to do it in C++ but I am interested in
> doing it in Lisp. I will welcome any hints, views and pointers of
> information. Right now I am searching the archives of CLL


ruby -e "puts ARGF.sort"
From: Raffael Cavallaro
Subject: Re: sorting the input
Date: 
Message-ID: <gabhpc$9qo$1@aioe.org>
On 2008-09-11 10:22:08 -0400, William James <·········@yahoo.com> said:

> ruby -e "puts ARGF.sort"

CL-USER 28 > ruby -e "puts ARGF.sort"

Error: Undefined operator RUBY in form (RUBY -E "puts ARGF.sort").
  1 (continue) Try invoking RUBY again.
  2 Return some values from the form (RUBY -E "puts ARGF.sort").
  3 Try invoking something other than RUBY with the same arguments.
  4 Set the symbol-function of RUBY to another function.
  5 Set the macro-function of RUBY to another function.
  6 (abort) Return to level 0.
  7 Return to top loop level 0.

Type :b for backtrace, :c <option number> to proceed,  or :? for other options

CL-USER 29 : 1 >

;; I think you want comp.lang.ruby
;; in lisp this is just:

CL-USER 30 > (sort (read) #'string<)
("zebra" "zebulon" "artichoke" "art" "boop")
("art" "artichoke" "boop" "zebra" "zebulon")
From: John Thingstad
Subject: Re: sorting the input
Date: 
Message-ID: <op.uhbfocceut4oq5@pandora.alfanett.no>
P� Thu, 11 Sep 2008 12:57:20 +0200, skrev arnuld <·······@invalid.address>:

> Hi all,
>
>
> I want to write a program in CL which will ask the use to input at stdin
> and then when user will press EOF (Ctrl-D in my BASH shell on Linux
> system) it will print the words in sorted order, each on a new line. I
> have done that in C++, you can see it here:
>
>
> http://groups.google.com/group/comp.lang.c++/browse_thread/thread/0488e58b666d0eb1#
>
>
> Now I don't have any clue on how to do it in C++ but I am interested in
> doing it in Lisp. I will welcome any hints, views and pointers of
> information. Right now I am searching the archives of CLL
>
>
>

Most Lisp input is done from The REPL (Read Eval Print Loop). That is the  
Lisp prompt.
So in that sense it doesn't work like in C+++.
Try writing one that reads a set of strings from the REPL instead.
You never have to leave Lisp to run the program.

Look up read-line, sort, write-string in the hyperspec.

--------------
John Thingstad
From: Espen Vestre
Subject: Re: sorting the input
Date: 
Message-ID: <m1zlme686p.fsf@gazonk.vestre.net>
"John Thingstad" <·······@online.no> writes:

> Most Lisp input is done from The REPL (Read Eval Print Loop). That is
> the  Lisp prompt.
> So in that sense it doesn't work like in C+++.
> Try writing one that reads a set of strings from the REPL instead.
> You never have to leave Lisp to run the program.
>
> Look up read-line, sort, write-string in the hyperspec.

Good advice (I assume you assume the OP is doing homework...).

To the OP: While John's advice (work from inside the lisp REPL) is
good advice if you want to learn lisp, just to avoid the usual
misconceptions, I'd like to add that it's entirely possible to either
build stand-alone executables from your lisp source, or to use them in
a shell-script manner.  For instance, clisp can be used out of the box
with "hash-bang" syntax, just put #!/usr/bin/clisp on the top of your
lisp code.
-- 
  (espen)
From: arnuld
Subject: Re: sorting the input
Date: 
Message-ID: <pan.2008.09.12.07.43.19.767494@invalid.address>
> On Thu, 11 Sep 2008 16:58:22 +0200, Espen Vestre wrote:

> To the OP: While John's advice (work from inside the lisp REPL) is
> good advice if you want to learn lisp, just to avoid the usual
> misconceptions, I'd like to add that it's entirely possible to either
> build stand-alone executables from your lisp source, or to use them in
> a shell-script manner.  For instance, clisp can be used out of the box
> with "hash-bang" syntax, just put #!/usr/bin/clisp on the top of your
> lisp code.


if it makes it a stand alone executable then you need to compile it, whihc
requires a compiler and I think running clisp at terminal gives me an
interpreter. 




-- 
www.lispmachine.wordpress.com
my email is @ the above blog.
Google Groups is Blocked. Reason: Excessive Spamming
From: Pascal J. Bourguignon
Subject: Re: sorting the input
Date: 
Message-ID: <878wtx4x6k.fsf@hubble.informatimago.com>
arnuld <·······@invalid.address> writes:

>> On Thu, 11 Sep 2008 16:58:22 +0200, Espen Vestre wrote:
>
>> To the OP: While John's advice (work from inside the lisp REPL) is
>> good advice if you want to learn lisp, just to avoid the usual
>> misconceptions, I'd like to add that it's entirely possible to either
>> build stand-alone executables from your lisp source, or to use them in
>> a shell-script manner.  For instance, clisp can be used out of the box
>> with "hash-bang" syntax, just put #!/usr/bin/clisp on the top of your
>> lisp code.
>
>
> if it makes it a stand alone executable then you need to compile it, whihc
> requires a compiler and I think running clisp at terminal gives me an
> interpreter. 

In any case you need a processor, so it won't be as stand alone as you
might think.

Once you accept a dependency on a processor, you can as well accept a
dependency on a OS virtual machine, and then you can as well accept a
dependency on a runtime library or other virtual machine.

/usr/lib/clisp/lisp.run is a library like /usr/lib/libc.so (only it
contains a 'main' while the deficient libc doesn't).


Then a script starting with #!/usr/bin/clisp is as stand alone as any
other executable in your system.

If you want to compile it, you can still do that.  If you start a
clisp .fas file with #!/usr/bin/clisp that makes it standalone.

Another way is to save an executable lisp image.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

ATTENTION: Despite any other listing of product contents found
herein, the consumer is advised that, in actuality, this product
consists of 99.9999999999% empty space.
From: arnuld
Subject: Re: sorting the input
Date: 
Message-ID: <pan.2008.09.12.07.39.19.514178@invalid.address>
> On Thu, 11 Sep 2008 14:01:14 +0200, John Thingstad wrote:



> Most Lisp input is done from The REPL (Read Eval Print Loop). That is
> the Lisp prompt.

That i know. I used to hang here in year 2005, when I had resources :) . I
can even recall some names Pascal J. Bourguignon and Pascal Constanza
(He even has a guide titled The Highly Opinionated Guide to Lisp ??)


> So in that sense it doesn't work like in C+++. Try writing one that
> reads a set of strings from the REPL instead. You never have to leave
> Lisp to run the program.
> 
> Look up read-line, sort, write-string in the hyperspec.

Thanks for these. I will read them up in Hyperspec.


-- 
www.lispmachine.wordpress.com
my email is @ the above blog.
Google Groups is Blocked. Reason: Excessive Spamming
From: arnuld
Subject: Re: sorting the input
Date: 
Message-ID: <pan.2008.09.12.07.50.09.837984@invalid.address>
> On Thu, 11 Sep 2008 14:01:14 +0200, John Thingstad wrote:

> ...SNIP....
> Look up read-line, sort, write-string in the hyperspec.


John, read-line and write-line work fine. I have to look a little deeper
into sort before I understand it. Here is some experimentation I have done:



[1]> (read-line)
like this
"like this" ;
NIL

it means, read-line return NIL by default while writing the input to
stdout as a side effect. It feels little like (format t "input")



[2]> (write-string (read-line))
like this
like this
"like this"
[3]> (sort (write-string (read-line)))
like this and baby sumit arnuld
like this and baby sumit arnuld
*** - EVAL: too few arguments given to SORT: (SORT (WRITE-STRING (READ-LINE)))
The following restarts are available:
ABORT          :R1      ABORT
Break 1 [4]> (sort (write-string (read-line)) >)
like this babay
like this babay
*** - EVAL: variable > has no value
The following restarts are available:
USE-VALUE      :R1      You may input a value to be used instead of >.
STORE-VALUE    :R2      You may input a new value for >.
ABORT          :R3      ABORT
ABORT          :R4



-- 
www.lispmachine.wordpress.com
my email is @ the above blog.
Google Groups is Blocked. Reason: Excessive Spamming
From: John Thingstad
Subject: Re: sorting the input
Date: 
Message-ID: <op.uhczkqpfut4oq5@pandora.alfanett.no>
P� Fri, 12 Sep 2008 09:50:11 +0200, skrev arnuld <·······@invalid.address>:

>> On Thu, 11 Sep 2008 14:01:14 +0200, John Thingstad wrote:
>
>> ...SNIP....
>> Look up read-line, sort, write-string in the hyperspec.
>
>
> John, read-line and write-line work fine. I have to look a little deeper
> into sort before I understand it. Here is some experimentation I have  
> done:
>
>
>
> [1]> (read-line)
> like this
> "like this" ;
> NIL
>
> it means, read-line return NIL by default while writing the input to
> stdout as a side effect. It feels little like (format t "input")
>
>
>
> [2]> (write-string (read-line))
> like this
> like this
> "like this"
> [3]> (sort (write-string (read-line)))
> like this and baby sumit arnuld
> like this and baby sumit arnuld
> *** - EVAL: too few arguments given to SORT: (SORT (WRITE-STRING  
> (READ-LINE)))
> The following restarts are available:
> ABORT          :R1      ABORT
> Break 1 [4]> (sort (write-string (read-line)) >)
> like this babay
> like this babay
> *** - EVAL: variable > has no value
> The following restarts are available:
> USE-VALUE      :R1      You may input a value to be used instead of >.
> STORE-VALUE    :R2      You may input a new value for >.
> ABORT          :R3      ABORT
> ABORT          :R4
>
>
>

Ok let's see if you can manage to piece it together after reading this.

CL-USER 1 > (progn (princ 'string>) (read-line) (values))
STRING>hello

CL-USER 2 > (sort '("Charly" "bravo" "oscar" "alpha") #'string-lessp)
("alpha" "bravo" "Charly" "oscar")

CL-USER 3 > (let ((line "Hello World!")) (write-line line) (values))
Hello World!



--------------
John Thingstad
From: John Thingstad
Subject: Re: sorting the input
Date: 
Message-ID: <op.uhcz8bf5ut4oq5@pandora.alfanett.no>
P� Fri, 12 Sep 2008 09:50:11 +0200, skrev arnuld <·······@invalid.address>:

>> On Thu, 11 Sep 2008 14:01:14 +0200, John Thingstad wrote:
>
>> ...SNIP....
>> Look up read-line, sort, write-string in the hyperspec.
>
>
> John, read-line and write-line work fine. I have to look a little deeper
> into sort before I understand it. Here is some experimentation I have  
> done:
>
>
>

You could also pehaps look at this  
http://home.online.no/~jpthing/games/roulette.html


-- 
--------------
John Thingstad
From: arnuld
Subject: Re: sorting the input
Date: 
Message-ID: <pan.2008.09.15.05.42.05.500603@invalid.address>
> On Fri, 12 Sep 2008 10:22:49 +0200, John Thingstad wrote:

> You could also pehaps look at this  
> http://home.online.no/~jpthing/games/roulette.html


yes, I did and came up with this pseudo code:


;;; This program will ask the user for input and will then print the words
;;; in alphabetically sorted format

(defun main()
    (format t "This program will sort the words you will enter")
;;  (save input from read-line here into some data structure)
;;  (sort the input)
;;  (print the input))


now if I run this program in interpreter I see ;sort; treats them as
characters rather than words. If I want to take them as a words I have to
take every word of user as a list of strings like '("this" "is" "a" "list"
"of" "strings") but then the problem is where to save that list and ho to
ask user for input and then interpret  them as words. In C++ i simply use 

  std::cin >> str  where str is of std::string type




-- 
www.lispmachine.wordpress.com
my email is @ the above blog.
Google Groups is Blocked. Reason: Excessive Spamming
From: arnuld
Subject: Re: sorting the input
Date: 
Message-ID: <pan.2008.09.15.05.53.18.673441@invalid.address>
> On Mon, 15 Sep 2008 10:43:57 +0500, arnuld wrote:

> now if I run this program in interpreter I see ;sort; treats them as
> characters rather than words. If I want to take them as a words I have to
> take every word of user as a list of strings like '("this" "is" "a" "list"
> "of" "strings") but then the problem is where to save that list and ho to
> ask user for input and then interpret  them as words. In C++ i simply use 
> 
>   std::cin >> str  where str is of std::string type


I tested this:

[3]> (list (read-line) (read-line))
like this
and this
("like this" "and this")


[10]> (sort (list (read-line) (read-line) (read-line)) #'string-lessp)
like
baby
is
("baby" "is" "like")
[11]> 

so ;read-line; treats everything as a string, which is a word in my case. 

So I can run an infinite while loop which will break only when user will
enter EOF (Ctrl-D in Linux)  and each time user will enter a word it will
be pushed onto an inifinetly long list of strings. Good idea ?

but still I need a way to have an infinitely long list of strings. Will
it be efficient in terms of CPU usage. Memory is cheap now a days, so i
won't have to care much about it.



-- 
www.lispmachine.wordpress.com
my email is @ the above blog.
Google Groups is Blocked. Reason: Excessive Spamming
From: Pascal J. Bourguignon
Subject: Re: sorting the input
Date: 
Message-ID: <87ljxu6j2e.fsf@hubble.informatimago.com>
arnuld <·······@invalid.address> writes:

>> On Mon, 15 Sep 2008 10:43:57 +0500, arnuld wrote:
>
>> now if I run this program in interpreter I see ;sort; treats them as
>> characters rather than words. If I want to take them as a words I have to
>> take every word of user as a list of strings like '("this" "is" "a" "list"
>> "of" "strings") but then the problem is where to save that list and ho to
>> ask user for input and then interpret  them as words. In C++ i simply use 
>> 
>>   std::cin >> str  where str is of std::string type
>
>
> I tested this:
>
> [3]> (list (read-line) (read-line))
> like this
> and this
> ("like this" "and this")
>
>
> [10]> (sort (list (read-line) (read-line) (read-line)) #'string-lessp)
> like
> baby
> is
> ("baby" "is" "like")
> [11]> 
>
> so ;read-line; treats everything as a string, which is a word in my case. 
>
> So I can run an infinite while loop which will break only when user will
> enter EOF (Ctrl-D in Linux)  and each time user will enter a word it will
> be pushed onto an inifinetly long list of strings. Good idea ?

No. This universe will end in ~15e9 years.  You won't have the time
needed to process an infinite list of words. 

Try with a finite one!


> but still I need a way to have an infinitely long list of strings. Will
> it be efficient in terms of CPU usage. Memory is cheap now a days, so i
> won't have to care much about it.

Well, you can still consider you very happy to have an infinite amount
of memory.  And since it's cheap, could you please send half of it
this way?  Thanks.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Until real software engineering is developed, the next best practice
is to develop with a dynamic system that has extreme late binding in
all aspects. The first system to really do this in an important way
is Lisp. -- Alan Kay
From: arnuld
Subject: Re: sorting the input
Date: 
Message-ID: <pan.2008.09.15.07.05.52.764801@invalid.address>
> On Mon, 15 Sep 2008 08:04:41 +0200, Pascal J. Bourguignon wrote:


> No. This universe will end in ~15e9 years.  You won't have the time
> needed to process an infinite list of words. 
> 
> Try with a finite one!


How about this:

;;; This program will ask the user for input and will then print the words
;;; in alphabetically sorted format


(defun sorting-input()
  (format t "This program will sort the words you will enter: ")
  (defparameter input-list NIL)
  (get-input input-list)
  (sort input-list #'string-lessp)
  (pprint input-list))


(defun get-input (list-of-strings)
  (defparameter input-string NIL)
  (loop while (setq input-string (read-line)) )
    (pushnew input-string list-of-strings))



In interpreter It loads and compiles fine but when I run it I get this
error:

[6]> (load "sort-input.lisp")
;; Loading file sort-input.lisp ...
;; Loaded file sort-input.lisp
T
[7]> (compile-file "sort-input.lisp")
;; Compiling file /home/arnuld/programs/ztest/sort-input.lisp ...
;; Wrote file /home/arnuld/programs/ztest/sort-input.fas
0 errors, 0 warnings
#P"/home/arnuld/programs/ztest/sort-input.fas" ;
NIL ;
NIL
[8]> (sorting-input)
This program will sort the words you will enter: like baby is

*** - READ: input stream #<IO TERMINAL-STREAM> has reached its end
The following restarts are available:
ABORT          :R1      ABORT
Break 1 [9]> 



 
> Well, you can still consider you very happy to have an infinite amount
> of memory.  And since it's cheap, could you please send half of it this
> way?  Thanks.


I meant, my programs need to to efficint in terms of CPU usage. I think we
have to make one choice when it comes to efficiency:  Memory or CPU




-- 
www.lispmachine.wordpress.com
my email is @ the above blog.
Google Groups is Blocked. Reason: Excessive Spamming
From: Pascal J. Bourguignon
Subject: Re: sorting the input
Date: 
Message-ID: <7c4p4hg6kb.fsf@pbourguignon.anevia.com>
arnuld <·······@invalid.address> writes:

>> On Mon, 15 Sep 2008 08:04:41 +0200, Pascal J. Bourguignon wrote:
>
>
>> No. This universe will end in ~15e9 years.  You won't have the time
>> needed to process an infinite list of words. 
>> 
>> Try with a finite one!
>
>
> How about this:
>
> ;;; This program will ask the user for input and will then print the words
> ;;; in alphabetically sorted format
>
>
> (defun sorting-input()
>   (format t "This program will sort the words you will enter: ")
>   (defparameter input-list NIL)
>   (get-input input-list)
>   (sort input-list #'string-lessp)
>   (pprint input-list))

DEFPARAMETER  _defines_  a  _special_ _global_ variable, and also _assigns_ it a value.
There are certainly THREE things it does you didn't want in here.

Use LET to bind local, lexical variable.


Lisp pass it's arguments by value.  If input-list was a lexical
variable, there would be absolutely no way for GET-INPUT to modify it.
As a global, special variable, GET-INPUT could modify INPUT-LIST, but
receiving its value as parameter is totally useless.

By the same token, while SORT is destructive, nothing specifies it
should modify the cons cell referenced by the variable INPUT-LIST so
that it appears to have the list sorted.


S/CL-USER[1]> (let ((list (list 4 3 2 1)))
                (sort list (function <))
                list)

(4)


In this case, you don't even need a variable:

(defun sorting-input (&optional (io-stream *query-io*))
    (format io-stream "This program will sort the words you will enter: ")
    (pprint (sort (get-input io-stream) (function string-lessp))))



> (defun get-input (list-of-strings)
>   (defparameter input-string NIL)
>   (loop while (setq input-string (read-line)) )
>     (pushnew input-string list-of-strings))

(defun get-input (io-stream)
  (loop :for line = (read-line io-stream nil nil) :while line :collect line))


> In interpreter It loads and compiles fine but when I run it I get this
> error:
>
> [6]> (load "sort-input.lisp")
> ;; Loading file sort-input.lisp ...
> ;; Loaded file sort-input.lisp
> T
> [7]> (compile-file "sort-input.lisp")
> ;; Compiling file /home/arnuld/programs/ztest/sort-input.lisp ...
> ;; Wrote file /home/arnuld/programs/ztest/sort-input.fas
> 0 errors, 0 warnings
> #P"/home/arnuld/programs/ztest/sort-input.fas" ;
> NIL ;
> NIL
> [8]> (sorting-input)
> This program will sort the words you will enter: like baby is
>
> *** - READ: input stream #<IO TERMINAL-STREAM> has reached its end
> The following restarts are available:
> ABORT          :R1      ABORT
> Break 1 [9]> 

You are expecting an end-of-file on the terminal input stream, so when
your function exits, there remains nothing more to read for the REPL.
Since you're running in a terminal, clisp can still display this error
message (and possibly ignore the end-of-file on the terminal, and go
on).


But when you run thru a pipe, it just can't do anything, once the pipe is closed:

C/USER[26]> (sorting-input)
This program will sort the words you will enter: Hello world!
How do you do?
Alice in Wonderland
What else?
^D
("Alice in Wonderland" "Hello world!" "How do you do?" "What else?")


Process inferior-lisp finished


You should read the data from a file:

C/USER[5]> (with-open-file (input "/tmp/data") (sorting-input (make-two-way-stream input *standard-output*))) 
This program will sort the words you will enter: 
("Alice in Wonderland" "Hello world!" "How do you do?" "What else?")

C/USER[6]> 

But then you see that it's not practical to mix interactive I/O with
functional parts...  You should modularize, and separate the user
interaction from the working parts of your program.



>> Well, you can still consider you very happy to have an infinite amount
>> of memory.  And since it's cheap, could you please send half of it this
>> way?  Thanks.
>
>
> I meant, my programs need to to efficint in terms of CPU usage. I think we
> have to make one choice when it comes to efficiency:  Memory or CPU

I mean, perhaps you should first learn to program, and then later
bother about efficiency.  There's no point of trying to optimize
something  you don't understand.

-- 
__Pascal Bourguignon__
From: arnuld
Subject: Re: sorting the input
Date: 
Message-ID: <pan.2008.09.15.10.14.01.613144@invalid.address>
> On Mon, 15 Sep 2008 10:24:36 +0200, Pascal J. Bourguignon wrote:


> DEFPARAMETER  _defines_  a  _special_ _global_ variable, and also
> _assigns_ it a value. There are certainly THREE things it does you
> didn't want in here.
> 
> Use LET to bind local, lexical variable.


okay

 
> Lisp pass it's arguments by value. 

Just like C (except of arrays)

> ...SNIP...

> S/CL-USER[1]> (let ((list (list 4 3 2 1)))
>                 (sort list (function <))
>                 list)
> 
> In this case, you don't even need a variable:
> 
> (defun sorting-input (&optional (io-stream *query-io*))
>     (format io-stream "This program will sort the words you will enter:
>     ") (pprint (sort (get-input io-stream) (function string-lessp))))
> 


Unable to understand what is going on
 

> (defun get-input (io-stream)
>   (loop :for line = (read-line io-stream nil nil) :while line :collect
>   line))
> 

that seems interesting
 



> I mean, perhaps you should first learn to program, and then later bother
> about efficiency.  There's no point of trying to optimize something  you
> don't understand.

Well, that show you do programming in C. Mixing interactive I/O with
functions.




-- 
www.lispmachine.wordpress.com
my email is @ the above blog.
Google Groups is Blocked. Reason: Excessive Spamming
From: Pascal J. Bourguignon
Subject: Re: sorting the input
Date: 
Message-ID: <7cvdwxeju2.fsf@pbourguignon.anevia.com>
arnuld <·······@invalid.address> writes:
>> (defun sorting-input (&optional (io-stream *query-io*))
>>     (format io-stream "This program will sort the words you will enter:
>>     ") (pprint (sort (get-input io-stream) (function string-lessp))))
>
> Unable to understand what is going on

Didn't  you learn about functions in maths?

When you have four sets, R, S, U and V,
and three functions, f from R to S, 
g from S to U, and h from U to V,

         f           g          h
   R --------> S --------> U ---------> V

you can compute f(r) for each element r in R,
then you can compute g(f(r))
and then you can compute h(g(f(r))).


Well here it is exactly the same:        (h (g (f r)))
only our g takes its argument from SxW:  (h (g (f r) w))

     (pprint (sort (get-input r) w))
     (pprint (sort (get-input io-stream) #'string-lessp))


Now, if you really need to, you can do as in maths, give names to each
intermediate results.

Let s be f(r)
let u be g(s,w)
let v be h(u)
the result is v.

(let* ((input   (get-input io-stream))
       (sorted  (sort input (function string-lessp)))
       (printed (pprint sorted)))
   printed)



>> I mean, perhaps you should first learn to program, and then later bother
>> about efficiency.  There's no point of trying to optimize something  you
>> don't understand.
>
> Well, that show you do programming in C. Mixing interactive I/O with
> functions.

I maintain, you should separate user interaction and I/O in general,
from the functional part of the program.


(defun read-interactively-a-list-of-strings (main-prompt item-prompt end-of-list io-stream)
  (format io-stream "~A" main-prompt)
  (loop
     :for item = (progn (format io-stream "~&~A" item-prompt)
                        (finish-output io-stream)
                        (read-line io-stream nil nil))
     :while (string/= item end-of-list)
     :collect item))


(defun sort-strings (list-of-string)
   (sort list-of-string (function string<)))


(defun interactive-sort-user-input (io-stream)
   (let ((input (read-interactively-a-list-of-strings 
                    "Please enter a list of strings, one per line, 
and terminate with a single dot on a line."
                    "Next line: " "." io-stream)))
    
      (pprint (sort-strings input)))
   (values))


C/USER[9]> (INTERACTIVE-SORT-USER-INPUT *query-io*)
Please enter a list of strings, one per line, 
and terminate with a single dot on a line.
Next line: Red
Next line: Green
Next line: Blue
Next line: Brick Yellow
Next line: .

("Blue" "Brick Yellow" "Green" "Red")

C/USER[10]> 


Usually, the functional parts (sort-strings here) will be more complex
than the user interface part, and separating it thusly will make it
more reusable.  Also, the user interface part changes often, and may
often also be generated automatically (from programs such as Interface
Builder).

-- 
__Pascal Bourguignon__
From: William James
Subject: Re: sorting the input
Date: 
Message-ID: <46a99647-15e0-4817-ac46-5ab94eee3d84@k13g2000hse.googlegroups.com>
On Sep 15, 6:20 am, ····@informatimago.com (Pascal J. Bourguignon)
wrote:

>
> (defun read-interactively-a-list-of-strings (main-prompt item-prompt end-of-list io-stream)
>   (format io-stream "~A" main-prompt)
>   (loop
>      :for item = (progn (format io-stream "~&~A" item-prompt)
>                         (finish-output io-stream)
>                         (read-line io-stream nil nil))
>      :while (string/= item end-of-list)
>      :collect item))

That's really prolix.  COMMON-LISP seems to be a language of the
same vintage as COBOL.

Ruby:

def read_strings_interactively m_prompt, i_prompt, end_of_list
  puts m_prompt
  s, list = "", []
  list << s until print(i_prompt) or end_of_list == s=gets.strip
  list
end
From: John Thingstad
Subject: Re: sorting the input
Date: 
Message-ID: <op.uhi73dsvut4oq5@pandora.alfanett.no>
P� Mon, 15 Sep 2008 18:15:29 +0200, skrev William James  
<·········@yahoo.com>:

>
> Ruby:
>
> def read_strings_interactively m_prompt, i_prompt, end_of_list
>   puts m_prompt
>   s, list = "", []
>   list << s until print(i_prompt) or end_of_list == s=gets.strip
>   list
> end
>

Why does the language read like Arabic from right to left?
In English we read from left to right.

--------------
John Thingstad
From: Joost Diepenmaat
Subject: Re: sorting the input
Date: 
Message-ID: <87abe9cp8o.fsf@zeekat.nl>
"John Thingstad" <·······@online.no> writes:

> På Mon, 15 Sep 2008 18:15:29 +0200, skrev William James
> <·········@yahoo.com>:
>
>>
>> Ruby:
>>
>> def read_strings_interactively m_prompt, i_prompt, end_of_list
>>   puts m_prompt
>>   s, list = "", []
>>   list << s until print(i_prompt) or end_of_list == s=gets.strip
>>   list
>> end
>>
>
> Why does the language read like Arabic from right to left?
> In English we read from left to right.

read this sentence until you see that your statement is wrong.

I think idea of using if, or etc as "statement modifiers" comes from
Perl, which may be the ugly, but when used well allows for some
remarkably readable constructs (readable as in: read it out loud).

-- 
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
From: Joost Diepenmaat
Subject: Re: sorting the input
Date: 
Message-ID: <8763oxcp5m.fsf@zeekat.nl>
Joost Diepenmaat <·····@zeekat.nl> writes:

> I think idea of using if, or etc as "statement modifiers" ...

err, that should be "if, while etc". or isn't a statement modifier.

-- 
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
From: Lars Rune Nøstdal
Subject: Re: sorting the input
Date: 
Message-ID: <1221523879.10480.295.camel@blackbox>
On Mon, 2008-09-15 at 09:15 -0700, William James wrote:
> On Sep 15, 6:20 am, ····@informatimago.com (Pascal J. Bourguignon)
> wrote:
> 
> >
> > (defun read-interactively-a-list-of-strings (main-prompt item-prompt end-of-list io-stream)
> >   (format io-stream "~A" main-prompt)
> >   (loop
> >      :for item = (progn (format io-stream "~&~A" item-prompt)
> >                         (finish-output io-stream)
> >                         (read-line io-stream nil nil))
> >      :while (string/= item end-of-list)
> >      :collect item))
> 
> That's really prolix.  COMMON-LISP seems to be a language of the
> same vintage as COBOL.
> 
> Ruby:
> 
> def read_strings_interactively m_prompt, i_prompt, end_of_list
>   puts m_prompt
>   s, list = "", []
>   list << s until print(i_prompt) or end_of_list == s=gets.strip
>   list
> end
> 

It's hopeless. People really are useless shit doomed to repeat the _same
stupid crap_ over and over again. I should switch to MS .NET and C# and
start writing applications.

Die.

-- 
Lars Rune Nøstdal   || AJAX/Comet GUI type stuff for Common Lisp
http://nostdal.org/ || http://groups.google.com/group/symbolicweb
From: ···············@gmail.com
Subject: Re: sorting the input
Date: 
Message-ID: <bf90d5cf-4951-4910-beed-04dea257ff3d@25g2000hsx.googlegroups.com>
On Sep 16, 2:11 am, Lars Rune Nøstdal <···········@gmail.com> wrote:
> It's hopeless. People really are useless shit doomed to repeat the _same
> stupid crap_ over and over again. I should switch to MS .NET and C# and
> start writing applications.

Please don't
Finish symbolicweb.
thanks

--
olivier buechel || lisper
From: arnuld
Subject: Re: sorting the input
Date: 
Message-ID: <pan.2008.09.15.06.46.55.582700@invalid.address>
> On Mon, 15 Sep 2008 10:53:19 +0500, arnuld wrote:


> ..SNIP...

> [10]> (sort (list (read-line) (read-line) (read-line)) #'string-lessp)
> like
> baby
> is
> ("baby" "is" "like")
> [11]> 

> ....SNIP....


I tried hard and came with this code:

;;; This program will ask the user for input and will then print the words
;;; in alphabetically sorted format

(defun main()
  (format t "This program will sort the words you will enter")
  (defparameter input-list NIL)
  (get-input input-list)
  (sort input-list #'string-lessp)
  (progn input-list))

(defun get-input (list-of-strings)
  (defparameter input-string NIL)
  (while (setq input-string (read-line)) )
    (pushnew input-string list-of-strings))



I did:

  (load          "filename.lisp") 
  (compile-file  "filename.lisp")


and it compiled without any failure. I don't know how to run the program.
It has created filename.fas and filename.lib files in the current
directory automatically.




-- 
www.lispmachine.wordpress.com
my email is @ the above blog.
Google Groups is Blocked. Reason: Excessive Spamming
From: William James
Subject: Re: sorting the input
Date: 
Message-ID: <6c284176-587f-4586-8aed-0509fbebf17f@t54g2000hsg.googlegroups.com>
On Sep 15, 1:46 am, arnuld <·······@invalid.address> wrote:
> > On Mon, 15 Sep 2008 10:53:19 +0500, arnuld wrote:
> > ..SNIP...
> > [10]> (sort (list (read-line) (read-line) (read-line)) #'string-lessp)
> > like
> > baby
> > is
> > ("baby" "is" "like")
> > [11]>
> > ....SNIP....
>
> I tried hard and came with this code:
>
> ;;; This program will ask the user for input and will then print the words
> ;;; in alphabetically sorted format
>
> (defun main()
>   (format t "This program will sort the words you will enter")
>   (defparameter input-list NIL)
>   (get-input input-list)
>   (sort input-list #'string-lessp)
>   (progn input-list))
>
> (defun get-input (list-of-strings)
>   (defparameter input-string NIL)
>   (while (setq input-string (read-line)) )
>     (pushnew input-string list-of-strings))

Ruby:

puts gets(nil).split.sort
From: Lars Rune Nøstdal
Subject: Re: sorting the input
Date: 
Message-ID: <1221469382.10480.264.camel@blackbox>
On Mon, 2008-09-15 at 00:37 -0700, William James wrote:
> On Sep 15, 1:46 am, arnuld <·······@invalid.address> wrote:
> > > On Mon, 15 Sep 2008 10:53:19 +0500, arnuld wrote:
> > > ..SNIP...
> > > [10]> (sort (list (read-line) (read-line) (read-line)) #'string-lessp)
> > > like
> > > baby
> > > is
> > > ("baby" "is" "like")
> > > [11]>
> > > ....SNIP....
> >
> > I tried hard and came with this code:
> >
> > ;;; This program will ask the user for input and will then print the words
> > ;;; in alphabetically sorted format
> >
> > (defun main()
> >   (format t "This program will sort the words you will enter")
> >   (defparameter input-list NIL)
> >   (get-input input-list)
> >   (sort input-list #'string-lessp)
> >   (progn input-list))
> >
> > (defun get-input (list-of-strings)
> >   (defparameter input-string NIL)
> >   (while (setq input-string (read-line)) )
> >     (pushnew input-string list-of-strings))
> 
> Ruby:
> 
> puts gets(nil).split.sort

Lisp:
(puts (sort (split (gets nil))))

..much better.

-- 
Lars Rune Nøstdal   || AJAX/Comet GUI type stuff for Common Lisp
http://nostdal.org/ || http://groups.google.com/group/symbolicweb
From: ······@corporate-world.lisp.de
Subject: Re: sorting the input
Date: 
Message-ID: <e965b39b-3bcb-4878-bf6d-d246e1f0b61a@m73g2000hsh.googlegroups.com>
On 15 Sep., 08:46, arnuld <·······@invalid.address> wrote:
> > On Mon, 15 Sep 2008 10:53:19 +0500, arnuld wrote:
> > ..SNIP...
> > [10]> (sort (list (read-line) (read-line) (read-line)) #'string-lessp)
> > like
> > baby
> > is
> > ("baby" "is" "like")
> > [11]>
> > ....SNIP....
>
> I tried hard and came with this code:
>
> ;;; This program will ask the user for input and will then print the words
> ;;; in alphabetically sorted format
>

Your code needs to be improved.

> (defun main()
>   (format t "This program will sort the words you will enter")
>   (defparameter input-list NIL)

DEFPARAMETER does not create a local variable, but a global.
Using global variables like you do is bad bad bad style.

>   (get-input input-list)

Calling GET-INPUT with INPUT-LIST makes no sense.

>   (sort input-list #'string-lessp)
>   (progn input-list))

PROGN does nothing useful here and can be removed.

(defun main ()
  (format t "This program will sort the words you will enter:~%")
  (sort (get-input) #'string-lessp))


>
> (defun get-input (list-of-strings)

You don't need that parameter LIST-OF-STRINGS.

>   (defparameter input-string NIL)

Again, DEFPARAMETER is not used like that.

>   (while (setq input-string (read-line)) )
>     (pushnew input-string list-of-strings))


(defun get-input ()
  (LOOP FOR input-string = (READ-LINE)
        WHILE (and input-string (plusp (length input-string)))
        COLLECT input-string))


CL-USER 16 > (main)
This program will sort the words you will enter:
obama
palin
mccain
biden

("biden" "mccain" "obama" "palin")


>
> I did:
>
>   (load          "filename.lisp")
>   (compile-file  "filename.lisp")
>
> and it compiled without any failure. I don't know how to run the program.
> It has created filename.fas and filename.lib files in the current
> directory automatically.
>
> --www.lispmachine.wordpress.com
> my email is @ the above blog.
> Google Groups is Blocked. Reason: Excessive Spamming
From: John Thingstad
Subject: Re: sorting the input
Date: 
Message-ID: <op.uhii4udbut4oq5@pandora.alfanett.no>
P� Mon, 15 Sep 2008 08:46:56 +0200, skrev arnuld <·······@invalid.address>:

>> On Mon, 15 Sep 2008 10:53:19 +0500, arnuld wrote:
>
>
>> ..SNIP...
>
>> [10]> (sort (list (read-line) (read-line) (read-line)) #'string-lessp)
>> like
>> baby
>> is
>> ("baby" "is" "like")
>> [11]>
>
>> ....SNIP....
>
>
> I tried hard and came with this code:
>
> ;;; This program will ask the user for input and will then print the  
> words
> ;;; in alphabetically sorted format
>
> (defun main()
>   (format t "This program will sort the words you will enter")
>   (defparameter input-list NIL)
>   (get-input input-list)
>   (sort input-list #'string-lessp)
>   (progn input-list))
>
> (defun get-input (list-of-strings)
>   (defparameter input-string NIL)
>   (while (setq input-string (read-line)) )
>     (pushnew input-string list-of-strings))
>
>
>
> I did:
>
>   (load          "filename.lisp")
>   (compile-file  "filename.lisp")
>
>
> and it compiled without any failure. I don't know how to run the program.
> It has created filename.fas and filename.lib files in the current
> directory automatically.
>

You "run" it the same way you any other function withing the REPL. How did  
you "run" sort? And why are you calling it main. This isn't C.

Not that this code would work.

1. You format hasn't added any line breaks. add use "text~%".
2. defparameter defines a global parameter every time the function is run.  
It doesn't make a whole lot of sense. Lexical (local) variables are made  
with let.
3. Why do you insist on throwing away the returned values of your  
functions? Obviously they will have no effect. Simularly functions have to  
return a value.
4. Where did 'while' come from? RTFM!

(defun read-words ()
   (let ((words nil))
     (format t "~&Enter words a line at a time and quit by typing  
'quit'.~%")
     (loop
        (let ((word (read-line)))
           (when (string= word "quit") (return)) ; exits 'loop', not  
function
           (pushnew word words)))
     words))


--------------
John Thingstad
From: William James
Subject: Re: sorting the input
Date: 
Message-ID: <6d0df5d4-0e29-49db-ac40-6154e027bca0@k30g2000hse.googlegroups.com>
On Sep 15, 2:59 am, "John Thingstad" <·······@online.no> wrote:
> På Mon, 15 Sep 2008 08:46:56 +0200, skrev arnuld <·······@invalid.address>:
>
> >> On Mon, 15 Sep 2008 10:53:19 +0500, arnuld wrote:
>
> >> ..SNIP...
>
> >> [10]> (sort (list (read-line) (read-line) (read-line)) #'string-lessp)
> >> like
> >> baby
> >> is
> >> ("baby" "is" "like")
> >> [11]>
>
> >> ....SNIP....
>
> > I tried hard and came with this code:
>
> > ;;; This program will ask the user for input and will then print the
> > words
> > ;;; in alphabetically sorted format
>
> > (defun main()
> >   (format t "This program will sort the words you will enter")
> >   (defparameter input-list NIL)
> >   (get-input input-list)
> >   (sort input-list #'string-lessp)
> >   (progn input-list))
>
> > (defun get-input (list-of-strings)
> >   (defparameter input-string NIL)
> >   (while (setq input-string (read-line)) )
> >     (pushnew input-string list-of-strings))
>
> > I did:
>
> >   (load          "filename.lisp")
> >   (compile-file  "filename.lisp")
>
> > and it compiled without any failure. I don't know how to run the program.
> > It has created filename.fas and filename.lib files in the current
> > directory automatically.
>
> You "run" it the same way you any other function withing the REPL. How did
> you "run" sort? And why are you calling it main. This isn't C.
>
> Not that this code would work.
>
> 1. You format hasn't added any line breaks. add use "text~%".
> 2. defparameter defines a global parameter every time the function is run.
> It doesn't make a whole lot of sense. Lexical (local) variables are made
> with let.
> 3. Why do you insist on throwing away the returned values of your
> functions? Obviously they will have no effect. Simularly functions have to
> return a value.
> 4. Where did 'while' come from? RTFM!
>
> (defun read-words ()
>    (let ((words nil))
>      (format t "~&Enter words a line at a time and quit by typing
> 'quit'.~%")
>      (loop
>         (let ((word (read-line)))
>            (when (string= word "quit") (return)) ; exits 'loop', not
> function
>            (pushnew word words)))
>      words))

Ruby:

def read_words
  word, words = nil, []
  puts "Enter words a line at a time & quit by typing 'quit'."
  words << word until "quit" == word = gets.strip
  words
end
From: Lars Rune Nøstdal
Subject: Re: sorting the input
Date: 
Message-ID: <1221469665.10480.270.camel@blackbox>
On Mon, 2008-09-15 at 01:36 -0700, William James wrote:
> On Sep 15, 2:59 am, "John Thingstad" <·······@online.no> wrote:
> > På Mon, 15 Sep 2008 08:46:56 +0200, skrev arnuld <·······@invalid.address>:
> >
> > >> On Mon, 15 Sep 2008 10:53:19 +0500, arnuld wrote:
> >
> > >> ..SNIP...
> >
> > >> [10]> (sort (list (read-line) (read-line) (read-line)) #'string-lessp)
> > >> like
> > >> baby
> > >> is
> > >> ("baby" "is" "like")
> > >> [11]>
> >
> > >> ....SNIP....
> >
> > > I tried hard and came with this code:
> >
> > > ;;; This program will ask the user for input and will then print the
> > > words
> > > ;;; in alphabetically sorted format
> >
> > > (defun main()
> > >   (format t "This program will sort the words you will enter")
> > >   (defparameter input-list NIL)
> > >   (get-input input-list)
> > >   (sort input-list #'string-lessp)
> > >   (progn input-list))
> >
> > > (defun get-input (list-of-strings)
> > >   (defparameter input-string NIL)
> > >   (while (setq input-string (read-line)) )
> > >     (pushnew input-string list-of-strings))
> >
> > > I did:
> >
> > >   (load          "filename.lisp")
> > >   (compile-file  "filename.lisp")
> >
> > > and it compiled without any failure. I don't know how to run the program.
> > > It has created filename.fas and filename.lib files in the current
> > > directory automatically.
> >
> > You "run" it the same way you any other function withing the REPL. How did
> > you "run" sort? And why are you calling it main. This isn't C.
> >
> > Not that this code would work.
> >
> > 1. You format hasn't added any line breaks. add use "text~%".
> > 2. defparameter defines a global parameter every time the function is run.
> > It doesn't make a whole lot of sense. Lexical (local) variables are made
> > with let.
> > 3. Why do you insist on throwing away the returned values of your
> > functions? Obviously they will have no effect. Simularly functions have to
> > return a value.
> > 4. Where did 'while' come from? RTFM!
> >
> > (defun read-words ()
> >    (let ((words nil))
> >      (format t "~&Enter words a line at a time and quit by typing
> > 'quit'.~%")
> >      (loop
> >         (let ((word (read-line)))
> >            (when (string= word "quit") (return)) ; exits 'loop', not
> > function
> >            (pushnew word words)))
> >      words))
> 
> Ruby:
> 
> def read_words
>   word, words = nil, []
>   puts "Enter words a line at a time & quit by typing 'quit'."
>   words << word until "quit" == word = gets.strip
>   words
> end


Lisp:
(defun read-words ()
  (puts "Enter words a line at a time & quit by typing 'quit'.")
  (loop :for word = (read-line) :until (string= word "quit") :collect word))

..much better.
   
-- 
Lars Rune Nøstdal   || AJAX/Comet GUI type stuff for Common Lisp
http://nostdal.org/ || http://groups.google.com/group/symbolicweb
From: William James
Subject: Re: sorting the input
Date: 
Message-ID: <bb791d28-bfc4-4ad5-a092-f0767e45936a@t54g2000hsg.googlegroups.com>
On Sep 15, 4:07 am, Lars Rune Nøstdal <···········@gmail.com> wrote:
> On Mon, 2008-09-15 at 01:36 -0700, William James wrote:
> > On Sep 15, 2:59 am, "John Thingstad" <·······@online.no> wrote:
> > > På Mon, 15 Sep 2008 08:46:56 +0200, skrev arnuld <·······@invalid.address>:
>
> > > >> On Mon, 15 Sep 2008 10:53:19 +0500, arnuld wrote:
>
> > > >> ..SNIP...
>
> > > >> [10]> (sort (list (read-line) (read-line) (read-line)) #'string-lessp)
> > > >> like
> > > >> baby
> > > >> is
> > > >> ("baby" "is" "like")
> > > >> [11]>
>
> > > >> ....SNIP....
>
> > > > I tried hard and came with this code:
>
> > > > ;;; This program will ask the user for input and will then print the
> > > > words
> > > > ;;; in alphabetically sorted format
>
> > > > (defun main()
> > > >   (format t "This program will sort the words you will enter")
> > > >   (defparameter input-list NIL)
> > > >   (get-input input-list)
> > > >   (sort input-list #'string-lessp)
> > > >   (progn input-list))
>
> > > > (defun get-input (list-of-strings)
> > > >   (defparameter input-string NIL)
> > > >   (while (setq input-string (read-line)) )
> > > >     (pushnew input-string list-of-strings))
>
> > > > I did:
>
> > > >   (load          "filename.lisp")
> > > >   (compile-file  "filename.lisp")
>
> > > > and it compiled without any failure. I don't know how to run the program.
> > > > It has created filename.fas and filename.lib files in the current
> > > > directory automatically.
>
> > > You "run" it the same way you any other function withing the REPL. How did
> > > you "run" sort? And why are you calling it main. This isn't C.
>
> > > Not that this code would work.
>
> > > 1. You format hasn't added any line breaks. add use "text~%".
> > > 2. defparameter defines a global parameter every time the function is run.
> > > It doesn't make a whole lot of sense. Lexical (local) variables are made
> > > with let.
> > > 3. Why do you insist on throwing away the returned values of your
> > > functions? Obviously they will have no effect. Simularly functions have to
> > > return a value.
> > > 4. Where did 'while' come from? RTFM!
>
> > > (defun read-words ()
> > >    (let ((words nil))
> > >      (format t "~&Enter words a line at a time and quit by typing
> > > 'quit'.~%")
> > >      (loop
> > >         (let ((word (read-line)))
> > >            (when (string= word "quit") (return)) ; exits 'loop', not
> > > function
> > >            (pushnew word words)))
> > >      words))
>
> > Ruby:
>
> > def read_words
> >   word, words = nil, []
> >   puts "Enter words a line at a time & quit by typing 'quit'."
> >   words << word until "quit" == word = gets.strip
> >   words
> > end
>
> Lisp:
> (defun read-words ()
>   (puts "Enter words a line at a time & quit by typing 'quit'.")
>   (loop :for word = (read-line) :until (string= word "quit") :collect word))
>
> ..much better.

Good.

Ruby:
def read_words
  puts "Enter words a line at a time & quit by typing 'quit'."
  accumulate_till{ [ w = gets.strip, "quit" == w ] }
end

with this proviso:

def accumulate_till
  list = []
  until (x, bool = yield) and bool do
    list << x
  end
  list
end
From: Marco Antoniotti
Subject: Re: sorting the input
Date: 
Message-ID: <1bfa2f97-d24c-4c07-8fff-33c588f23d8b@x41g2000hsb.googlegroups.com>
On Sep 15, 11:15 pm, William James <·········@yahoo.com> wrote:
> On Sep 15, 4:07 am, Lars Rune Nøstdal <···········@gmail.com> wrote:
>
>
>
> > On Mon, 2008-09-15 at 01:36 -0700, William James wrote:
> > > On Sep 15, 2:59 am, "John Thingstad" <·······@online.no> wrote:
> > > > På Mon, 15 Sep 2008 08:46:56 +0200, skrev arnuld <·······@invalid.address>:
>
> > > > >> On Mon, 15 Sep 2008 10:53:19 +0500, arnuld wrote:
>
> > > > >> ..SNIP...
>
> > > > >> [10]> (sort (list (read-line) (read-line) (read-line)) #'string-lessp)
> > > > >> like
> > > > >> baby
> > > > >> is
> > > > >> ("baby" "is" "like")
> > > > >> [11]>
>
> > > > >> ....SNIP....
>
> > > > > I tried hard and came with this code:
>
> > > > > ;;; This program will ask the user for input and will then print the
> > > > > words
> > > > > ;;; in alphabetically sorted format
>
> > > > > (defun main()
> > > > >   (format t "This program will sort the words you will enter")
> > > > >   (defparameter input-list NIL)
> > > > >   (get-input input-list)
> > > > >   (sort input-list #'string-lessp)
> > > > >   (progn input-list))
>
> > > > > (defun get-input (list-of-strings)
> > > > >   (defparameter input-string NIL)
> > > > >   (while (setq input-string (read-line)) )
> > > > >     (pushnew input-string list-of-strings))
>
> > > > > I did:
>
> > > > >   (load          "filename.lisp")
> > > > >   (compile-file  "filename.lisp")
>
> > > > > and it compiled without any failure. I don't know how to run the program.
> > > > > It has created filename.fas and filename.lib files in the current
> > > > > directory automatically.
>
> > > > You "run" it the same way you any other function withing the REPL. How did
> > > > you "run" sort? And why are you calling it main. This isn't C.
>
> > > > Not that this code would work.
>
> > > > 1. You format hasn't added any line breaks. add use "text~%".
> > > > 2. defparameter defines a global parameter every time the function is run.
> > > > It doesn't make a whole lot of sense. Lexical (local) variables are made
> > > > with let.
> > > > 3. Why do you insist on throwing away the returned values of your
> > > > functions? Obviously they will have no effect. Simularly functions have to
> > > > return a value.
> > > > 4. Where did 'while' come from? RTFM!
>
> > > > (defun read-words ()
> > > >    (let ((words nil))
> > > >      (format t "~&Enter words a line at a time and quit by typing
> > > > 'quit'.~%")
> > > >      (loop
> > > >         (let ((word (read-line)))
> > > >            (when (string= word "quit") (return)) ; exits 'loop', not
> > > > function
> > > >            (pushnew word words)))
> > > >      words))
>
> > > Ruby:
>
> > > def read_words
> > >   word, words = nil, []
> > >   puts "Enter words a line at a time & quit by typing 'quit'."
> > >   words << word until "quit" == word = gets.strip
> > >   words
> > > end
>
> > Lisp:
> > (defun read-words ()
> >   (puts "Enter words a line at a time & quit by typing 'quit'.")
> >   (loop :for word = (read-line) :until (string= word "quit") :collect word))
>
> > ..much better.
>
> Good.
>
> Ruby:
> def read_words
>   puts "Enter words a line at a time & quit by typing 'quit'."
>   accumulate_till{ [ w = gets.strip, "quit" == w ] }
> end
>
> with this proviso:
>
> def accumulate_till
>   list = []
>   until (x, bool = yield) and bool do
>     list << x
>   end
>   list
> end

Apologies for the noise.

I am missing the

   accumulate_till.compile_to_assembly()

method (or similarly named one;
accumlate_till.compile_to_JVM_bytecodes() would be a proof of
existence).  Where can I find it?

Cheers
--
Marco
From: Lars Rune Nøstdal
Subject: Re: sorting the input
Date: 
Message-ID: <1221523297.10480.288.camel@blackbox>
On Mon, 2008-09-15 at 14:15 -0700, William James wrote:
> On Sep 15, 4:07 am, Lars Rune Nøstdal <···········@gmail.com> wrote:
> > On Mon, 2008-09-15 at 01:36 -0700, William James wrote:
> > > On Sep 15, 2:59 am, "John Thingstad" <·······@online.no> wrote:
> > > > På Mon, 15 Sep 2008 08:46:56 +0200, skrev arnuld <·······@invalid.address>:
> >
> > > > >> On Mon, 15 Sep 2008 10:53:19 +0500, arnuld wrote:
> >
> > > > >> ..SNIP...
> >
> > > > >> [10]> (sort (list (read-line) (read-line) (read-line)) #'string-lessp)
> > > > >> like
> > > > >> baby
> > > > >> is
> > > > >> ("baby" "is" "like")
> > > > >> [11]>
> >
> > > > >> ....SNIP....
> >
> > > > > I tried hard and came with this code:
> >
> > > > > ;;; This program will ask the user for input and will then print the
> > > > > words
> > > > > ;;; in alphabetically sorted format
> >
> > > > > (defun main()
> > > > >   (format t "This program will sort the words you will enter")
> > > > >   (defparameter input-list NIL)
> > > > >   (get-input input-list)
> > > > >   (sort input-list #'string-lessp)
> > > > >   (progn input-list))
> >
> > > > > (defun get-input (list-of-strings)
> > > > >   (defparameter input-string NIL)
> > > > >   (while (setq input-string (read-line)) )
> > > > >     (pushnew input-string list-of-strings))
> >
> > > > > I did:
> >
> > > > >   (load          "filename.lisp")
> > > > >   (compile-file  "filename.lisp")
> >
> > > > > and it compiled without any failure. I don't know how to run the program.
> > > > > It has created filename.fas and filename.lib files in the current
> > > > > directory automatically.
> >
> > > > You "run" it the same way you any other function withing the REPL. How did
> > > > you "run" sort? And why are you calling it main. This isn't C.
> >
> > > > Not that this code would work.
> >
> > > > 1. You format hasn't added any line breaks. add use "text~%".
> > > > 2. defparameter defines a global parameter every time the function is run.
> > > > It doesn't make a whole lot of sense. Lexical (local) variables are made
> > > > with let.
> > > > 3. Why do you insist on throwing away the returned values of your
> > > > functions? Obviously they will have no effect. Simularly functions have to
> > > > return a value.
> > > > 4. Where did 'while' come from? RTFM!
> >
> > > > (defun read-words ()
> > > >    (let ((words nil))
> > > >      (format t "~&Enter words a line at a time and quit by typing
> > > > 'quit'.~%")
> > > >      (loop
> > > >         (let ((word (read-line)))
> > > >            (when (string= word "quit") (return)) ; exits 'loop', not
> > > > function
> > > >            (pushnew word words)))
> > > >      words))
> >
> > > Ruby:
> >
> > > def read_words
> > >   word, words = nil, []
> > >   puts "Enter words a line at a time & quit by typing 'quit'."
> > >   words << word until "quit" == word = gets.strip
> > >   words
> > > end
> >
> > Lisp:
> > (defun read-words ()
> >   (puts "Enter words a line at a time & quit by typing 'quit'.")
> >   (loop :for word = (read-line) :until (string= word "quit") :collect word))
> >
> > ..much better.
> 
> Good.
> 
> Ruby:
> def read_words
>   puts "Enter words a line at a time & quit by typing 'quit'."
>   accumulate_till{ [ w = gets.strip, "quit" == w ] }
> end
> 
> with this proviso:
> 
> def accumulate_till
>   list = []
>   until (x, bool = yield) and bool do
>     list << x
>   end
>   list
> end

That looks like shit. If you disagree; then why are you here in the
first place?

-- 
Lars Rune Nøstdal   || AJAX/Comet GUI type stuff for Common Lisp
http://nostdal.org/ || http://groups.google.com/group/symbolicweb
From: John Thingstad
Subject: Re: sorting the input
Date: 
Message-ID: <op.uhilqapdut4oq5@pandora.alfanett.no>
P� Mon, 15 Sep 2008 09:59:08 +0200, skrev John Thingstad  
<·······@online.no>:

>
> (defun read-words ()
>    (let ((words nil))
>      (format t "~&Enter words a line at a time and quit by typing  
> 'quit'.~%")
>      (loop
>         (let ((word (read-line)))
>            (when (string= word "quit") (return)) ; exits 'loop', not  
> function
>            (pushnew word words)))
>      words))
>

The others have one liners.
But how about trimming beginning and trailing spaces.
Adding a prompt to the beginning of each line.
Checking the word is a valid word.

Some lispers happily trade robustness for code elegance.

Try adding some of these features.

Oh, and it should be (pushnew word words :test #'equal). As it stood it  
checks whether strings are at the same location in memory. Not if they  
contain the same characters.


--------------
John Thingstad
From: Espen Vestre
Subject: Re: sorting the input
Date: 
Message-ID: <m1myid68w0.fsf@gazonk.vestre.net>
arnuld <·······@invalid.address> writes:

> [3]> (sort (write-string (read-line)))

Please, please RTFM before you post here! (and learn what arguments
to pass to sort)

And also read Pascal's helpful clarification of what I said about
clisp!

If you prefer stand-alone binaries, some lisp implementations will
give you that easily. Here's how I'd do it in the most minimal way in
Lispworks:
------
(compile 
 (defun main ()
  ;; insert your code here
   ))

(deliver 'main "my-sort" 5)
------
-- 
  (espen)