Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
idiomatic Lisp style
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 51 - 75 of 79 - Collapse all  -  Translate all to Translated (View all originals) < Older  Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
cartercc  
View profile  
 More options Feb 12 2009, 10:39 am
Newsgroups: comp.lang.lisp
From: cartercc <carte...@gmail.com>
Date: Thu, 12 Feb 2009 07:39:37 -0800 (PST)
Local: Thurs, Feb 12 2009 10:39 am
Subject: Re: idiomatic Lisp style
On Feb 12, 9:51 am, Geoffrey Summerhayes <sumr...@gmail.com> wrote:

> On Feb 12, 9:35 am, Marco Antoniotti <marc...@gmail.com> wrote:

> > Nope.  It prints just fine.  Check the INITIALLY clause.

> Ah well, at least he got your name right. :-(

> --
> Geoff

My apology. Sorry. CC.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pascal J. Bourguignon  
View profile  
 More options Feb 12 2009, 11:54 am
Newsgroups: comp.lang.lisp
From: p...@informatimago.com (Pascal J. Bourguignon)
Date: Thu, 12 Feb 2009 17:54:47 +0100
Local: Thurs, Feb 12 2009 11:54 am
Subject: Re: idiomatic Lisp style

Perhaps you should try:

    Common Lisp: A Gentle Introduction to Symbolic Computation
    David S. Touretzky
    http://www-cgi.cs.cmu.edu/afs/cs.cmu.edu/user/dst/www/LispBook/index....
    http://www.cs.cmu.edu/~dst/LispBook/

> The above is merely an observation, not a personal attack on anyone or
> an insult to the Lisp community, so please, no flames.

Probably the lisp mind is self inquiring.  When I self taught my first
programming language, I had the reference manual. There were example
programs, but no "exercises" properly.  I wrote programs to exercise
each statement I learned, one by one.

Lisp REPL is so natural and essential to the lispers, that it comes
without saying that whenever you're presented with some lisp forms,
you will be exercising it at the REPL, trying variations, playing with
it.

--
__Pascal Bourguignon__


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pascal J. Bourguignon  
View profile  
 More options Feb 12 2009, 11:57 am
Newsgroups: comp.lang.lisp
From: p...@informatimago.com (Pascal J. Bourguignon)
Date: Thu, 12 Feb 2009 17:57:50 +0100
Local: Thurs, Feb 12 2009 11:57 am
Subject: Re: idiomatic Lisp style

It shouldn't prompt fir the first input.  There's nothing in that code
saying that it should.

First, for interactive querying, you should use *QUERY-IO*, not
*standard-output* / *standard-input*.  It could be tolerated to use
*TERMINAL-IO*, but in cases such as those of slime, there's no
directly accessible terminal.  Use *QUERY-IO* to dialog with the user!

Then if you want to ensure that the user sees what you print, you
should use FORCE-OUTPUT or FINISH-OUTPUT.

--
__Pascal Bourguignon__


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Slobodan Blazeski  
View profile  
 More options Feb 12 2009, 11:58 am
Newsgroups: comp.lang.lisp
From: Slobodan Blazeski <slobodan.blaze...@gmail.com>
Date: Thu, 12 Feb 2009 08:58:42 -0800 (PST)
Local: Thurs, Feb 12 2009 11:58 am
Subject: Re: idiomatic Lisp style
On Feb 12, 3:24 pm, cartercc <carte...@gmail.com> wrote:

(gr-blaze)
Enter next grade, 'Q' to quit: 22
Grade: 22, total: 22, count: 1, average: 22

Error: Undefined operator AVG in form (AVG (+ G S) (1+ N)).
  1 (continue) Try invoking AVG again.
  2 Return some values from the form (AVG (+ G S) (1+ N)).
  3 Try invoking something other than AVG with the same arguments.
  4 Set the symbol-function of AVG to another function.
  5 Set the macro-function of AVG 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

Do you know what have you done wrong?

bobi


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Slobodan Blazeski  
View profile  
 More options Feb 12 2009, 12:02 pm
Newsgroups: comp.lang.lisp
From: Slobodan Blazeski <slobodan.blaze...@gmail.com>
Date: Thu, 12 Feb 2009 09:02:38 -0800 (PST)
Local: Thurs, Feb 12 2009 12:02 pm
Subject: Re: idiomatic Lisp style
On Feb 12, 3:27 pm, Marco Antoniotti <marc...@gmail.com> wrote:

Another entry for my blog post. http://tourdelisp.blogspot.com/2008/03/real-lispers.html
Real Lispers use very-long-and-descriptive-hyphenated-names

thanks  Marco

bobi


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
cartercc  
View profile  
 More options Feb 12 2009, 12:23 pm
Newsgroups: comp.lang.lisp
From: cartercc <carte...@gmail.com>
Date: Thu, 12 Feb 2009 09:23:00 -0800 (PST)
Subject: Re: idiomatic Lisp style
On Feb 12, 11:58 am, Slobodan Blazeski <slobodan.blaze...@gmail.com>
wrote:

Yes, I didn't rename the recursive call. When I copied all the
functions to one file, I had renamed it, but this must have come from
my intermediate version. Anyway, the code works, and I think I like
your version the best, mainly because it avoids the loop.

Thanks, CC.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alexander Lehmann  
View profile  
 More options Feb 12 2009, 12:46 pm
Newsgroups: comp.lang.lisp
From: Alexander Lehmann <lehma...@in.tum.de>
Date: Thu, 12 Feb 2009 18:46:46 +0100
Local: Thurs, Feb 12 2009 12:46 pm
Subject: Re: idiomatic Lisp style

cartercc wrote:
> I ran your code, output follows. Doesn't calculate the average. Is
> this my mistake or yours?

> CC

> ...
> Grade: 99, total: 99, count: 1, average: 99.00
> Enter next grade, 'Q' to quit: 988
> Grade: 988, total: 1087, count: 2, average: 543.50
        ^^^
> ...
> Average is 275.00

Seems correct from my point of view ;-)

