Re: new to lisp, need help.

Liste des GroupesRevenir à cl lisp 
Sujet : Re: new to lisp, need help.
De : No_spamming (at) *nospam* noWhere_7073.org (B. Pym)
Groupes : comp.lang.lisp
Date : 15. Jun 2024, 22:55:57
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v4kv4s$3kq0q$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
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))

Date Sujet#  Auteur
15 Jun 24 o Re: new to lisp, need help.1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal