Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #286: Telecommunications is downgrading.


comp / comp.lang.scheme / Re: Confused about Scheme...???

SubjectAuthor
* Re: Confused about Scheme...???B. Pym
`- Re: Confused about Scheme...???B. Pym

1
Subject: Re: Confused about Scheme...???
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Tue, 6 Aug 2024 06:18 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: Confused about Scheme...???
Date: Tue, 6 Aug 2024 06:18:50 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <v8sf86$1f6im$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Tue, 06 Aug 2024 08:18:51 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="59d6c6aa30eb0502f9bfd8ce98c9d6f2";
logging-data="1546838"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/0QTV6zJZST9c8jkwbQSIF"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:TidOXieeIEK9sn/qUE5d7QwPhFc=
View all headers

> In short, 'reduce-list', is take a list of variable length, 'b',
> below and reduce it if the (caar ls) and (caadr ls) are equal...this
> is the first atom within the pair of consecutive sublists and if this
> is true contruct a list, (list (caar ls) (+ (cadar ls) (cadadr ls)))
> , and add second atom of the consective pairs. For example,
> (reduce-list b) ==> ((4 3) (3 7) (2 1) (1 2) (0 1)). I can get it to
> work for the first two terms without using recursion, produces (4 3),
> but when I implement recursion it barfs. Could some one tell me what
> I'm doing wrong because I know that I'm trying to do to much at once?
>
>
> -Conrad
>
>
> (define (reduce-list ls)
> (cond ((null? ls) ls)
> (else
> (cond ((null? (cadr ls)) ls)
> (else
> (cond ((eq? (caar ls) (caadr ls))
> (list (caar ls) (+ (cadar ls) (cadadr ls)))
> (reduce-list (cdr ls)))
> (else (list (car ls) (reduce-list (cdr ls)))))))))))
>
>
> (define b '((4 1) (4 2) (3 3) (3 4) (2 1) (1 2) (0 1)))
>
> (reduce-list b)

newLISP

(define b '((4 1) (4 2) (4 80) (3 3) (3 4) (2 6) (9 2) (9 5)))

(define (meld xs)
(local (K A B)
(if (null? xs)
'()
(let (u (unify '((K A) (K B)) (0 2 xs)))
(if u
(begin (bind u) (meld (cons (list K (+ A B)) (2 xs))))
(cons (first xs) (meld (rest xs))))))))

(meld b)

((4 83) (3 7) (2 6) (9 7))

Subject: Re: Confused about Scheme...???
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Tue, 6 Aug 2024 15:37 UTC
References: 1
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: Confused about Scheme...???
Date: Tue, 6 Aug 2024 15:37:40 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <v8tfvu$1lupu$1@dont-email.me>
References: <v8sf86$1f6im$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Tue, 06 Aug 2024 17:37:40 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="94b510cfdba61ab92451386f03b599b0";
logging-data="1768254"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18UppO2DgJ+9nd/LRCuEfCb"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:S0XEu/ctc66vLTrpPNh2F2F8c74=
View all headers

B. Pym wrote:

> > In short, 'reduce-list', is take a list of variable length, 'b',
> > below and reduce it if the (caar ls) and (caadr ls) are equal...this
> > is the first atom within the pair of consecutive sublists and if this
> > is true contruct a list, (list (caar ls) (+ (cadar ls) (cadadr ls)))
> > , and add second atom of the consective pairs. For example,
> > (reduce-list b) ==> ((4 3) (3 7) (2 1) (1 2) (0 1)). I can get it to
> > work for the first two terms without using recursion, produces (4 3),
> > but when I implement recursion it barfs. Could some one tell me what
> > I'm doing wrong because I know that I'm trying to do to much at once?
> >
> >
> > -Conrad
> >
> >
> > (define (reduce-list ls)
> > (cond ((null? ls) ls)
> > (else
> > (cond ((null? (cadr ls)) ls)
> > (else
> > (cond ((eq? (caar ls) (caadr ls))
> > (list (caar ls) (+ (cadar ls) (cadadr ls)))
> > (reduce-list (cdr ls)))
> > (else (list (car ls) (reduce-list (cdr ls)))))))))))
> >
> >
> > (define b '((4 1) (4 2) (3 3) (3 4) (2 1) (1 2) (0 1)))
> >
> > (reduce-list b)
>
> newLISP
>
> (define b '((4 1) (4 2) (4 80) (3 3) (3 4) (2 6) (9 2) (9 5)))
>
> (define (meld xs)
> (local (K A B)
> (if (null? xs)
> '()
> (let (u (unify '((K A) (K B)) (0 2 xs)))
> (if u
> (begin (bind u) (meld (cons (list K (+ A B)) (2 xs))))
> (cons (first xs) (meld (rest xs))))))))
>
> (meld b)
>
> ((4 83) (3 7) (2 6) (9 7))

Shorter:

(define (meld xs , K A B)
(if (null? xs)
'()
(if (unify '((K A) (K B)) (0 2 xs))
(begin (bind $it) (meld (cons (list K (+ A B)) (2 xs))))
(cons (first xs) (meld (rest xs))))))

1

rocksolid light 0.9.8
clearnet tor