[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4762: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4764: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4765: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4766: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
newlispfanclub.alh.net • View topic - strange result with map and apply

strange result with map and apply

Q&A's, tips, howto's

strange result with map and apply

Postby fdb » Sat Apr 26, 2014 9:57 pm

fdb
 
Posts: 49
Joined: Sat Nov 09, 2013 8:49 pm

Re: strange result with map and apply

Postby bairui » Sat Apr 26, 2014 11:13 pm

bairui
 
Posts: 64
Joined: Sun May 06, 2012 2:04 am
Location: China

Re: strange result with map and apply

Postby Lutz » Sun Apr 27, 2014 1:47 pm

Like in Scneme (+) or (apply +) evaluates to 0. So your map expression maps 0 onto two lists.
Using a number as operator is implicit resting. 0 gives you back the whole list.
Try also (map (apply *) '((0 1 2) (3 4 5))) to prove the point. Like in Scheme (*) gives 1.

So using curry for what you want is the right thing.
Lutz
 
Posts: 5279
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Re: strange result with map and apply

Postby bairui » Mon Apr 28, 2014 1:19 am

Ah, that makes sense. Thanks, Lutz.
bairui
 
Posts: 64
Joined: Sun May 06, 2012 2:04 am
Location: China

Re: strange result with map and apply

Postby fdb » Mon Apr 28, 2014 9:49 pm

fdb
 
Posts: 49
Joined: Sat Nov 09, 2013 8:49 pm

Re: strange result with map and apply

Postby cormullion » Tue Apr 29, 2014 11:04 am

cormullion
 
Posts: 2037
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W

Re: strange result with map and apply

Postby bairui » Tue Apr 29, 2014 12:54 pm

bairui
 
Posts: 64
Joined: Sun May 06, 2012 2:04 am
Location: China

Re: strange result with map and apply

Postby fdb » Tue Apr 29, 2014 7:19 pm

Thx!

I understood the function from bairui directly (why didn't i think of that..) but i had to look in the documentation to understand cormullion's solution and then i saw in the documentation this example:
(set-ref-all '(oranges *) data (list (first $it) (apply + (rest $it))) match) ....

Great docs, just have to read them more carefully next time.
fdb
 
Posts: 49
Joined: Sat Nov 09, 2013 8:49 pm


Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 1 guest

cron