map inmplementation on klisp is wrong?

34 views
Skip to first unread message

Mariano Guerra

unread,
Nov 14, 2012, 4:35:52 AM11/14/12
to kl...@googlegroups.com
section 5.9.1 in the specification says:

"lists must be a nonempty list of lists; if there are two or more, they must all have
the same length"

trying on klisp:

klisp> (map ($lambda (a) (+ a 1)) (list 1 2 3 4 5))
(2 3 4 5 6)
klisp> (map ($lambda (a) (+ a 1)) (list (list 1 2 3 4 5) (list 6 7 8 9 10)))

*ERROR*:
+: bad operand type
Location: #[operative: + @ kgnumbers.c (line: 2533, col: 0)]
Backtrace:
#[continuation (map-acyclic-part) @ *STDIN* (line: 1, col: 1)]
#[continuation (map-ret) @ *STDIN* (line: 1, col: 1)]
#[continuation (repl-print-loop) @ *STDIN* (line: 1, col: 1)]
#[continuation (pass-value) @ *STDIN* (line: 1, col: 1)]
#[continuation (pass-value) @ *STDIN* (line: 1, col: 1)]
#[continuation: root-continuation (exit) @ kstate.c (line: 275, col: 0)]

klisp> (map ($lambda (a) (+ a 1)) (list 1 2 3 4 5) (list 6 7 8 9 10))

*ERROR*:
?: ptree doesn't match arguments
Location: #[operative @ *STDIN* (line: 1, col: 6)]
Backtrace:
#[continuation (map-acyclic-part) @ *STDIN* (line: 1, col: 1)]
#[continuation (map-ret) @ *STDIN* (line: 1, col: 1)]
#[continuation (repl-print-loop) @ *STDIN* (line: 1, col: 1)]
#[continuation (pass-value)]
#[continuation (pass-value)]
#[continuation: root-continuation (exit) @ kstate.c (line: 275, col: 0)]

it seems it only accepts one list, am I doing something wrong?

DAY

unread,
Nov 14, 2012, 4:51:30 AM11/14/12
to kl...@googlegroups.com
If you pass two lists to `map`, the function you passed to `map` should take two arguments, say

(map ($lambda (a b) (+ a b)) (list 1 2 3 4 5) (list 6 7 8 9 10))

 

Mariano Guerra

unread,
Nov 14, 2012, 6:24:29 AM11/14/12
to kl...@googlegroups.com
Quoting DAY (2012-11-14 10:51:30)
great, thanks for the clarification

Andres Navarro

unread,
Nov 14, 2012, 1:19:49 PM11/14/12
to kl...@googlegroups.com

This is correct.  In this case "(map + (list 1 2 3 4 5) (list 6 7 8 9 10))" would also work because + takes any number of arguments. 

As for the stack trace, in this case it doesn't seem to help much, but there is still some info there to debug this. If you look at your second example, the second line it tells you the problem lies in the operative created from stdin, first line character 6, which corresponds to the lambda form.  What this error is telling you is that the underlying operative of the applicative created there was passed an operand tree that doesn't match with the one it expected (in this case it expected a single operand).  If you define it first, it will even give you the name instead of the '?' in the first line, say, if you did "($define! sum ($lambda (a) (+ a 1))) (map sum ...) it would say something like:
*ERROR*:
sum: ptree doesn't match arguments
Location: #[operative @ *STDIN* (line: 1, col: 6)]
...

Backtraces and error messages could still be a lot better thou (especially when interacting with tail calls...)

Regards,
Andres Navarro
Reply all
Reply to author
Forward
0 new messages