# Thread: Confusion with lambda function

1. ## Confusion with lambda function

Registered forum members do not see this ad.

Hi Guys

How to Create Line for coordinates from list using lambda function
Please need help for solve this

Code:
```(defun c:test(/ lst )
(setq lst '((1515.32 999.613 0.0) (2314.23 1081.97 0.0) (1690.57 752.536 0.0)
(2458.55 829.747 0.0) (1685.41 474.574 0.0) (2716.26 443.689 0.0))
)
(mapcar (function (lambda (x y)
(command "line" x y "") ????
))
lst
)
)```

2. Code:
```(mapcar
'(lambda (x y) (entmakex (list (cons 0 "LINE") (cons 10 x) (cons 11 y))))
lst
(append (cdr lst) (list (last lst)))
)```
Or:
Code:
```(mapcar
'(lambda (x) (entmakex (list (cons 0 "LINE") (cons 10 (car x)) (cons 11 (cadr x)))))
(mapcar 'list lst (append (cdr lst) (list (last lst))))
)```

EDIT: Or if you use LM's entmake functions, then you could just
Code:
```(defun LWPoly (lst cls) ; LM
(entmakex
(append
(list
(cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity")
(cons 100 "AcDbPolyline") (cons 90 (length lst)) (cons 70 cls)
)
(mapcar (function (lambda (p) (cons 10 p))) lst)
)
)
)```
do this:
Code:
`(LWPoly lst 0)`

3. Grrr

That was awesome and i don't want to create only 3 Line Entity's for example '(1 1) '(2 2) '(3 3) Please waiting for your reply

example.jpg

4. Originally Posted by gS7
Grrr

That was awesome and i don't want to create only 3 Line Entity's for example '(1 1) '(2 2) '(3 3) Please waiting for your reply
If you want to create lines from a point list, you have to group the items so each one consists of 2 points (a line is defined of 2 points) :
Instead of such list
Code:
`'(1 1) '(2 2) '(3 3)`
you'll have to use:
Code:
```(list
'((1 1) (2 2)) ; line #1
'((2 2) (3 3)) ; line #2
'((3 3) (1 1)) ; line #3 (if you want to close the shape)
)```

5. Registered forum members do not see this ad.

Originally Posted by Grrr
If you want to create lines from a point list, you have to group the items so each one consists of 2 points (a line is defined of 2 points) :
Instead of such list
Code:
`'(1 1) '(2 2) '(3 3)`
you'll have to use:
Code:
```(list
'((1 1) (2 2)) ; line #1
'((2 2) (3 3)) ; line #2
'((3 3) (1 1)) ; line #3 (if you want to close the shape)
)```

Grrr thank you It is helped me lot

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts