This is something that's easy to trip up over if you're not fully converted to functional programming... :) Every function returns a value.
println returns a value.
println also has a useful side-effect - it prints stuff. But it returns a value too.
In the newLISP console, type this:
Code: Select all
>(set 'item "one")
"one"
> (println {<li><a href="/} item {">} item {</a></li>})
<li><a href="/one">one</a></li>
"</a></li>"
You'll see that, after the printing, the value returned by the
println expression is "</a></li>" - the last value produced. So although the output was what you wanted, the return value wasn't. And it's that return value that is collected up and stored by
map that you've stored in the list. Hence the collection of strings you've got in your hlist.
If you want the output to be printed and the same output to be returned as a value, you have to take steps to output and return the same string:
Code: Select all
(set 'hlist (map (fn (item) (println (string {<li><a href="/} item {">} item {</a></li>}))) lst))
The string function returns a value, which is printed by println and returned by println as the result of the anonymous function. So your result will be the strings in a list:
Code: Select all
("<li><a href=\"/one\">one</a></li>" "<li><a href=\"/two\">two</a></li>" "<li><a href=\"/three\">three</a></li>")