[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Named let*
From: |
Michele La Monaca |
Subject: |
Re: [Chicken-users] Named let* |
Date: |
Wed, 29 May 2013 23:22:48 +0200 |
On Wed, May 29, 2013 at 11:10 PM, Michele La Monaca
<address@hidden> wrote:
> On Wed, May 29, 2013 at 10:20 PM, Patrick Li <address@hidden> wrote:
>> Hi Michele,
>>
>> I realized after posting my version of named-let*, that you actually
>> *cannot* use it to accomplish all of what you want. For that you do need
>> loop to be a syntactic extension, as mentioned by Jorg.
>>
>> For instance, my named-let* macro would not simplify the example you posted
>> earlier:
>>
>> (let loop ((i (some-function)) (ch (string-ref buf (some-function))))
>> (do-something)
>> (if (some-condition-is-true)
>> (loop (+ i 1)
>> (string-ref buf (+ i 1)))))
>>
>> The key issue underlying this is, when you call (loop), would you like to
>> call it with one or two arguments?
>>
>
> Two. Your macro seems good to me. For example, let's say I want to
> print a string starting from a random position:
>
> (define buf "foobar")
>
> (named-let* loop ((i (random (string-length buf))) (ch (string-ref buf i)))
> (display ch)
> (if (< (+ i 1) (string-length buf))
> (loop (+ i 1) (string-ref buf (+ i 1)))))
>
>
> or even better:
>
> (named-let* loop ((len (string-length buf)) (i (random len)) (ch
> (string-ref buf i)))
> (display ch)
> (if (< (+ i 1) len)
> (loop len (+ i 1) (string-ref buf (+ i 1)))))
>
>
> Michele
Or even even better (or worse depending on your tastes):
(named-let* loop ((len (string-length buf)) (i (random len)) (j (+ 1
i)) (ch (string-ref buf i)))
(display ch)
(if (< j len)
(loop len j (+ j 1) (string-ref buf j))))
:-)
- Re: [Chicken-users] Named let*, (continued)
- Re: [Chicken-users] Named let*, Peter Bex, 2013/05/24
- Re: [Chicken-users] Named let*, Michele La Monaca, 2013/05/27
- Re: [Chicken-users] Named let*, Jörg F . Wittenberger, 2013/05/29
- Re: [Chicken-users] Named let*, Patrick Li, 2013/05/29
- Re: [Chicken-users] Named let*, Michele La Monaca, 2013/05/29
- Re: [Chicken-users] Named let*, Patrick Li, 2013/05/29
- Re: [Chicken-users] Named let*, Jim Ursetto, 2013/05/29
- Re: [Chicken-users] Named let*, Michele La Monaca, 2013/05/29
- Re: [Chicken-users] Named let*,
Michele La Monaca <=
- Re: [Chicken-users] Named let*, Michele La Monaca, 2013/05/30
- Re: [Chicken-users] Named let*, Michele La Monaca, 2013/05/29