From: Hugh Aguilar on
On Mar 10, 1:42 am, Helmut Eller <eller.hel...(a)gmail.com> wrote:
> I had the impression that Thinking Forth was concerned a lot with
> style, conventions and the "Forth way" in general. I would also say
> that well written Forth code, e.g. OpenFirmware, is highly stylized.

"Thinking Forth" is one of the best books I've ever read. I agree that
there are important *principles* to keep in mind when writing Forth.
Most bad Forth is the result of mentally porting C programs into Forth
without regard to Forth philosophy.

Philosophy is very important. Style is less important, and I'm pretty
flexible in this regard. For example, you will notice that my LowDraw.
4th program has names with capitals (such as LowDraw). My more recent
programs would use lower-case and hyphens (it would be low-draw in
this case). I switched my style in regard to names just to be more
consistent with what the rest of the Forth world is doing. I don't
really care either way though --- just so long as there is consistency
within a program.

I mostly just get annoyed at people who endlessly harp on the
importance of "idiomatic" code, and who believe that programming can
be done mechanically --- that it isn't a creative process. What they
are preaching isn't a matter of understanding principles, but is more
a matter of imitation without understanding! From what I've seen of
the Lisp community, I think that you guys are mostly with me on this.
I hope so, anyway.
From: Vassil Nikolov on

On Wed, 10 Mar 2010 14:28:54 -0500, Eli Barzilay <eli(a)barzilay.org> said:
> ...
> (proclaim '(optimize (speed 3) (safety 1) (space 0) (debug 0)))
> (defun fib (n) (if (<= n 1) n (+ (fib (- n 1)) (fib (- n 2)))))
> (compile 'fib)
> (time (fib 40))

> It runs in ~3.5 seconds. I then added (declare (fixnum n)) and it
> went down to ~3.3.

Just declaring N to be a fixnum does not make much difference,
without declaring FIB's signature and then something along the lines
of either (a) inserting ``THE FIXNUM'' declarations or (b) declaring
N to be no less than (- MOST-NEGATIVE-FIXNUM 2) and declaring FIB to
return no more than (FLOOR MOST-POSITIVE-FIXNUM 2). (Doing the
above when the compiler prints notes about optimizations that cannot
be made is left as an exercise...)

> ...
> And finally, to make it use unsafe fixnum operations ...

... which should be compared against ``(SAFETY 0)'' with Common Lisp.

---Vassil.


--
No flies need shaving.
From: Vassil Nikolov on

On Wed, 10 Mar 2010 13:51:10 +0000, Tim Bradshaw <tfb(a)tfeb.org> said:
> ...
> I do think that Forth and Lisp should appeal to the same people (well,
> they both appeal to me).

I second this. As another view on it, consider the following
(possibly well-known) thought experiment: what does one do if one
has _only_ bare iron, but no software whatsoever (and no access to
any, either)? A friend proposed to implement Forth as step 1 and
based on that, to implement Lisp as step 2. (As opposed to
"repeating philogenesis" and implementing an assembler as step 1.)

---Vassil.


--
No flies need shaving.
From: Eli Barzilay on
Vassil Nikolov <vnikolov(a)pobox.com> writes:

> On Wed, 10 Mar 2010 14:28:54 -0500, Eli Barzilay <eli(a)barzilay.org> said:
>> ...
>> (proclaim '(optimize (speed 3) (safety 1) (space 0) (debug 0)))
>> (defun fib (n) (if (<= n 1) n (+ (fib (- n 1)) (fib (- n 2)))))
>> (compile 'fib)
>> (time (fib 40))
>
>> It runs in ~3.5 seconds. I then added (declare (fixnum n)) and it
>> went down to ~3.3.
>
> Just declaring N to be a fixnum does not make much difference,
> without declaring FIB's signature and then something along the
> lines of either (a) inserting ``THE FIXNUM'' declarations or (b)
> declaring N to be no less than (- MOST-NEGATIVE-FIXNUM 2) and
> declaring FIB to return no more than (FLOOR MOST-POSITIVE-FIXNUM
> 2). (Doing the above when the compiler prints notes about
> optimizations that cannot be made is left as an exercise...)

Adding a declaration that `fib' is a fixnum to fixnum function, and
adding `the fixnum' around constants didn't make any difference, which
is why I didn't even mention it. However,

>> And finally, to make it use unsafe fixnum operations ...
>
> ... which should be compared against ``(SAFETY 0)'' with Common
> Lisp.

I somehow forgot to try that, and used only the recommended 1 value.
Getting safety down to 0 takes the (fib 40) time down to 2.6, and in
this case adding a declaration for `fib's type and adding `the's does
make a difference and takes it further down to 2.2s.

But in case it wasn't clear -- I wasn't trying to get into any kind of
a pissing contest; if you look at the benchmark pages that I pointed
at, you'll see that PLT does not usually beat the other
implementations (and though it doesn't mention any Common Lisps, I
would have assumed that something as established and with the amount
of work invested in it would be faster -- so I didn't try to optimize
things completely). The point that I did make is that these points

Nicolas Neuss:
> Since you are apparently interested in good performance [...] PLT
> Scheme is not the way to go.

fortunatus <daniel.eliason(a)excite.com>
> On the other hand, while PLT is a slow environment [...chicken...]

are wrong: the difference is, for most code, negligible.

--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://barzilay.org/ Maze is Life!
From: Vassil Nikolov on

On Wed, 10 Mar 2010 23:55:17 -0500, Eli Barzilay <eli(a)barzilay.org> said:
> ...
> adding `the fixnum' around constants didn't make any difference

No, that wouldn't; but, given a fixnum declaration for N, there _is_
a significant difference between (- N 1) and (THE FIXNUM (- N 1)),
or, given fixnum declarations for the return values of FOO and BAR,
there is a significant difference between (+ (FOO ...) (BAR ...))
and (THE FIXNUM (+ (FOO ...) (BAR ...))).

> ...
> I wasn't trying to get into any kind of a pissing contest

No, you weren't, but if we discuss the declarations one could make
in a Common Lisp program to speed it up, let's at least try for
better coverage.

---Vassil.

P.S. Fixnum declarations are really rather crude, of course, but
when employing (INTEGER <lower bound> <upper bound>) types in
declarations (of variables and functions), which can be better
matched to requirements and problem constraints anyway, in a lot of
cases in practice one will not need THE forms to achieve fast
arithmetic operations.


--
No flies need shaving.