Author Topic: Deconstructing Lists  (Read 5029 times)

0 Members and 1 Guest are viewing this topic.

whdjr

  • Guest
Deconstructing Lists
« on: June 08, 2005, 05:06:31 PM »
Is there a lisp command that will turn this
Code: [Select]
;;;One single list
((1 2 3)(4 5 6))
into this
Code: [Select]
;;;Two seperate lists
(1 2 3)(4 5 6)
or do you just have to use car and cadr?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Deconstructing Lists
« Reply #1 on: June 08, 2005, 05:19:28 PM »
Not sure what you may be trying to do with the discombobulation Will, but I can not think of an easier way than car, cadr.
What is the construct you are using this in ? .. It seems unusual to have 2 consecutive lists without a container .
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

whdjr

  • Guest
Deconstructing Lists
« Reply #2 on: June 08, 2005, 05:51:34 PM »
I have a mapcar that returns two lists of strings.  I have another piece of code that returns the common strings from the two lists.  This code takes two arguments, the two lists.  I could change the code to accept a list, but I didn't want to have to change it as I use it for other functions as well.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Deconstructing Lists
« Reply #3 on: June 08, 2005, 06:03:27 PM »
Sample data and desired output please.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Deconstructing Lists
« Reply #4 on: June 09, 2005, 08:45:51 AM »
I would also like to see some example data; I have a few string and list functions that, maybe, could be of use.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Deconstructing Lists
« Reply #5 on: June 09, 2005, 09:07:28 AM »
You could create an intermediate routine to split like this
Code: [Select]
(defun split (fun arg)
  (if (= (length arg) 2)
    (fun (car arg) (cadr arg)) ; **  see note
    (prompt "\n**  Error in data - expected list of two items")
  )
)

**  This will not work but I forgot how to make a variable act as a function.
Use EVAL I think?? Never used it but I did see it somewhere.

The call would be
Code: [Select]
(split myroutine_name '((1 2 3)(4 5 6)) )

But how hard is it to use
Code: [Select]
(myroutine_name (car ((1 2 3)(4 5 6))) ((cadr ((1 2 3)(4 5 6)))) )
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

SMadsen

  • Guest
Deconstructing Lists
« Reply #6 on: June 09, 2005, 09:10:18 AM »
APPLY with the original list?

(apply 'another_function theList)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Deconstructing Lists
« Reply #7 on: June 09, 2005, 09:57:55 AM »
Thanks Stig, good to see ya.

I guess my idea would not work then as you must pass both items as two arguments to satisfy the subroutine "MyRoutine arg1 arg2".
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

whdjr

  • Guest
Deconstructing Lists
« Reply #8 on: June 09, 2005, 10:00:35 AM »
I prompt the user for a

Source Directory --> d:\test    
   
and a

Target Directory  --> d:\test 2

Then it returns all the folders in those two paths which I then remove the source and target folders from the paths:

Code: [Select]
(("\\test a" "\\test a\\test a1" "\\test a\\test a2" "\\test a\\test a3" "\\test c" "\\test c\\test c1")
 ("\\test a" "\\test a\\test a1" "\\test a\\test a2" "\\test b" "\\test b\\test b1" "\\test b\\test b2")
)

Then I will pass this list to another function to return only similar paths:
Code: [Select]
(defun Return_Same_Items (lst1 lst2)
  (vl-remove-if-not '(lambda (x) (member x lst2)) lst1)
)

This function however accepts two lists instead of one list.  I would rather not change this function because I use in other programs.

My delimma is how to get this
Code: [Select]
(("\\test a" "\\test a\\test a1" "\\test a\\test a2" "\\test a\\test a3" "\\test c" "\\test c\\test c1")
 ("\\test a" "\\test a\\test a1" "\\test a\\test a2" "\\test b" "\\test b\\test b1" "\\test b\\test b2")
)
into this
Code: [Select]
("\\test a" "\\test a\\test a1" "\\test a\\test a2" "\\test a\\test a3" "\\test c" "\\test c\\test c1")
("\\test a" "\\test a\\test a1" "\\test a\\test a2" "\\test b" "\\test b\\test b1" "\\test b\\test b2")
Comprende? :)

whdjr

  • Guest
Deconstructing Lists
« Reply #9 on: June 09, 2005, 10:03:45 AM »
I wish I would have tried your post before I wrote my post Stig.  Thanks man that was the ticket. :lol:

Stig  --> 8)  and :loneranger:

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Deconstructing Lists
« Reply #10 on: June 09, 2005, 10:06:36 AM »
I must be missing something because it seems no more ambitious than using car and cadr, ie --

(Return_Same_Items (car lst) (cadr lst))

Where lst equals --

Code: [Select]
(  ("\\test a" "\\test a\\test a1" "\\test a\\test a2" "\\test a\\test a3" "\\test c" "\\test c\\test c1")
   ("\\test a" "\\test a\\test a1" "\\test a\\test a2" "\\test b" "\\test b\\test b1" "\\test b\\test b2")
)

?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

whdjr

  • Guest
Deconstructing Lists
« Reply #11 on: June 09, 2005, 10:13:02 AM »
That does work MP, its just that I use that routine for other progs as well and I didn't want to change for just this one.  That was all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Deconstructing Lists
« Reply #12 on: June 09, 2005, 10:18:33 AM »
Sorry, I'm pretty thick this morning, I still don't get it. What is it your changing or not changing? :oops:
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Deconstructing Lists
« Reply #13 on: June 09, 2005, 10:26:11 AM »
Ok, I get it, you want to go this route --

(apply 'Return_Same_Items lst)

Rather than

(Return_Same_Items (car lst) (cadr lst))

Okidoki.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

whdjr

  • Guest
Deconstructing Lists
« Reply #14 on: June 09, 2005, 10:29:54 AM »
:D