Hmm, informed discourse... ok, I'm tempted back.

Beni Cherniavsky <[EMAIL PROTECTED]> wrote:
> First-class functions are quite simple.  Polymorphic classes - a bit
> harder.  Yet doing loops and conditionals with them *is* harder to
> comprehend than::
> 
>     for i in [1, 2, 3]:
>         if i != 2:
>             print i

I beg to differ. I'm sure the following won't seem that strange -
#(1 2 3) do: [:i | 
        (i ~= 2) ifTrue: [Transcript show: i]]

Loops are messages to collections or numbers or blocks (anonymous
functions - code between []s). Conditions are messages to booleans (the
two of which, true and false, respond differently of course). Since
loops aren't syntax, but constructed, you can extend the libraries with
new constructs that you find yourself repeating. For example, if you
know SQL, you can guess what this does:
#(1 2 3 4 5 6) groupBy: [:num | num even] 

Never mind that the same code, implemented once, works on all kinds of
collections, all kinds of stored objects, all keying functions - [:num |
num rem: 2] would have a very simiar effect, despite returning objects
of a different type).

Daniel

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to