• Re: new to lisp, need help.

    From B. Pym@21:1/5 to Kaz Kylheku on Sat Jun 15 20:55:57 2024
    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))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)