-- Alexander


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tobias C. Rittweiler  
View profile  
 More options Feb 12 2009, 1:26 pm
Newsgroups: comp.lang.lisp
From: "Tobias C. Rittweiler" <t...@freebits.de.invalid>
Date: Thu, 12 Feb 2009 19:26:45 +0100
Local: Thurs, Feb 12 2009 1:26 pm
Subject: Re: idiomatic Lisp style

Slobodan Blazeski <slobodan.blaze...@gmail.com> writes:
> Another entry for my blog post. http://tourdelisp.blogspot.com/2008/03/real-lispers.html
> Real Lispers use very-long-and-descriptive-hyphenated-names

Brucio, is that you?

  -T.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bob Felts  
View profile  
 More options Feb 12 2009, 1:38 pm
Newsgroups: comp.lang.lisp
From: w...@stablecross.com (Bob Felts)
Date: Thu, 12 Feb 2009 13:38:39 -0500
Local: Thurs, Feb 12 2009 1:38 pm
Subject: Re: idiomatic Lisp style
Pascal J. Bourguignon <p...@informatimago.com> wrote:

> cartercc <carte...@gmail.com> writes:

[...]

> > Personally, I would find it really helpful to have a series of go-slow
> > exercises, with the solutions, as an aid to learning. I'm trying to do
> > this on my own, but I really don't have the Lisp chops to do it, so
> > I'm pulling exercises from other sources that look like they relate to
> > a topic.

> Perhaps you should try:

>     Common Lisp: A Gentle Introduction to Symbolic Computation
>     David S. Touretzky
>     http://www-cgi.cs.cmu.edu/afs/cs.cmu.edu/user/dst/www/LispBook/index....
>     http://www.cs.cmu.edu/~dst/LispBook/

I'm using this book with my 16 yr. old daughter for this very reason.

There are also any number of web sites that have Lisp exercises.  One
example is:

http://www.cc.gatech.edu/computing/classes/cs2360/fall95/handouts/asgn3.
txt


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marco Antoniotti  
View profile  
 More options Feb 12 2009, 4:24 pm
