Mapping with two arguments

Q&A's, tips, howto's
Locked
Fritz
Posts: 66
Joined: Sun Sep 27, 2009 12:08 am
Location: Russia

Mapping with two arguments

Post by Fritz »

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

Code: Select all

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

(map (add-tail "-Schwanz") '("Hund" "Katze" "Pinguin"))
Now I do this so:

Code: Select all

(map add-tail (dup "-Schwanz" 3 true) '("Hund" "Katze" "Pinguin"))
But I have a feeling there should be a simpler way.

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

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

Code: Select all

(map (curry add-tail (dup "-Schwanz" 3 true)) '("Hund" "Katze" "Pinguin"))
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Jeff meant to say this:

Code: Select all

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

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

Was he trying to append "-Schwanz" or "-Schwanz-Schwanz-Schwanz"?
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

Le pido perdon. Hablo solamente ingles y espanol. Y lisp ;)
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

Fritz
Posts: 66
Joined: Sun Sep 27, 2009 12:08 am
Location: Russia

Post by Fritz »

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
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

You can rename all function inside Newlisp ;-) I did once made a Dutch newlisp..
..Awfull ;-)
-- (define? (Cornflakes))

Locked