[plt-scheme] Re: Naming style

From: Will Duquette (will at wjduquette.com)
Date: Sat Feb 14 18:20:14 EST 2009

Thanks both, for the answers.  Keyword style is what I had in mind.
(I do most of my programming in Tcl/Tk these days, and Scheme keywords
seem the obvious analogy to Tcl-style option arguments.)

A follow-on question.  I gather Scheme has keyword arguments with the
syntax #:mykeyword.  In the example

   (append 'horizontal)

you use an ordinary quoted symbol instead of a keyword symbol, e.g.,
#:horizontal.  Which would normally be considered good style for
keywords?  (And while we're on that, why is the keyword prefix "#:"
instead of the shorter ":", as in Common Lisp?  (I don't mean to be
critical; I'm just curious.)

Thanks again!

Will Duquette

On Feb 14, 2:08 pm, Robby Findler <ro... at eecs.northwestern.edu> wrote:
> 1. is the historically accurate reason.
>
> Robby
>
>
>
> On Sat, Feb 14, 2009 at 4:04 PM, Eli Barzilay <e... at barzilay.org> wrote:
> > On Feb 13, Will Duquette wrote:
> >> Warning: I am a clueless newbie when it comes to PLT-Scheme (though I
> >> have some slight background with Lisp-like languages).
>
> >> I've just started glancing at "An Introduction to Scheme with
> >> Pictures", which uses something called "#lang slideshow".  Almost
> >> immediately I see the function "hc-append".  When I go look at the
> >> docs, as suggested, I see that it's one of a family of functions, all
> >> of which follow this naming convention:
>
> >>     <options>-<operation>
>
> >> Thus, this command appends pictures together horizontally ("h"),
> >> centering them vertically. ("c").
>
> >> This strikes me as a very add way to name functions; I'd have
> >> thought that having one function, "append", with arguments
> >> indicating the alignment, would make more sense.  On the other hand,
> >> someone implemented it this way on purpose, and given that it's used
> >> in a document for newbies like me I presume it's good style.  Would
> >> someone care to explain to me *why* it's good style?
>
> > There are two arguments for this that I can think of (disclaimer: I'm
> > not the one who wrote that interface...):
>
> > 1. It was designed before PLT had an organized way for using keyword
> >   arguments, which are one of the obvious ways to make a more
> >   convenient interface.
>
> > 2. Having separate bindings for `hc-append' and `vc-append' (for
> >   example) mean that you'll get feedback of whether you wrote the
> >   right thing immediately: if there is no `vc-append' (or if you made
> >   some typo) then the code wouldn't even compile, and you'll know
> >   that you need to fix it.
>
> >   OTOH, you could have a mode argument, and have `append' check it
> >   and either use the mode or throw an error -- that means that you
> >   only get an error when you try to run the code.  BTW, there is also
> >   an option of:
>
> >     (define (append mode blah ...)
> >       (let ([horiz (eq? mode 'horizontal)])
> >         ...))
>
> >   which means that a user typo like
>
> >     (append 'horiz)
>
> >   will silently use vertical mode, which can be very confusing.
>
> > --
> >          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
> >                  http://www.barzilay.org/                Maze is Life!
> > _________________________________________________
> >  For list-related administrative tasks:
> >  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> _________________________________________________
>   For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme


Posted on the users mailing list.