Newsgroups: comp.lang.lisp
From: Marco Antoniotti <marc...@gmail.com>
Date: Thu, 12 Feb 2009 13:24:08 -0800 (PST)
Local: Thurs, Feb 12 2009 4:24 pm
Subject: Re: idiomatic Lisp style
On Feb 12, 3:51 pm, cartercc <carte...@gmail.com> wrote:

Probably something to do with flushing of the buffers in CLisp.  I use
LWM most of the time.

Cheers
--
Marco


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Riesbeck  
View profile  
 More options Feb 12 2009, 4:55 pm
Newsgroups: comp.lang.lisp
From: Chris Riesbeck <Chris.Riesb...@gmail.com>
Date: Thu, 12 Feb 2009 15:55:22 -0600
Local: Thurs, Feb 12 2009 4:55 pm
Subject: Re: idiomatic Lisp style

When Peter was sending out drafts for comments, he asked if I'd use it
in a course, and I said the lack of exercises was a serious problem.

Graham's not so bad on that score, though I augmented and modified for
my purposes.

On the other hand, most textbook exercises are like gym exercises. They
work on one or two muscles but they're not about how it all works
together. They often encourage using the wrong tool for a job *as an
exercise* which would be fine if students were told that in real code
not to invent the wheel.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Riesbeck  
View profile  
 More options Feb 12 2009, 5:00 pm
Newsgroups: comp.lang.lisp
From: Chris Riesbeck <Chris.Riesb...@gmail.com>
Date: Thu, 12 Feb 2009 16:00:40 -0600
Local: Thurs, Feb 12 2009 5:00 pm
Subject: Re: idiomatic Lisp style

cartercc wrote:
> On Feb 11, 11:34 am, cartercc <carte...@gmail.com> wrote:
>> The following script averages a series of grades from console input. I
>> wrote it as if I would write a C program -- obviously not in idiomatic
>> Lisp. How would one rewrite this in idiomatic Lisp?

> Thanks to all. Here is a clean copy of the scripts so far submitted,
> warts and all.

Adding my own approach. In my idiom, I would not limit this to one
function. I start with a vision of a simple loop that does the job,
basically something that says

   while next grade
     update and print stats
   print final average

Then I work as hard as possible to make that loop the first thing anyone
sees, e.g.,

