Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #33: piezo-electric interference


comp / comp.lang.lisp / Re: Ex. 3.5 in ACL

SubjectAuthor
o Re: Ex. 3.5 in ACLB. Pym

1
Subject: Re: Ex. 3.5 in ACL
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Fri, 13 Sep 2024 21:07 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: Re: Ex. 3.5 in ACL
Date: Fri, 13 Sep 2024 21:07:41 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <vc29ip$11q31$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Fri, 13 Sep 2024 23:07:41 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="b23a757b35dd03cbd4947edb1cfbe6d8";
logging-data="1108065"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19eWREoA+f3ysw3jpFEJ3vV"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:NxeRK1bt1WmMnC/TtPcghfmVsUc=
View all headers

Zachary Beane wrote:

> (defun mapcar-pos+ (list)
> (let ((i -1))
> (mapcar #'(lambda (elt) (+ elt (incf i)))

Truly abysmal ignorance or willful stupidity.

The #' is redundant.

>
> > iteration:
> >
> > (defun pos+ (lst)
> > (setf acc NIL)
> > (setf i 0)
> > (dolist (obj lst)
> > ; i know, instead of append, i could do a cons and reverse afterwards...
> > (progn (setf acc (append acc (list (+ obj i))))
> > (setf i (+ i 1))))
> > acc)
>
> I'd prefer LOOP here:
>
> (defun loop-pos+ (list)
> (loop for i from 0
> for elt in list
> collect (+ elt i)))

Gauche Scheme:

(define (pos+ input)
(@ (i -1) map x : (+ x (++ i)) input))

(pos+ '(900 800 700 600 500))
===>
(900 801 702 603 504)

Given:

(define ++ inc!)

(define-syntax @-aux
(syntax-rules (:)
[(_ () goodlets func (vars ...) : expr lst ...)
(let* goodlets (func (lambda (vars ...) expr) lst ...))]
[(_ () goodlets func (vars ...) var more ...)
(@-aux () goodlets func (vars ... var) more ...)]
[(_ (var val more ...) (goodlets ...) stuff ...)
(@-aux (more ...) (goodlets ... (var val)) stuff ...)]))

(define-syntax @
(syntax-rules ()
[(_ (lets ...) func stuff ...)
(@-aux (lets ...) () func () stuff ...)]
[(_ func stuff ...)
(@ () func stuff ...)]))

1

rocksolid light 0.9.8
clearnet tor