Apply error message

Q&A's, tips, howto's

Apply error message

Postby cameyo » Sat Nov 17, 2018 3:03 pm

The following expression give me an error:
Code: Select all
(apply map list '((a 1) (b 2) (c 3)))

ERR: list expected in function apply : list@4095B0

Instead, I wish the output was:
((a b c) (1 2 3))

Can someone help me?
Thanks

cameyo
cameyo
 
Posts: 15
Joined: Sun Mar 27, 2011 3:07 pm

Re: Apply error message

Postby Lutz » Sat Nov 17, 2018 6:00 pm

Use transpose:

Code: Select all
> (transpose '((a 1) (b 2) (c 3)))
((a b c) (1 2 3))
>


A hint will be added to the description of list in the manual.
Lutz
 
Posts: 5258
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Re: Apply error message

Postby cameyo » Sat Nov 17, 2018 8:05 pm

"transpose" works like i want :-)
But is the expression wrong logically or syntactically?
Why "apply" does not receive a list?
Thanks again

cameyo
cameyo
 
Posts: 15
Joined: Sun Mar 27, 2011 3:07 pm

Re: Apply error message

Postby rickyboy » Sat Nov 17, 2018 11:58 pm

cameyo wrote:But is the expression wrong logically or syntactically?
Why "apply" does not receive a list?

This is what you had been looking for originally.

Code: Select all
(apply map (cons list '((a 1) (b 2) (c 3))))
(λx. x x) (λx. x x)
rickyboy
 
Posts: 554
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Re: Apply error message

Postby cameyo » Sun Nov 18, 2018 10:58 am

Thanks.
A big help for me.

cameyo
cameyo
 
Posts: 15
Joined: Sun Mar 27, 2011 3:07 pm


Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 2 guests