libera/#lisp - IRC Chatlog
Search
20:35:06
moon-child
jcowan: I don't see why funcall is useful for adapting cl programs to scheme. The primary hurdle is colliding names that were previously in different namespaces; once you've taken care of that, you can freely remove all instances of funcall
20:35:29
moon-child
but, as aeth points out, it _can_ be useful in scheme when writing higher-order functions
20:36:08
jcowan
You can freely remove them, but if you'd rather not mess with the source more than absolutely necessary, having a definition of funcall is a small step in that direction.
20:39:28
moon-child
my point is that ensuring there are no collisions is a very invasive change, far more so than removing instances of funcall
20:44:18
moon-child
(looked at my old code where I thought I was using it, but I guess I decided against using it, so I don't have an example, unfortunately)
21:43:38
jcowan
moon-child: I mean, what is the advantage of funcall when dealing with higher-order functions?
21:47:58
aeth
(define (funcall fn . args) (apply fn args)) (define mapcar map) (mapcar funcall (do ((i 0 (+ 1 i)) (l '() (cons (lambda () i) l))) ((>= i 10) l)))
21:50:25
pjb
jcowan: the advantage is that you can have both functions and variables named with the same name, just like in English and a lot of other natural languages.
21:50:26
aeth
You might think to do (defconstant funcall 'funcall) in the CL version because 'funcall works just as well as #'funcall, but, no, there's a package lock on COMMON-LISP (and thus on COMMON-LISP:FUNCALL) in SBCL and any other implementation is free to do the same.
21:54:20
aeth
pjb: Yes, it's a debate as old as time. Which one do you want to be easy and which one do you want to be awkward? (defun list-of-list (list) (list list)) vs (define (f x) (x))
21:58:50
moon-child
jcowan: you can pass funcall as the 'function' and some other function as the 'data' into a higher-order function to make the hof call the 'data' function
22:03:43
aeth
(define (funcall fn . args) (apply fn args)) (map funcall (list (lambda () 1) (lambda () 2))) ; works