Illegal function error on defining custom map function for learning purposes

(define (head a) (car a))
(define (tail a) (cdr a))
(define (my-map f args) (if (null? (tail args)) (f (head args)) ((f (head args)) (my-map f (tail args)))))

Hi! When I enter my-map definition, no error happens, but when I call it like this: (my-map some-function-here '(1 2 3)) it fails with Error: Illigal function error. I don’t get what’s the problem here, error tells nothing about what went wrong.

Solution:

(define (my-map f args) (if (null? (tail args)) (list (f (head args))) (append (list (f (head args))) (my-map f (tail args)))))

i wonder if the language supports splitting this up in multiple lines to make it more readable :smiley:

It does, but the GIMP interactive console itself doesn’t AFAIK.

You can always copy-paste a group of lines from an external editor

1 Like