gnu-arch-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnu-arch-users] Re: Tla spork


From: Zenaan Harkness
Subject: Re: [Gnu-arch-users] Re: Tla spork
Date: Sat, 28 Aug 2004 11:12:18 +1000
User-agent: Mutt/1.5.6+20040523i

On Fri, Aug 27, 2004 at 04:50:10PM +0100, Andrew Suffield wrote:
> On Fri, Aug 27, 2004 at 04:40:37PM +0200, Tobias C. Rittweiler wrote:
> > (define (fib n)
> >   (if (or (= n 0) (= n 1))
> >      1
> >      (+ (fib (- n 1)) 
> >         (fib (- n 2)))))
> 
> Now, let's introduce a rule that says parentheses aren't required:
> function applications bind stronger than anything else and associate
> to the left.
> 
> define (fib n)
>   if (or (= n 0) (= n 1))
>     1
>     + (fib (- n 1))
>       (fib (- n 2))
> 
> That's got rid of a few nasty parentheses.

So you only need parens to disambiguate right?

> Now introduce a rule that if a function name is wrapped in (), it is a
> prefix function, and if it is wrapped in ``, it is an infix
> function. Currently, all functions are prefix by default. We'll
> introduce normal logical precedence at the same time.
> 
> Now we introduce a rule which says that a function with a name
> comprised of punctuation !#$%&*+./<=>address@hidden|-~ is infix by default.
> 
> define (fib n)
>   if (or ((=) n 0) ((=) n 1))
>     1
>     (+) (fib ((-) n 1))
>         (fib ((-) n 2))
> 
> But we can also have:
> 
> define (fib n)
>   if (or (n = 0) (n = 1))
>     1
>     fib (n - 1) + fib (n - 2)
> 
> And even:
> 
> define (fib n)
>   if (n = 0 `or` n = 1)
>     1
>     fib (n - 1) + fib (n - 2)

Would it make sense for the `` wrapping to be used when defining
the function, to change it's _default_ ordering from prefix to infix,
or what that get too confusing for users (not knowing what is the
default for a function), which come to think about it might be pretty
likely, and lead to always using explicit `` or () wrapping.

> But let's introduce operator ||:
> 
> define (fib n)
>   if (n = 0 || n = 1)
>     1
>     fib (n - 1) + fib (n - 2)
> 
> Rename = to ==:
> 
> define (fib n)
>   if (n == 0 || n == 1)
>     1
>     fib (n - 1) + fib (n - 2)
> 
> Now, introduce operator '=' which is the infix form of 'define':
> 
> fib n = if (n == 0 || n == 1)
>           1
>           fib (n - 1) + fib (n - 2)
> 
> Now we're starting to get something that's nowhere near as ugly. Let's
> change 'if' to have 'then' and 'else' delimiters:
> 
> fib n = if n == 0 || n == 1
>           then 1
>           else fib (n - 1) + fib (n - 2)
> 
> There, you don't even need to know the language to understand what
> that means. But we're not done yet. if/then/else is a terrible
> structure for non-trivial purposes; it lends itself to unnecessary
> levels of indentation. Let's introduce 'guards'. They work like this:
> 
>  | a = b
>  | c = d
>  otherwise = e
> 
> Which means:
> 
>  if a then b else (if c then d else e)
> 
> (The list of guards can extend without limit)
> 
> And now we have:
> 
> fib n
>  | n == 0  = 1
>  | n == 1  = 1
>  otherwise = fib (n - 1) + fib (n - 2)
> 
> Now *that* is a real syntax (it's Haskell). Almost all the nasty
> parentheses have been eliminated, and those that remain merely enhance
> clarity rather than reduce it.

Thanks Andrew. That too is great stuff! I think I like haskell syntax
better. However I think it is in fact all starting to sink in.

So is there a page or old post someone can point me to to bring pika/
furth, whatever into the picture? I'll try google though...

Thanks again
Zen




reply via email to

[Prev in Thread] Current Thread [Next in Thread]