|
|||
|
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? |
|
|
||||
|
||||
|
|
|
|||
|
"laplacian42@gmail.com" <laplacian42@gmail.com> writes:
> 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? 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__ |
|
|||
|
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? |
|
|||
|
"laplacian42@gmail.com" <laplacian42@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 |
|
|||
|
"laplacian42@gmail.com" <laplacian42@gmail.com> writes:
> 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? 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__ |
|
|||
|
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/viewpo...?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 |
|
|||
|
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 |
|
|||
|
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_. |
|
|||
|
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> |
|
|||
|
On 15 Mar, 07:12, "laplacia...@gmail.com" <laplacia...@gmail.com>
wrote: > 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? 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). |
|
|||
|
Elena <egarrulo@gmail.com> writes:
>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? 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 <arcfide@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))) ++++++++++++++ |
|
|||
|
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? |
|
|||
|
Grant Rettke <grettke@gmail.com> writes:
>On Mar 17, 10:21=A0pm, 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? 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. -- Aaron W. Hsu <arcfide@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 wrote:
> 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? "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:michael@schuerig.de http://www.schuerig.de/michael/ |
|
|||
|
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 |
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Re: Create macro variable to refer to program name - for multiple | kat j | Newsgroup comp.soft-sys.sas | 0 | 07-26-2007 05:03 PM |
| Re: Create macro variable to refer to program name - for multiple | toby dunn | Newsgroup comp.soft-sys.sas | 0 | 07-26-2007 03:11 PM |
| Create macro variable to refer to program name - for multiple | kat j | Newsgroup comp.soft-sys.sas | 0 | 07-26-2007 02:58 PM |
| OT: design theory: wicked problems | Fehd, Ronald J. | Newsgroup comp.soft-sys.sas | 0 | 01-23-2007 03:04 PM |
| Re: Possible to run a SAS program within another SAS program? | Michael Raithel | Newsgroup comp.soft-sys.sas | 0 | 12-07-2005 07:06 PM |