Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help: seeking program design advice

6 views
Skip to first unread message

lapla...@gmail.com

unread,
Mar 15, 2009, 2:12:58 AM3/15/09
to
Any object oriented programs I've written tend to consist of a number
of objects instantiated from a number of classes. In the "main"
function I create objects as needed and set them off on their various
tasks. This works pretty well for me (AFAICT).

Any C-style function-based programs I've written tend to be a bunch of
functions composed of some other lower-level functions (which
themselves are likely composed of still more lower-level ones), plus
global variables (which seem to often be difficult to avoid). These
programs tend to grow global variables until things get too hairy, at
which point the program starts getting split off into smaller parts.

How does program design work in a language like Scheme? Which parts
should I write first (and last)? Can anyone sum up in a paragraph or
so how you go about writing a program in Scheme?

Pascal J. Bourguignon

unread,
Mar 15, 2009, 5:18:34 AM3/15/09
to
"lapla...@gmail.com" <lapla...@gmail.com> writes:

The one-paragraph answer:

In Scheme, you can go about writing a program in any way you want.


Let's explain:

Scheme, as a lisp, is a multi-paradigm meta-programming programming
language. You can define data structures, so you have data
abstraction. You have first class functions so you have functional
abstraction. You have a homoiconic language so you have easy
meta-linguistic abstraction. And you have macros so you have
syntactic abstraction. This allows you to write in any programming
style, using any paradigm, and even using different paradigms in
different parts of your program.

You can easily do object-oriented, functional, logic, imperative,
rule-based, event-based, data-driven, whatever, programming.

The language doesn't impose a specific methodology or paradigm, or
render your life difficult when you choose your prefered paradigm.
(eg. doing OO in C is possible, but difficult, until you skip a
metalinguistic level implementing a front-end to get Objective-C or
C++ ; on the other hand, doing OO in Scheme is trivial, there are
several libraries implementing different OO systems, and you can write
your own basic OO system in one page of scheme code, completely
integrated with the rest of the language).

So I would say that program design in scheme works by ignoring
entirely the language side, and concentrating only on the problem
domain: you will design your program in function of the problem you
have. If your problem can be solved correctly in some way, then you
will design your program that way. Scheme won't get in your way.

You can write any part in any order. You can do top-down or
bottom-up, or inside-out, or whatever.


--
__Pascal Bourguignon__

lapla...@gmail.com

unread,
Mar 15, 2009, 12:58:10 PM3/15/09
to
On Mar 15, 5:18 am, p...@informatimago.com (Pascal J. Bourguignon)
wrote:

>
> The one-paragraph answer:
>
> In Scheme, you can go about writing a program in any way you want.
>
> Let's explain: [snip]
>

Thank you Pascal, but unfortunately I don't yet know what terms like
homoiconic and meta-linguistic mean. I'm new to Scheme and to
functional programming in general and would like to learn functional
programming using Scheme. Can you recommend a programming methodology
that would work well for that?

Prabhakar Ragde

unread,
Mar 15, 2009, 1:03:22 PM3/15/09
to
"lapla...@gmail.com" <lapla...@gmail.com> writes:

> Thank you Pascal, but unfortunately I don't yet know what terms like
> homoiconic and meta-linguistic mean. I'm new to Scheme and to
> functional programming in general and would like to learn functional
> programming using Scheme. Can you recommend a programming methodology
> that would work well for that?

http://www.htdp.org

--PR

--
Prabhakar Ragde, Professor plragde at uwaterloo dot ca
Cheriton School of Computer Science http://www.cs.uwaterloo.ca/~plragde
Faculty of Mathematics DC 1314, (519)888-4567,x34660
University of Waterloo Waterloo, Ontario CANADA N2L 3G1

Pascal J. Bourguignon

unread,
Mar 15, 2009, 1:49:28 PM3/15/09
to
"lapla...@gmail.com" <lapla...@gmail.com> writes:

The functional programming methodology.
Basically, you avoid side effects and assignments.


For example to compute the average of a list of numbers you could
write it procedurally:

(define (average numbers)
(let ((sum 0)
(count 0))
(do ((nums numbers (cdr nums)))
((null? nums)
(if (= 0 count)
'not-enough-numbers
(/ sum count)))
(set! sum (+ sum (car nums)))
(set! count (+ count 1)))))


or you could write it functionnaly:

(define (average numbers)
(letrec ((average-step
(lambda (numbers sum count)
(if (null? numbers)
(if (= 0 count)
'not-enough-numbers
(/ sum count))
(average-1 (cdr numbers) (+ sum (car numbers)) (+ count 1))))))
(average-step numbers 0 0)))

Start reading
http://en.wikipedia.org/wiki/Functional_programming
and follow the links.

Read SICP, Structure and Interpretation of Computer Programs.

--
__Pascal Bourguignon__

Michele Simionato

unread,
Mar 15, 2009, 2:18:31 PM3/15/09
to
On Mar 15, 5:58 pm, "laplacia...@gmail.com" <laplacia...@gmail.com>
wrote:

> I'm new to Scheme and to
> functional programming in general and would like to learn functional
> programming using Scheme.

There is a six part section of my "Adventures of a Pythonista
in Schemeland" about functional programming that you may
find useful:

http://www.artima.com/weblogs/viewpost.jsp?thread=251474

> Can you recommend a programming methodology
> that would work well for that?

Yes, take a simple example of an imperative program
and try to translate it into a functional style, asking
here when you reach a point where you cannot progress.

Michele Simionato

Elena

unread,
Mar 15, 2009, 2:28:02 PM3/15/09
to
On 15 Mar, 18:49, p...@informatimago.com (Pascal J. Bourguignon)
wrote:

