Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You would if you could but you can't so you won't.


comp / comp.lang.lisp / Re: new to lisp, need help.

SubjectAuthor
o Re: new to lisp, need help.B. Pym

1
Subject: Re: new to lisp, need help.
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sat, 15 Jun 2024 20:55 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: new to lisp, need help.
Date: Sat, 15 Jun 2024 20:55:57 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <v4kv4s$3kq0q$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sat, 15 Jun 2024 22:55:58 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7c6202153264b9e7ab99088707c90cc4";
logging-data="3827738"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19KKjD5LfJvBdWDdK25uQ+T"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:szHnGXCu98n99eORdzkmM+t3BSo=
View all headers

Kaz Kylheku wrote:

> On 2012-09-17, mchukhlib@gmail.com <mchukhlib@gmail.com> wrote:
> > Assumptions:
> > You can assume the following:
> > 1. AND is the only word that can create compound sentences.
> > 2. Any time that AND is used it is a compound sentence.
> > 3. A compound sentence can only have 1 AND in it.
> >
> > Sample Output:
> > Here is sample output for the function.
> > Break 10 [14]> (BREAK_COMP '(I like you))
> > ((I LIKE YOU))
> > Break 10 [14]> (BREAK_COMP '(I like you and you like me))
> > ((I LIKE YOU) (YOU LIKE ME))
>
> (defun break-comp (list)
> (let* ((and-clause (member 'and list))
> (main-clause (ldiff list and-clause)))
> `(,main-clause ,@(if and-clause `(,(cdr and-clause))))))
>
>
> Uncool version, without backquote notation:
>
> (defun break-comp (list)
> (let* ((and-clause (member 'and list))
> (main-clause (ldiff list and-clause)))
> (if and-clause
> (list main-clause and-clause)
> (list main-clause))))

The "uncool" version is incorrect; it fails to remove
the "and":

* (BREAK-COMP '(I like you and you like me))

((I LIKE YOU) (AND YOU LIKE ME))

Gauche Scheme

(use srfi-1) ;; break

(define (break-comp sentence)
(receive (a b)
(break (lambda(x) (eqv? x 'and)) sentence)
(if (null? b)
`(,a)
`(,a ,(cdr b)))))

(break-comp '(foo bar))
===>
((foo bar))

(break-comp '(be here and go hence))
===>
((be here) (go hence))

1

rocksolid light 0.9.8
clearnet tor