POV-Ray : Newsgroups : povray.pov4.discussion.general : Next Generation SDL Brainstorming : Re: Next Generation SDL Brainstorming Server Time
28 Sep 2024 18:41:46 EDT (-0400)
  Re: Next Generation SDL Brainstorming  
From: nemesis
Date: 28 Mar 2009 03:47:34
Message: <49cdd616@news.povray.org>
clipka wrote:
> nemesis <nam### [at] nospam-gmailcom> wrote:
>> (for i from 0 to 9 => (vector-set! vec i (* i i)))
>>
>> Nevertheless, don't you find it amazing to be able to simply churn out
>> new syntax as you see fit?
> 
> #define FROM for(int
> #define TO ;!(
> #define INCREMENT );
> #define BEGIN ++){
> #define END }
> 
> FROM i = 1 TO i = 10 INCREMENT i
> BEGIN
> END
> 
> didn't test it, but if I'm not mistaken it should be perfectly valid C++ code.

It's a very cheap and limited preprocessing trick which won't work if 
you want to place things differently.  In Scheme/Lisp you have true 
syntatic abstraction and it's used for very good purposes.  Macros are 
an intrinsic part of Lisp.

For instance, I can rewrite the same syntax for various purposes:

(define-syntax for
     (syntax-rules (=> from to in resulting initially do:)
       ; simple list iteration
       ((for i in ls do: body ...)
        (for-each (lambda (x) (let ((i x)) body ...)) ls))
       ; imperative iteration over numeric range
       ((for i from x to y do: body ...)
        ((range x y) #t (lambda (i o) (begin body ...) o)))
       ; functional iteration over numeric range
       ((for i from x to y resulting j initially init do: body ...)
        ((range x y) init (lambda (i o) (let ((j o)) body ...))))))

and then use :

 > (for x from 1 to 2 do:
       (for y from 1 to 3 do: (display x)(display y)(newline)))
11
12
13
21
22
23
true
 > (for item in '(1 2 3) do: (display item)(newline))
1
2
3
 > (for x from 5 to 1 resulting y initially () do: (cons (* 2 x) y))
`(2 4 6 8 10)

And the real bad deal:  your example looks more like pascal than C. 
Lisp code is extremely regular, it always look alike, despite new handy 
syntax.

Plus, if I want to DECREMENT in your example I'm screwed, most likely 
having to resort to a different "begin" to try to get around the fact 
that the new "syntax" has its semantics fixed in place but scattered all 
around the labels.


> I have one word for that:
> 
>     Inconsistency.

Indeed.

> *You* can read it, but someone else must first learn your brand-new churned-out
> syntax to grasp your code.

Not a problem in Lisp culture, where people read the code by scope.

 > No, its higher digestibility lies not only in the sheer familiarity of
 > C itself (and its heirs), but mainly in that the basic *concept* is
 > probably familiar to *any* programmer.

Funnily enough, and except for the syntatic abstraction, my example 
dealt only with function definition and function application.  I thought 
those concepts were flying around for ages now.

well, ok, functions returning functions is not generally mainstream...

> So it's not like Windows. It's like GUI. Everyone has seen it, and everyone
> knows at least a *bit* of how to get along in it somehow; even if all your
> computer experience was from a Mac, you'd have at least some vague idea of how
> to do *something* in Windows - and vice versa; even those who prefer to work
> with vi typically know at least a bit about how to operate a GUI. - But place a
> random person in front of a console with vi running, and they'll be lost.
> Utterly. They wouldn't even be able to shut down the computer (well, unless
> they have access to the power switch).

It's an interesting comparison.

Here's a more interesting one:  put a novice with no knowledge of 
programming languages in front of the monitor and ask him/her what 
he/she figures out of this one:

(for x from 1 to 5 do: (display x)(newline))

and then this one:

int i; for(i = 1; i <= 5; i++) printf("%d\n", i);

What is the point of this little experiment?  To show that creating your 
own syntax clearly has many benefits (specially for DSLs) -- like making 
it more suited for the audience/domain or if you simply don't dig the 
basic cryptic one -- and that awkwardness is in the eyes of the 
beholder.  Lisp folks are known to create the language most well suited 
and then program in that.

Scheme is often taught in first year compsci courses because of its 
simplicity:  function definition and function application is all there 
really is to it, predefined syntatic details is minimal.  So, I feel 
astonished when people find it overwhelming.

That said, I wasn't *seriously* proposing Scheme for povray's scripting 
language in the first place although I do believe it could be beneficial 
in many ways.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.