Re: Differences in mapping functions
Hi Srini, > Another difference is that the mapcon and mapcan functions must supply > a function that returns a list, while the others can supply a function > that returns an atom? Not exactly. 'mapcon' and 'mapcan' can return any s-expression. These results are then concatenated just as 'conc' does, and they may well be atoms (most importantly, they can be NIL). This corresponds to : (conc (1) 2 (3 4) 5 (6)) -> (1 3 4 6) while 'maplist' and 'mapcar' build a list from the results, just as 'list' does: : (list (1) 2 (3 4) 5 (6)) -> ((1) 2 (3 4) 5 (6)) ♪♫ Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: Differences in mapping functions
Hi Alex The diagram you produced makes a very nice and succinct reference... Whole list Only CAR --+-+--- No result | map | mapc | | append | maplist | mapcar | | concat | mapcon | mapcan Thanks again Srini - Original Message - > From: Thorsten Jolitz > To: picolisp@software-lab.de > Sent: Monday, July 28, 2014 4:03:59 PM >> Alexander Burger writes: >>> I am often confused between the variants of the map functions: map, >>> mapc, mapcar, mapcan, mapcon, maplist. >> Yes, indeed. The names of these 6 functions are historic, they are in >> most Lisp variants since early on. [...] >> I hope this clears things up a little. > Thanks for this nice and short explanation, I'm sure I will use this > post as a reference in the future. [Srini] Yes, for me also... > -- > cheers, > Thorsten -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: Differences in mapping functions
I agree. I'm constantly reading the reference of any lisp when dealing with maps, and their descriptions are usually vague. When prototyping I always ignore mapcon and mapcan because I always forget their difference (and because of their destructive nature, which isn't considered functional). El jul 28, 2014 1:11 PM, "Thorsten Jolitz" escribió: > Alexander Burger writes: > > Hi Alex, > > >> I am often confused between the variants of the map functions: map, > >> mapc, mapcar, mapcan, mapcon, maplist. > > > > Yes, indeed. The names of these 6 functions are historic, they are in > > most Lisp variants since early on. > > [...] > > > I hope this clears things up a little. > > Thanks for this nice and short explanation, I'm sure I will use this > post as a reference in the future. > > I would even say that it would make a perfect wiki article! > > , > | Mapping functions in PicoLisp > ` > > or so > > -- > cheers, > Thorsten > > -- > UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe >
Re: Differences in mapping functions
Alexander Burger writes: Hi Alex, >> I am often confused between the variants of the map functions: map, >> mapc, mapcar, mapcan, mapcon, maplist. > > Yes, indeed. The names of these 6 functions are historic, they are in > most Lisp variants since early on. [...] > I hope this clears things up a little. Thanks for this nice and short explanation, I'm sure I will use this post as a reference in the future. I would even say that it would make a perfect wiki article! , | Mapping functions in PicoLisp ` or so -- cheers, Thorsten -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: Differences in mapping functions
Hi Alex Thanks for your prompt reply...I am adding my replies inline.. Srini > From: Alexander Burger > To: picolisp@software-lab.de > Sent: Monday, July 28, 2014 1:50:28 PM > Subject: Re: Differences in mapping functions ... > > I am often confused between the variants of the map functions: map, > > mapc, mapcar, mapcan, mapcon, maplist. > Yes, indeed. The names of these 6 functions are historic, they are in > most Lisp variants since early on. Thanks, this was good to know, as I was then able to find some Lisp sites with additional documentation/examples on these functions. ... > In general, all functions in the "Only CAR" column above can be replaced > by the "Whole list" functions if the argument function takes car of > applying 'car' to the argument list. Another difference is that the mapcon and mapcan functions must supply a function that returns a list, while the others can supply a function that returns an atom? > I hope this clears things up a little. Yes, thanks again.. > ♪♫ Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: Differences in mapping functions
Hi Srini, > I am often confused between the variants of the map functions: map, > mapc, mapcar, mapcan, mapcon, maplist. Yes, indeed. The names of these 6 functions are historic, they are in most Lisp variants since early on. > Is there a short one-line synposis/organization of these functions > with the key words, and/or a mnemonic that you may use to remember the > differences? There is a kind of systematic pattern. All 6 functions take an argument funtion and one or several lists. But they differ in whether they 1. pass the whole (rest)list to the function, or only the CAR. 2. build a result list or not (i.e. whether they return something useful or are just for the side-effects). 3. build the result list destructively (using the equivalent of 'con' or 'conc') or non-destructively (using 'cons' or 'append'). Wole list Only CAR --+-+--- No result | map |mapc | | append|maplist | mapcar | | concat|mapcon | mapcan The logic of the naming might be (my interpretation): * The "c" in 'mapc' means "CAR", as does the "car" in 'mapcar' * 'maplist' passes the whole list, while 'mapcar' takes the CAR * The "con" in 'mapcon' means "concat" while the "can" in 'mapcan' replaces the "o" with an "a" from "CAR". Note that you can implement ALL these 6 functions using 'mapcon'. So 'mapcon' is the mother of all mapping functions (as also of 'find', 'filter' and so on). For example, instead of : (mapcar inc (1 2 3)) -> (2 3 4) you could as well write : (mapcon '((L) (cons (inc (car L (1 2 3)) -> (2 3 4) or instead of : (mapc println (1 2 3)) 1 2 3 you could write : (mapcon '((L) (println (car L)) NIL) (1 2 3)) 1 2 3 and so on. In general, all functions in the "Only CAR" column above can be replaced by the "Whole list" functions if the argument function takes car of applying 'car' to the argument list. I hope this clears things up a little. ♪♫ Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe