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

Re: What?



In article <bruce-8E0B11.09280612082002@copper.ipg.tsnz.net>,
 Bruce Hoult <bruce@hoult.org> wrote:

> In article <joswig-CDF2A4.13101611082002@news.fu-berlin.de>,
>  Rainer Joswig <joswig@lispmachine.de> wrote:
> 
> > Hehe, I hear the Gwydion Dylan people are adding more Lisp stuff
> > to Dylan.
> 
> What are you thinking of here?

Ask Andreas. He seems to have the plan. ;-)

>  I'm certainly interested in seeing if 
> there's anything that CL obviously does better than Dylan,

Ah, there is so much - don't get me started.

> but to date 
> I'm not aware of any changes that have been made to the Dylan language.
> 
> Oh, wait ... I did add a "foo = bar" clause to the for loop as a 
> shorthand for "foo = bar then baz" where bar and baz are the same 
> expression.  So the summing example can be written as:
> 
>  define method sum-stream (stream)
>    let sum = 0;
>    for (n = read-line(stream, on-end-of-stream: #f),
>           while: n)
>      sum := sum + string-to-integer(n);
>    end;
>    sum
>  end;
> 
> I was certainly aware of the corresponding CL usage:
> 
> (defmethod sum-stream ((stream stream))
>   (setq sum 0)
>   (loop for line = (read-line stream nil nil)
>         while line do (incf sum (parse-integer line)))
>   sum)
> 
> So I guess you could that's adding CL stuff to Dylan.  On the other hand 
> I don't have any intention to add collect or sum or count to Gwydion 
> Dylan's for loop.

Above is not useful in CL. LET introduces local variables.
SETQ would set some global variable in this case, because it
does not introduce a binding.

(defmethod sum-stream ((stream stream))
  (let ((sum 0))
    (loop for line = (read-line stream nil nil)
          while line do (incf sum (parse-integer line)))
    sum))

This is another example where I like Lisp syntax much better.
I want the binding to enclose the form - even if the enclosed
form moves two spaces to the right (my Cinema Display makes
even extremely widely formatted Lisp code possible. ;-) )
I think the LET of Dylan is confusing. For me, indentation
and grouping (with parentheses) are real features. ;-)

The more "ugly" version is to introduce the variable in the LOOP:

(defmethod sum-stream ((stream stream))
  (loop with sum = 0
        for line = (read-line stream nil nil)
        while line do (incf sum (parse-integer line)) 
        finally (return sum)))

Or sum directly into a variable (you could have multiple summing
clauses with different variables):

(defmethod sum-stream ((stream stream))
  (loop for line = (read-line stream nil nil)
        while line
        summing (parse-integer line) into sum
        finally (return sum)))

Anyway, the iteration ideas in Dylan are okay and useful.
Previous attempts in Lisp were stuff like LOOP, ITERATE
and SERIES - but they were pre-CLOS. I'm sure, CLOS-based
iteration stuff exists in some libraries, but I have never
seen them used widely.