(defun gr-riesbeck ()
   (let ((stats (make-instance 'stats)))
     (loop while (prin1 (add-grade (read-grade) stats)))
     (format t "~%Average is ~g~%" (stats-average stats))))

(defun read-grade ()
   (princ "Enter next grade, 'Q' to quit: ")
   (read))

(defclass stats ()
   ((grade :initform 0)
    (total :initform 0)
    (count :initform 0)
    (average :initform 0 :accessor stats-average)))

(defmethod add-grade (n (s stats))
   (if (numberp n)
     (with-slots (grade total count average) s
       (setq grade n)
       (incf total n)
       (incf count)
       (setq average (/ total count))
       s)))

(defmethod print-object ((s stats) stream)
   (with-slots (grade total count average) s
     (format stream "Grade: ~a, total: ~a, count: ~a, average: ~a~%"
       grade total count average)))


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kaz Kylheku  
View profile  
 More options Feb 12 2009, 5:08 pm
Newsgroups: comp.lang.lisp
From: Kaz Kylheku <kkylh...@gmail.com>
Date: Thu, 12 Feb 2009 22:08:00 +0000 (UTC)
Subject: Re: idiomatic Lisp style
On 2009-02-12, cartercc <carte...@gmail.com> wrote:

> On Feb 11, 11:34 am, cartercc <carte...@gmail.com> wrote:
>> The following script averages a series of grades from console input. I
>> wrote it as if I would write a C program -- obviously not in idiomatic
>> Lisp. How would one rewrite this in idiomatic Lisp?

> Thanks to all. Here is a clean copy of the scripts so far submitted,
> warts and all.

``Scripts''? ;)

How quaint.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kaz Kylheku  
View profile  
 More options Feb 12 2009, 5:47 pm
Newsgroups: comp.lang.lisp
From: Kaz Kylheku <kkylh...@gmail.com>
Date: Thu, 12 Feb 2009 22:47:35 +0000 (UTC)
Local: Thurs, Feb 12 2009 5:47 pm
Subject: Re: idiomatic Lisp style
On 2009-02-12, cartercc <carte...@gmail.com> wrote:

> On Feb 11, 11:34 am, cartercc <carte...@gmail.com> wrote:
>> The following script averages a series of grades from console input. I
>> wrote it as if I would write a C program -- obviously not in idiomatic
>> Lisp. How would one rewrite this in idiomatic Lisp?

> Thanks to all. Here is a clean copy of the scripts so far submitted,
> warts and all.

> ;;;---------------------Charles Carter---------------------
> (defun gr-carter ()
>   (progn
>     (setq total 0)
>     (setq count 0)
>     (setq avg 0)

This is no good. You function has free references to symbols which have no
definition in sight. Worse, you are assigning to them.

In Lisp you cannot use a symbolic form without defining it somewhere as a
lexical variable or symbol macro, dynamic variable, constant, or global symbol
macro.

Because assigning to an unbound symbol actually has some kind of effect
in many Lisps (but not the exact same effect across all of them), the ANSI
standard does not require the situation to be diagnosed as an unbound error.

The behavior is simply undefined!

> ;;;------------------Marco Antoniotti--------------------
> ;;; doesn't prompt for input on the first instance
> (defun gr-anton ()
>    (loop with avg   = 0.0
>         initially (princ "Enter next grade, 'Q' to quit: ")
>         for grade = (read *standard-input* nil t)
>         while (numberp grade)
>         sum grade into total
>         count grade into count
>         do (setf avg (/ total count))
>         do (format t  "Grade: ~a, total: ~a, count: ~a, average: ~G~@
>                            Enter next grade, 'Q' to quit: "
>                    grade total count avg)
>         finally (format t "~&Average is ~G~%" avg)))

Nice. This one gets my vote, if there were to be a poll. :)

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
cartercc  
View profile  
 More options Feb 12 2009, 11:04 pm
Newsgroups: comp.lang.lisp
From: cartercc <carte...@gmail.com>
Date: Thu, 12 Feb 2009 20:04:34 -0800 (PST)
Local: Thurs, Feb 12 2009 11:04 pm
Subject: Re: idiomatic Lisp style
On Feb 12, 5:47 pm, Kaz Kylheku <kkylh...@gmail.com> wrote:

> > ;;;---------------------Charles Carter---------------------
> > (defun gr-carter ()
> >   (progn
> >     (setq total 0)
> >     (setq count 0)
> >     (setq avg 0)

> This is no good. You function has free references to symbols which have no
> definition in sight. Worse, you are assigning to them.

Which was one of the reasons I posted this thread. Due to my
ignorance, I simply did not know how to do it.

> In Lisp you cannot use a symbolic form without defining it somewhere as a
> lexical variable or symbol macro, dynamic variable, constant, or global symbol
> macro.

Unlike C, or Perl, where you can declare a variable without assigning
it a value. It's not enough to know that you can't do it, but WHY you
can't do it.

> Because assigning to an unbound symbol actually has some kind of effect
> in many Lisps (but not the exact same effect across all of them), the ANSI
> standard does not require the situation to be diagnosed as an unbound error.

Okay, how would you explain that in language that someone who was not
familiar with Lisp would understand? What is a symbol? Other languages
don't seem to have them. Is it a variable? Why say that it is
'unbound' rather than saying that it has been declared but not yet
assigned a value?

> The behavior is simply undefined!

Which means what? In Perl, my day-to-day language, undefined objects
can play important, positive roles, that is, an object can exist but
not be defined, you can test for that state, and use it as a boolean
test for iteration or selection structures.

Why do you like it more than the others? (Not interested in right or
wrong, but simply in your reasons for liking this one.)

CC


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kenneth Tilton  
View profile  
 More options Feb 13 2009, 12:41 am
Newsgroups: comp.lang.lisp
From: Kenneth Tilton <kentil...@gmail.com>
Date: Fri, 13 Feb 2009 00:41:09 -0500
Local: Fri, Feb 13 2009 12:41 am
Subject: Re: idiomatic Lisp style

Did you just change the subject? Aside from that, not sure you want to
say "unlike" when Lisp does the same as what you are unliking:

(defvar *wtf*)

> It's not enough to know that you can't do it, but WHY you
> can't do it.

Because that is what the spec says? Too easy? If you were looking for a
good reason, I would say that since the lamnguage has  both dynamic and
lexical scope that if a compiler comes across a variable it simply has
never seen before then it is forced into guessing at whether someone
forget defvar or let and it really hates guessing. so it guesses but
yells (my lisp anyway).

>> Because assigning to an unbound symbol actually has some kind of effect
>> in many Lisps (but not the exact same effect across all of them), the ANSI
>> standard does not require the situation to be diagnosed as an unbound error.

> Okay, how would you explain that in language that someone who was not
> familiar with Lisp would understand?

(1) become familiar with Lisp
(2) read that again

> What is a symbol?

a data structure, in effect, with a name unique within a package. I
think you are starting at the wrong end.

> Other languages
> don't seem to have them. Is it a variable? Why say that it is
> 'unbound' rather than saying that it has been declared but not yet
> assigned a value?

because unbound is about ten words shorter?

>> The behavior is simply undefined!

> Which means what?

nose. demons. please note order.

 > In Perl, my day-to-day language, undefined objects

> can play important, positive roles, that is, an object can exist but
> not be defined, you can test for that state, and use it as a boolean
> test for iteration or selection structures.

Sure. Ill-considered hacks of languages do all sorts of whacky things
until they grow up if they do before they die.

kt


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew Reilly  
View profile  
 More options Feb 13 2009, 3:06 am
Newsgroups: comp.lang.lisp
From: Andrew Reilly <andrew-newsp...@areilly.bpc-users.org>
Date: 13 Feb 2009 08:06:43 GMT
Local: Fri, Feb 13 2009 3:06 am
Subject: Re: idiomatic Lisp style

On Fri, 13 Feb 2009 00:41:09 -0500, Kenneth Tilton wrote:
> Sure. Ill-considered hacks of languages do all sorts of whacky things
> until they grow up if they do before they die.

Always, it seems.

After your mention of Richard Gabriel the other day, I read a few papers
from his web site, including "A Pattern of Language Evolution" (with Guy
Steele, Jr.), which I thought was really interesting.  There was a cool
bit where some of the MacLisp users were complaining that one of the
trade-offs intended to make it and Interlisp more similar was that (car
nil) -> nil and (cdr nil) -> nil.  The *reason* that they didn't like
this is that up until then they'd been able to (cdr symbol) to get the
property list for  symbol (just because that's where it was stored in
memory).  They weren't concerned about the great boon that this would
bring to the conciseness of their code (ref the thread on the finer
points of car), but that this required that nil be treated differently
from all of the other symbols.  History is neat, huh?

Cheers,

--
Andrew


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Slobodan Blazeski  
View profile  
 More options Feb 13 2009, 3:10 am
Newsgroups: comp.lang.lisp
From: Slobodan Blazeski <slobodan.blaze...@gmail.com>
Date: Fri, 13 Feb 2009 00:10:15 -0800 (PST)
Local: Fri, Feb 13 2009 3:10 am
Subject: Re: idiomatic Lisp style
On Feb 12, 7:26 pm, "Tobias C. Rittweiler" <t...@freebits.de.invalid>
wrote:
> Slobodan Blazeski <slobodan.blaze...@gmail.com> writes:
> > Another entry for my blog post.http://tourdelisp.blogspot.com/2008/03/real-lispers.html
> > Real Lispers use very-long-and-descriptive-hyphenated-names

> Brucio, is that you?

Who's Brucio?

bobi


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Slobodan Blazeski  
View profile  
 More options Feb 13 2009, 3:21 am
Newsgroups: comp.lang.lisp
From: Slobodan Blazeski <slobodan.blaze...@gmail.com>
Date: Fri, 13 Feb 2009 00:21:43 -0800 (PST)
Local: Fri, Feb 13 2009 3:21 am
Subject: Re: idiomatic Lisp style
On Feb 12, 6:23 pm, cartercc <carte...@gmail.com> wrote:

> Yes, I didn't rename the recursive call. When I copied all the
> functions to one file, I had renamed it, but this must have come from
> my intermediate version. Anyway, the code works, and I think I like
> your version the best, mainly because it avoids the loop.

Thank you for your kind words, when you feel ready please consider
joining the club of extended loop haters, functional style bigots and
OO loathers. There is no entry fee but as per out first chairman
recommendation there is tax on every use of:
set setq setf psetf psetq incf decf push pop pushnew
rplaca rplacd rotatef shiftf remf remprop remhash

cheers
Bobi


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Slobodan Blazeski  
View profile  
 More options Feb 13 2009, 3:29 am
Newsgroups: comp.lang.lisp
From: Slobodan Blazeski <slobodan.blaze...@gmail.com>
Date: Fri, 13 Feb 2009 00:29:25 -0800 (PST)
Local: Fri, Feb 13 2009 3:29 am
Subject: Re: idiomatic Lisp style
On Feb 13, 5:04 am, cartercc <carte...@gmail.com> wrote:

> On Feb 12, 5:47 pm, Kaz Kylheku <kkylh...@gmail.com> wrote:

> > > ;;;---------------------Charles Carter---------------------
> > > (defun gr-carter ()
> > >   (progn
> > >     (setq total 0)
> > >     (setq count 0)
> > >     (setq avg 0)

> > This is no good. You function has free references to symbols which have no
> > definition in sight. Worse, you are assigning to them.

> Which was one of the reasons I posted this thread. Due to my
> ignorance, I simply did not know how to do it.

Though its nice to share your code here in cll, it would be probably
be better to go through some nice book first
http://tourdelisp.blogspot.com/2009/02/learning-common-lisp.html if
you got stuck or you have problem to understand anything feel free  to
ask here, or even better use (describe 'some-symbol) first than ask.
Unlike some lazy bastards like this
http://groups.google.com/group/comp.lang.lisp/browse_thread/thread/a8...

bobi


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pascal J. Bourguignon  
View profile  
 More options Feb 13 2009, 4:28 am
Newsgroups: comp.lang.lisp
From: p...@informatimago.com (Pascal J. Bourguignon)
Date: Fri, 13 Feb 2009 10:28:09 +0100
Local: Fri, Feb 13 2009 4:28 am
Subject: Re: idiomatic Lisp style

cartercc <carte...@gmail.com> writes:
>> The behavior is simply undefined!

> Which means what?

Which means that the standard doesn't say what will happen.

An implementation may say what will happen, but there could be
implementation where this would still be undefined.  That's where
nasal demons enter the scene.

> In Perl, my day-to-day language, undefined objects
> can play important, positive roles, that is, an object can exist but
> not be defined, you can test for that state, and use it as a boolean
> test for iteration or selection structures.

Perl is not defined.  There's no perl standard.  There's no
alternative implementation.

--
__Pascal Bourguignon__


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rob Warnock  
View profile  
 More options Feb 13 2009, 6:57 am
Newsgroups: comp.lang.lisp
From: r...@rpw3.org (Rob Warnock)
Date: Fri, 13 Feb 2009 05:57:52 -0600
Local: Fri, Feb 13 2009 6:57 am
Subject: Re: idiomatic Lisp style
cartercc  <carte...@gmail.com> wrote:

+---------------
| Output below. Apparently needs a priming read as it doesn't prompt
| the user for the first input.
+---------------

It doesn't need a "priming READ"; it needs[1] a FORCE-OUTPUT after
the initial PRINC, and possibly after the main FORMAT as well.

-Rob

[1] Well, whether it *needs* it or not is implementation-dependent,
    but adding FORCE-OUTPUT will portably make it work.

-----
Rob Warnock                     <r...@rpw3.org>
627 26th Avenue                 <URL:http://rpw3.org/>
San Mateo, CA 94403             (650)572-2607


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kaz Kylheku  
View profile  
 More options Feb 13 2009, 8:45 pm
Newsgroups: comp.lang.lisp
From: Kaz Kylheku <kkylh...@gmail.com>
Date: Sat, 14 Feb 2009 01:45:23 +0000 (UTC)
Local: Fri, Feb 13 2009 8:45 pm
Subject: Re: idiomatic Lisp style
On 2009-02-13, cartercc <carte...@gmail.com> wrote:

I don't follow this. I didn't say that in Lisp you had to provide a value while
defining a variable, but that you had to define a variable before using it.

You certainly can define a dynamic variable in Lisp without giving it a value.

> It's not enough to know that you can't do it, but WHY you
> can't do it.

Why you can't use a variable without defining it is simply because that's
how the language is.

There are languages in which you can just use a previously unknown name, and it
magically becomes a variable right there, and even has some default value.

In the POSIX shell language you can evaluate $anything, and it works---unless
checking for unset variables been turned on with ``set -u''. So the POSIX shell
language is two languages in one: one in which variables must be defined before
use, and a language in which they don't have to be.

>> Because assigning to an unbound symbol actually has some kind of effect
>> in many Lisps (but not the exact same effect across all of them), the ANSI
>> standard does not require the situation to be diagnosed as an unbound error.

> Okay, how would you explain that in language that someone who was not
> familiar with Lisp would understand?

The prof teaching the course is supposed to understand the above language, and
it's his job to teach that in a way that the students understand.

> What is a symbol? Other languages
> don't seem to have them.

The term symbol is certainly used in other languages. C toolchains typically
refer to object files has having ``symbols'', etc.

I wasn't using ``symbol'' as a Lisp data type here.

>? Is it a variable? Why say that it is
> 'unbound' rather than saying that it has been declared but not yet
> assigned a value?

Because unbound is roughly the opposite of defined or declared.

I.e. why would I say ``X'', if I really wanted to say ``not X''?

>> The behavior is simply undefined!

> Which means what?

Which means that the American national standard for the language does not
impose any requirements about how a language implementation should respond
to the construct.

If demons fly out of the programmer's nose, that is conforming behavior.

This is what ``undefined behavior'' commonly means in the definitions of many
programming languages, not only in Lisp.

> In Perl, my day-to-day language, undefined objects

Well, your day-to-day language is a moving target that is defined by the
behavior of its latest source code tarball.

> can play important, positive roles

``Undefined object'' is not the same thing as ``undefined behavior''.

A program defining a variable is a completely different ``defining'' from a
language standard defining a requirement that a program or language
implementation must mean.

> Why do you like it more than the others? (Not interested in right or
> wrong, but simply in your reasons for liking this one.)

Because it neatly meets all of the requirements using features of LOOP, which
are missed by some of the other implementations. So, in effect, it's all
written in one programming language: the LOOP programming language.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Thomas A. Russ  
View profile  
 More options Feb 13 2009, 8:23 pm
Newsgroups: comp.lang.lisp
From: t...@sevak.isi.edu (Thomas A. Russ)
Date: 13 Feb 2009 17:23:06 -0800
Local: Fri, Feb 13 2009 8:23 pm
Subject: Re: idiomatic Lisp style

cartercc <carte...@gmail.com> writes:
> On Feb 12, 5:47ˇ pm, Kaz Kylheku <kkylh...@gmail.com> wrote:

[snip undeclared variable example]

> > In Lisp you cannot use a symbolic form without defining it somewhere as a
> > lexical variable or symbol macro, dynamic variable, constant, or global symbol
> > macro.

> Unlike C, or Perl, where you can declare a variable without assigning
> it a value. It's not enough to know that you can't do it, but WHY you
> can't do it.

Well, you can declare global (special = dynamic) variable without giving them a
value.  They are then UNBOUND.  But since there is a difference in the
behavior of special and lexical variables, it is good practice to
declare any variables you wish to have be treated as special, since this
is often a globally pervasive decision and affects the treatment of
variables bound in LET blocks.

In fact, since the behavior is so different, Lisp coding style has
adopted the very strong and nearly universal convention of denoting
special variables by naming them so that they begin and end with
asterisk ("*") characters.  In fact, there are some lisps that will give
a style warning for globally special variables that are not so named.

> > Because assigning to an unbound symbol actually has some kind of effect
> > in many Lisps (but not the exact same effect across all of them), the ANSI
> > standard does not require the situation to be diagnosed as an unbound error.

> Okay, how would you explain that in language that someone who was not
> familiar with Lisp would understand? What is a symbol? Other languages
> don't seem to have them.

That is correct.  Most other languages DON'T have them.  Symbols are one
of the basic objects that exist in Common Lisp.  They have many
properties, but among them is that they can be bound to values, which
makes them be variables.

> Is it a variable?

No.  It is a first-class object in its own right.  It may be used to
name a variable, and when bound to values it acts like a variable.  But
it has additional functions as well.  It can name a function and a class
in addition to having a (lexical or dynamic) value.

> Why say that it is
> 'unbound' rather than saying that it has been declared but not yet
> assigned a value?

Because that is the lisp terminology.  The association of a symbol with
a value is called a "binding" of that symbol.  So if there is no such
binding, then the logical name for the state is "unbound".  This is a
fundamental term in lisp, so it's good to get used to it.

> > The behavior is simply undefined!

> Which means what?

It means that if you do that, you can't predict what a conforming
implementation of Common Lisp will do.  Now, all known implementations
do something "reasonable", but exactly what that reasonable behavior is
does vary, perhaps in subtle ways, between implementations.

The majority of lisps will treat references to undeclared variables as
special (=dynamic) references to those variables.  But that is done each
time the variable is encountered, and doesn't affect the global state of
declarations.  In other lisps, notably CMUCL, setting the undeclared
variable makes it be proclaimed to be globally special, on the
assumption that the user reallly meant that, but forgot.  That is
different behavior because it affects the state of global definitions.

In all cases I'm aware of, the compiler will complain (issue a warning).

Those two compilers will treat the following code differently, and give
you different answers:

    (defun foo () (print a))

    (setf a 10)

    (let ((a 5))
      (foo))

One implementation will print 5 and the other 10.  And you can't
complain because the behavior is not defined by the standard.  That is
precisely what "undefined behavior" means.

> In Perl, my day-to-day language, undefined objects
> can play important, positive roles, that is, an object can exist but
> not be defined, you can test for that state, and use it as a boolean
> test for iteration or selection structures.

There is an important difference between a value being undefined and
behavior being undefined.  Even in Perl, you would probably not want to
do something where the implementation says the effects are undefined
(and thus not predictable).

Actually, Perl probably doesn't really have undefined objects, but
rather it refers to pointers (variables) that don't point to any
particular object.  (Or else to a special value, "null", that isn't any
object.  I'm not really up on the details of Perl semantics).

--
Thomas A. Russ,  USC/Information Sciences Institute


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Wooding  
View profile  
 More options Feb 19 2009, 12:37 pm
Newsgroups: comp.lang.lisp
From: Mark Wooding <m...@distorted.org.uk>
Date: Thu, 19 Feb 2009 17:37:33 +0000
Local: Thurs, Feb 19 2009 12:37 pm
Subject: Re: idiomatic Lisp style

Kaz Kylheku <kkylh...@gmail.com> writes:
> I use &aux if I just need one /more/ local.

I think the only circumstances under which I use &AUX are in DEFSTRUCT
constructor lambda-lists.

-- [mdw]


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 51 - 75 of 79 < Older  Newer >
« Back to Discussions « Newer topic     Older topic »