Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

This was the most unkindest cut of all. -- William Shakespeare, "Julius Caesar"


comp / comp.lang.scheme / Re: Loopiness

SubjectAuthor
* LoopinessB. Pym
`- Re: LoopinessKaz Kylheku

1
Subject: Loopiness
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Thu, 26 Sep 2024 21:13 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Loopiness
Date: Thu, 26 Sep 2024 21:13:00 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <vd4ior$cfmj$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Thu, 26 Sep 2024 23:13:00 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="6e77691426056b075e20adf4ee6093ea";
logging-data="409299"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18XBbHKa+VfDrWnlvnRUzOh"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:M1EvYS0aVnM839txn1LcmPSp/0o=
View all headers

> (loop for x in things
> when (foo-p x) collect x into foos
> when (bar-p x) collect x into bars
> when (and (foo-p x) (bar-p x)) collect x into both
> finally (return (values foos bars both)))

It's shorter in Gauche Scheme.

(define things '(0 3 -5 4 9 -7 6 8))

(let@ (() odds posi both)
(dolist (x things)
(when (odd? x) (push! odds x))
(when (positive? x) (push! posi x)
(when (odd? x) (push! both x))))
(values odds posi both))

(-7 9 -5 3)
(8 6 9 4 3)
(9 3)

Given:

(define-macro let@
(lambda (lets . exprs)
(let ((lets lets)
(let-pairs '()))
(if (list? lets)
(while (pair? lets)
(let ((x (pop! lets)))
(cond
((not (symbol? x))
(while (pair? lets)
(push! let-pairs (list (pop! lets) x))))
((null? lets) (push! let-pairs (list x 0)))
(#t (push! let-pairs (list x (pop! lets)))))))
(set! let-pairs `((,lets 0))))
`(let* ,(reverse let-pairs)
,@exprs))))

Subject: Re: Loopiness
From: Kaz Kylheku
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Fri, 27 Sep 2024 01:13 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 643-408-1753@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: Loopiness
Date: Fri, 27 Sep 2024 01:13:00 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <20240926180921.249@kylheku.com>
References: <vd4ior$cfmj$1@dont-email.me>
Injection-Date: Fri, 27 Sep 2024 03:13:01 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="785518da76bda1deaa0450891ef936b3";
logging-data="470011"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ctlCdABjLPwW4k40CplxqW+vGMhtjPss="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:veZEo/C+tJu2PLQYVIfm3uwI+Jc=
View all headers

On 2024-09-26, B. Pym <Nobody447095@here-nor-there.org> wrote:
>> (loop for x in things
>> when (foo-p x) collect x into foos
>> when (bar-p x) collect x into bars
>> when (and (foo-p x) (bar-p x)) collect x into both
>> finally (return (values foos bars both)))
>
> It's shorter in Gauche Scheme.

It's five physical nonblank lines of code.

>
> (define things '(0 3 -5 4 9 -7 6 8))
>
> 1: (let@ (() odds posi both)
> 2: (dolist (x things)
> 3: (when (odd? x) (push! odds x))
> 4: (when (positive? x) (push! posi x)
> 5: (when (odd? x) (push! both x))))
> 6: (values odds posi both))
>
> (-7 9 -5 3)
> (8 6 9 4 3)
> (9 3)
>
> Given:
>
> 7: (define-macro let@
> 8: (lambda (lets . exprs)
> 9: (let ((lets lets)
> 10: (let-pairs '()))
> 11: (if (list? lets)
> 12: (while (pair? lets)
> 13: (let ((x (pop! lets)))
> 14: (cond
> 15: ((not (symbol? x))
> 16: (while (pair? lets)
> 17: (push! let-pairs (list (pop! lets) x))))
> 18: ((null? lets) (push! let-pairs (list x 0)))
> 19: (#t (push! let-pairs (list x (pop! lets)))))))
> 20: (set! let-pairs `((,lets 0))))
> 21: `(let* ,(reverse let-pairs)
> 22: ,@exprs))))

How is twenty-two nonblank lines shorter than five?

You are clearly not well.

1

rocksolid light 0.9.8
clearnet tor