Mapping with two arguments

Started by Fritz, October 13, 2009, 06:51:40 AM

Previous topic - Next topic

Fritz

Is it possible to give some argument to a map function? The method below want not work:



(define (add-tail tl str)
  (append str tl))

(map (add-tail "-Schwanz") '("Hund" "Katze" "Pinguin"))


Now I do this so:



(map add-tail (dup "-Schwanz" 3 true) '("Hund" "Katze" "Pinguin"))


But I have a feeling there should be a simpler way.

Jeff

#1
You need to pass map a function. You can do that with curry:


(map (curry add-tail (dup "-Schwanz" 3 true)) '("Hund" "Katze" "Pinguin"))
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

Lutz

#2
Jeff meant to say this:


(map (curry add-tail "-Schwanz") '("Hund" "Katze" "Pinguin"))

Jeff

#3
Was he trying to append "-Schwanz" or "-Schwanz-Schwanz-Schwanz"?
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

Lutz

#4
one "Schwanz" (tail in German) should be enough for each animal :)

Jeff

#5
Le pido perdon. Hablo solamente ingles y espanol. Y lisp ;)
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

Fritz

#6
Thanx! Now it works.



Btw, Spanish is very useful for me to name functions. I can define something like "buscar", "cargar" or "destripar" and be sure, that these symbols are not protected.

newdep

#7
You can rename all function inside Newlisp ;-) I did once made a Dutch newlisp..

..Awfull ;-)
-- (define? (Cornflakes))