Q&A's, tips, howto's
Fritz
Posts: 66 Joined: Sun Sep 27, 2009 12:08 am
Location: Russia
Post
by Fritz » Tue Oct 13, 2009 1:51 pm
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 » Tue Oct 13, 2009 2:21 pm
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 » Tue Oct 13, 2009 2:40 pm
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 » Tue Oct 13, 2009 2:41 pm
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 » Tue Oct 13, 2009 2:42 pm
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 » Tue Oct 13, 2009 2:43 pm
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 » Tue Oct 13, 2009 3:55 pm
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 » Tue Oct 13, 2009 4:11 pm
You can rename all function inside Newlisp ;-) I did once made a Dutch newlisp..
..Awfull ;-)
-- (define? (Cornflakes))