help me, pls 
Author Message
 help me, pls

Please help a lisp newbie.
I am trying to do the following
(setq my-list '( a b c))
then a becomes (a1 a2)
and b becomes (b1 b2)
then, my-list should look like
((a1 b1 c) (a1 b2 c) (a2 b1 c) (a2 b2 c))
Please show me how to do it in lisp.
Thanks a million!!!!
jason


Mon, 22 Apr 2002 03:00:00 GMT  
 help me, pls

Quote:

> Please help a lisp newbie.
> I am trying to do the following
> (setq my-list '( a b c))
> then a becomes (a1 a2)
> and b becomes (b1 b2)
> then, my-list should look like
> ((a1 b1 c) (a1 b2 c) (a2 b1 c) (a2 b2 c))
> Please show me how to do it in lisp.

(setq a '(a1 a2))
(setq b '(b1 b2))
(setq my-list '((a1 b1 c) (a1 b2 c) (a2 b1 c) (a2 b2 c)))
Kidding of course.

Could you formulate your problem in other way? What are you trying to
do? Is it something about matrixes?
The description above is not terribly self-explanatory.

--
  Eugene



Mon, 22 Apr 2002 03:00:00 GMT  
 help me, pls
:-(
thanks.
Sorry for the ambiguity of my first post.
Here is what I am trying to do.

There is a list with arbitrary length, which looks like (A B C D)
Then, any element in the list could turn into a list with no more than
two elements in it, e.g, "A" could take a the form like (a1 a2) or A1.
 Given the new values of A B C and D, the list should look like something
like this:
((a1 B c1  D1)
 (a1 B c2 D1)
 (a2 B c1 D1)
 (a2 B c2 D1)).
here is function  I am working on::
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun make-new-lists (old-list, update-values)
;old-list is just like (A B C D) i said above
;update -values is like ((a1 a2) B (c1 c2) (D1) )
;( want to end up with a list like ((a1 B c1  D1) (a1 B c2 D1) (a2 B c1
D1) (a2 B c2 D1)), yes, a matrix.
    (let ((result-list nil))
       ;;;I wrote some codes here, which does not make sense even to
myself

result-list))
;;;;;;;;;;;;;;;;;;;;;;;;;
Would you pls show me how to do it?
I really needs your help.
Thank you very very much.

Quote:

> (setq a '(a1 a2))
> (setq b '(b1 b2))
> (setq my-list '((a1 b1 c) (a1 b2 c) (a2 b1 c) (a2 b2 c)))
> Kidding of course.

> Could you formulate your problem in other way? What are you trying to
> do? Is it something about matrixes?
> The description above is not terribly self-explanatory.

> --
>   Eugene




Mon, 22 Apr 2002 03:00:00 GMT  
 help me, pls

Hmm, this is a very vague problem spec.. could you try to state it more
conciesly? I'm sure you'll get more meaningful help that way.

Also: Have you thouhg of using mapcar, or mapcan? I'm sure you could use
this with a lambda to achieve your desired results.

Quote:

> Please help a lisp newbie.
> I am trying to do the following
> (setq my-list '( a b c))
> then a becomes (a1 a2)
> and b becomes (b1 b2)
> then, my-list should look like
> ((a1 b1 c) (a1 b2 c) (a2 b1 c) (a2 b2 c))
> Please show me how to do it in lisp.
> Thanks a million!!!!
> jason

  jgard.vcf
< 1K Download


Mon, 22 Apr 2002 03:00:00 GMT  
 help me, pls

Quote:

>There is a list with arbitrary length, which looks like (A B C D)
>Then, any element in the list could turn into a list with no more than
>two elements in it, e.g, "A" could take a the form like (a1 a2) or A1.
> Given the new values of A B C and D, the list should look like something
>like this:
>((a1 B c1  D1)

If line above is first element of original list (A B C D)  i.e. element A,
then why it contains of 4 subelements ?  Then, why do you use
capital and lowercase letters, maybe it means that a1 is a
'terminal' element, when B is a list ?
Quote:
> (a1 B c2 D1)
> (a2 B c1 D1)
> (a2 B c2 D1)).



Tue, 23 Apr 2002 03:00:00 GMT  
 help me, pls


[snip]

Quote:
> here is function  I am working on::
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (defun make-new-lists (old-list, update-values)
> ;old-list is just like (A B C D) i said above
> ;update -values is like ((a1 a2) B (c1 c2) (D1) )
> ;( want to end up with a list like ((a1 B c1  D1) (a1 B c2 D1) (a2 B c1
> D1) (a2 B c2 D1)), yes, a matrix.
>     (let ((result-list nil))
>        ;;;I wrote some codes here, which does not make sense even to
> myself

Wait, wait. Are you sure that B in update-values should be atomic? Why do
you need old-list? It has no relation with result-list, except it is also a
four-element list and it has atom B.
Ok, here is my cut, though it doesn't works with atomic list entries.
Massaging input properly should be easy. I didn't meditated over a recursive
solution that wouldn't (to . hell).

(defun make-new-lists (l)
  (destructuring-bind (sub1 sub2 sub3 sub4 &optional (result nil))
      l
    (loop for a1 in sub1
          do (loop for a2 in sub2
                   do (loop for a3 in sub3
                            do (loop for a4 in sub4
                                     do
                                     (setf result (cons (list a1 a2 a3 a4)
result))))))
    (nreverse result)))

CL-USER 3 > (make-new-lists '((a1 a2) (b) (c1 c2) (d1)))
((A1 B C1 D1) (A1 B C2 D1) (A2 B C1 D1) (A2 B C2 D1))

--
  Eugene



Tue, 23 Apr 2002 03:00:00 GMT  
 help me, pls

Quote:
> Please help a lisp newbie.
> I am trying to do the following
> (setq my-list '( a b c))
> then a becomes (a1 a2)
> and b becomes (b1 b2)
> then, my-list should look like
> ((a1 b1 c) (a1 b2 c) (a2 b1 c) (a2 b2 c))
> Please show me how to do it in lisp.

Something like this?

---
(defun msubstitute (list &rest subs)
  (apply 'msubs-aux (list list) subs))

(defun msubs-aux (lists &rest subs)
  (if subs
    (let (newlists)
      (dolist (list lists (apply 'msubs-aux newlists (cdr subs)))
        (setf newlists
              (append newlists
                      (mapcar #'(lambda (r)
                                  (substitute r (caar subs) list))
                              (cadar subs))))))
    lists))
---

A



Tue, 23 Apr 2002 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Help me pls

2. toggle-checker, help me pls

3. Help me pls

4. HELP ME PLS (VRML LINK PROBLEM)

5. Help me pls...

6. TypeError interp, help wanted pls

7. Porolog help needed, pls.

8. Newbie assembler language question,pls help.

9. Newbie assembler language question,pls help.

10. still have syntax error in line 14, pls help

11. newbie help pls

12. PB for Dos Question pls help

 

 
Powered by phpBB® Forum Software