>


> Read SICP, Structure and Interpretation of Computer Programs.
>

Does SICP show how to perform common tasks in a functional way? Is
there a design patterns book for FP. I remember that OOP finally
clicked after reading the GoF book. Currently, I understand what FP
is, but how do you deal for instance with GUI interaction which is
full of state? By means of Continuations Passing Style?

Thanks

Grant Rettke

unread,
Mar 15, 2009, 10:01:27 PM3/15/09
to
On Mar 15, 1:12 am, "laplacia...@gmail.com" <laplacia...@gmail.com>
wrote:

> How does program design work in a language like Scheme? Which parts
> should I write first (and last)? Can anyone sum up in a paragraph or
> so how you go about writing a program in Scheme?

Start with _How to Design Programs_.

nick_keigh...@hotmail.com

unread,
Mar 16, 2009, 7:56:07 AM3/16/09
to
On 15 Mar, 16:58, "laplacia...@gmail.com" <laplacia...@gmail.com>
wrote:

> On Mar 15, 5:18 am, p...@informatimago.com (Pascal J. Bourguignon)
> wrote:

[how do you design scheme programs]

> > The one-paragraph answer:
>
> > In Scheme, you can go about writing a program in any way you want.
>
> > Let's explain: [snip]
>
> Thank you Pascal, but unfortunately I don't yet know what terms like
> homoiconic

http://en.wikipedia.org/wiki/Homoiconicity

"[H] is a property of some programming languages, in which the
primary
representation of programs is also a data structure in a primitive
type
of the language itself, from homo meaning the same and icon meaning
representation."

It's all that a-lisp-program-is-a-list stuff

> and meta-linguistic mean.

http://en.wikipedia.org/wiki/Metalinguistic_abstraction

"[MLA] is the process of solving complex problems by creating a new
language or vocabulary to better understand the problem space."

<snip>

Vend

unread,
Mar 16, 2009, 9:35:58 AM3/16/09
to
On 15 Mar, 07:12, "laplacia...@gmail.com" <laplacia...@gmail.com>
wrote:

Try designing the same way you design C programs (and try to avoid
global variables).
Then, if you like, you can gradually move to the functional paradigm
(no variable mutations).

Aaron W. Hsu

unread,
Mar 17, 2009, 11:21:22 PM3/17/09
to
Elena <egar...@gmail.com> writes:

SICP will teach you how to program. It does this using many paradigms,
but a large portion of the book is what people would call "functional"
style. In any case, the book focuses more on teaching you how to
program, and I think it does a good job of illustrating the errant --
IMO -- emphasis on using one paradigm over the other.

In any case, definitely read the book, because it will be very
educational to you, and you will learn a good deal about programming
paradigms.
--
Aaron W. Hsu <arc...@sacrideo.us> | <http://www.sacrideo.us>
"Government is the great fiction, through which everybody endeavors to
live at the expense of everybody else." -- Frederic Bastiat
+++++++++++++++ ((lambda (x) (x x)) (lambda (x) (x x))) ++++++++++++++

Grant Rettke

unread,
Mar 18, 2009, 11:49:59 AM3/18/09
to
On Mar 17, 10:21 pm, Aaron W. Hsu <arcf...@sacrideo.us> wrote:
> SICP will teach you how to program. It does this using many paradigms,
> but a large portion of the book is what people would call "functional"
> style. In any case, the book focuses more on teaching you how to
> program, and I think it does a good job of illustrating the errant --
> IMO -- emphasis on using one paradigm over the other.

Do you have any favorite multi-paradigm books on learning how to
program?

Aaron W. Hsu

unread,
Mar 18, 2009, 5:16:03 PM3/18/09
to
Grant Rettke <gre...@gmail.com> writes:

Without a doubt SICP is one of my favorites for its general
applicability and no nonsense approach. Other than this, I have to admit
that I haven't seen a lot of books that cover multi-paradigms that well.
The algorithm books do a good job of teaching a key part of programming,
and they really help with "thinking" about the problems in ways that you
wouldn't have thought of before, but often they are written in a sort of
imperative pseudo code.

Most of my computer books that I have are language references,
Algorithms related books, and then Mathematics texts. Of course SICP is
the major exception there.

Michael Schuerig

unread,
Mar 19, 2009, 6:15:24 AM3/19/09
to
Grant Rettke wrote:

"Concepts, Techniques, and Models of Computer Programming" by Peter Van
Roy and Seif Haridi

http://www.info.ucl.ac.be/~pvr/book.html

Michael

--
Michael Schuerig
mailto:mic...@schuerig.de
http://www.schuerig.de/michael/

kub

unread,
Mar 19, 2009, 4:08:35 PM3/19/09
to
I'm not too experienced Scheme programmer but IMHO using language-
oriented approach as much as possible should be a good strategy.
Consider using
- macros/lambdas for Scheme embedded languages
and
- s-expression interpreters/compilers
for DSLs.

For example, you can have embedded language for describing UI which
works via FFI with existing GUI library or you can have full blown UI
DSL which can be compiled to HTML, Java, c#, c, c++ at the same time.

Note that Scheme is probably the best option for a language-oriented
programming.

--
Bogdan

puzzler

unread,
Mar 19, 2009, 10:42:35 PM3/19/09
to
> > Do you have any favorite multi-paradigm books on learning how to
> > program?
>
> "Concepts, Techniques, and Models of Computer Programming" by Peter Van
> Roy and Seif Haridi
>
> http://www.info.ucl.ac.be/~pvr/book.html

This is my favorite multi-paradigm book as well.

0 new messages