Hidekazu IWAKI <
i.hid...@gmail.com> writes:
> Hi.
> My understanding of your opinions are
> 1. It isn't a good way to teach functional programming since the
> macros are quite complete and advanced techniques.
> 2. The macros will not lead imperative programmer to typical
> functional programming. They will misunderstand about functional
> programming.
>
> Of course, now that you say that, but if I follow such a line, I can't
> explain anything. I'm not a special instructor of lisp for beginner.
>
> I want only to recommend scheme to my friends casually.
If they're friends, perhaps they trust your judgement, then you can just
tell them to learn scheme without giving anymore details. Point them to
scheme resources on the web:
http://schemers.org/
http://xivilization.net/~marek/tex/schemerocks/schemerocks.pdf
etc.
> Please imagine if a person talk about the first experience language
> for his friends in very detail, the man will lose them later. I don't
> want to lose my friends.
If they're already programmers, they should withstand detailled
explainations about a programming language. Otherwise, you may still be
friend with them, but distrust their programming abilities.
> uh.. So, I'll use this macros as a non-typical functional code.
Macros are not sued for functional style programming. They're used for
metalinguistic style programming (integrated DSL).
Read again my C example. Functional style programming is characterized
by the use of functions as first class objects, and higher order
functions, and the possibility to make recursive function calls. The
important part of my example, is how you can pass a function such as
plus as argument to a function reduce, and how plus and reduce don't
need to use assignation (beside initialization), but just return a new
result given as an expression of function calls.
Of course, one difficulty doing this in C, is that when you have a chain
of function calls such as:
int s=reduce(plus,cons(1,cons(2,cons(3,NULL))),0);
the memory allocated by cons(1,cons(2,cons(3,NULL))) is not freed
automatically. You have to use a garbage collector. For this you can
use BoehmGC (-lgc) or implement one inside your program, but since
there's BoehmGC, it's not even worth speaking of it.
So the advantage of lisp, is that it was the language for which garbage
collection was invented, in 1959. That's why historically functional
programming style has been taught with LISP; FORTRAN and COBOL lacked
recursive function calls, functions as first class object and garbage
collection; C and Pascal lacked garbage collection, but you could still
teach functional programming style with C or Pascal, since you have
first class functions (well half class functions in Pascal) and
recursive function calls in C or Pascal.
One thing that has been added to the functional programming style since,
was closures. (C didn't have closures or anonymous functions until 2011,
Pascal had only delimited closures: local functions can access visible
global and local variable when they're called from a function called in
the same dynamic scope, but they cannot be returned or stored, so they
cannot be called from a different dynamic scope).
(Anonymous functions are only a syntactic nicety, they're not
fundamental to functional programming style, but they're quite practical
indeed. You could still write program in a language that wouldn't allow
literal numbers or literal strings.)
So my definition of the functional programming style is:
- functions are first class objects.
- you can make recursive calls.
- you can make closures.
- there's a garbage collector, or a way to deal with the memory
allocated for function results.
Of course, wikipedia differs, but I'm just a lisper ;-) :
http://en.wikipedia.org/wiki/Functional_programming