[plt-scheme] Re: (newbie question) About Loop

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Fri Jun 12 08:40:54 EDT 2009


Of course:

#lang scheme

(define-syntax-rule (while tst {body ...}) (let L () (when tst  
body ... (L))))
(define-syntax-rule (:= lhs rhs) (set! lhs rhs))
(define ! not)

;; ---

(define l (mcons 1 null))
(while (! (null? l))
        { (printf "~s\n" (mcar l)) ;
          (:= l (mcdr l)) })





On Jun 12, 2009, at 7:57 AM, emre berat nebioğlu wrote:

> I just wonder someone This is possible.Thats it :D
>
> On Fri, Jun 12, 2009 at 2:37 PM, Matthias Felleisen  
> <matthias at ccs.neu.edu> wrote:
>
> Why would you want to use while in Scheme? You might as well use  
> Java then :-)
>
>
>
>
> On Jun 12, 2009, at 7:21 AM, emre berat nebioğlu wrote:
>
>> Can we use while or do while in drscheme.Just i wonder.I mean that
>>
>> While(list != null)
>>      list=list.cdr
>>
>> On Fri, Jun 12, 2009 at 9:10 AM, Noel Welsh <noelwelsh at gmail.com>  
>> wrote:
>> On Fri, Jun 12, 2009 at 7:05 AM,  
>> Captain___nemo<mmrasheed at gmail.com> wrote:
>> > Thanks a lot :)
>> >
>> > Won't it be inefficient building list for large values (say  
>> thousands
>> > instead of 10)? Isn't there any direct loop syntax in Scheme?
>>
>> In PLT there are for comprehensions:
>>
>> (for ([i (in-range 10)]) ...)
>>
>> However, it is almost always bad style to use loops like you would in
>> Java. Functional programmers think of expressions creating values,
>> whereas Java's loops are fundamentally imperative. So rather than a
>> for comprehension, I would expect someone to use for/list or another
>> value returning comprehension.
>>
>> N.
>> _________________________________________________
>>  For list-related administrative tasks:
>>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>
>> _________________________________________________
>>   For list-related administrative tasks:
>>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090612/34f8eeda/attachment.html>

Posted on the users mailing list.