Questions tagged [funcall]

12 questions
31
votes
3 answers

Why do we need funcall in Lisp?

Why do we have to use funcall to call higher order functions in Common Lisp? For example, why do we have to use: (defun foo (test-func args) (funcall test-func args)) instead of the simpler: (defun bar (test-func args) (test-func args)) Coming…
Voo
  • 29,040
  • 11
  • 82
  • 156
5
votes
2 answers

mapcan, sharp quote and closures

I'm somewhat new to CL and currently trying to wrap my head around mapcan, #', funcall and closures. Here is a closure, which applies a predicate to a number n and, if correct, returns (list n), else nil: (defun all-those (predicate) (lambda (n) …
Frank
  • 433
  • 3
  • 10
3
votes
1 answer

Common Lisp - How to funcall/apply a function with keyword arguments?

Context With functions like (lambda (List arg1 arg2 ... argn)) I can use funcall/apply to call those methods with the original arguments and thus modify the list inside the lambda. With functions like (lambda (arg1 arg2 ... argn &key List)) I can…
Alberto
  • 565
  • 5
  • 14
2
votes
2 answers

Common Lisp, "defined but never used"

This function compiles with warnings, fn is defined and never used in the first line, and that fn is an undefined function in the second line: (defun test-function (fn) (funcall #'fn)) Why? A general explanation or a link to it would be…
Carlos Ledesma
  • 307
  • 1
  • 2
  • 8
1
vote
1 answer

`apply` or `funcall` for macros instead of functions

In Lisp, a function's arguments are evaluated first before entering the function body. Macro arguments stay not evaluated. But sometimes, one wants to inject code pieces stored in variables into a macro. This means evaluating the argument for the…
Gwang-Jin Kim
  • 9,303
  • 17
  • 30
1
vote
4 answers

Writing a test function leveraging two namespaces in lisp

I started to learn Lisp and using Lispworks personal edition 6.1.1 and I hit on problem when evaluating basic functions. I am able to get them right in Scheme but they are not working when I try to evaluate them in Lisp. I know in Lisp that every…
stack93m
  • 115
  • 6
1
vote
1 answer

Comparison returns expected value call function directory, but it is not so at process on list

I am creating a simple elisp tester. However, I am getting the wrong behavior (which I can not understand) as seen below. I think that testers should return t test cases (:eq 'a 'a) and (:eq (return-symbol) 'a) naturally as my tester also precedes…
Conao3
  • 171
  • 1
  • 3
  • 17
0
votes
3 answers

In Common Lisp, how to use lexical scope and funcall to make another function be passed as an argument?

I am using SBCL, Emacs, and Slime. Hence, I can do: CL-USER> (defvar example #'(lambda (x) (* x 20))) EXAMPLE CL-USER> (funcall example 10) 200 Ok. It works as expected. Using the library Dexador, I can also so: CL-USER> (ql:quickload :dexador) To…
Pedro Delfino
  • 2,421
  • 1
  • 15
  • 30
0
votes
2 answers

Nested callback function in C

I have written some code for calling nested functions using callback. But i am not getting output as I expected. Please have look into code: #include #include typedef int (*f_ptr)(int a, int b); typedef int…
ajayg2808
  • 375
  • 2
  • 10
0
votes
3 answers

Use do, if, and funcall to define (satisfy fun lst) which returns a list of the items in a list that satisfy a function

I've been looking around and still don't understand how funcall works. Would really appreciate if someone can give me a suggestion on ways to approach an think about the problem. I know that "fun" will have to be a predicate function, but after that…
0
votes
1 answer

How to call ObjectSpace.each_object with C API without rb_string_eval?

I'm currently trying to get all the instances of a class and I wanted to use ObjectSpace.each_object to achieve that. Here is my actual code in C : ruby_init(); int ruby_state = 0; rb_string_eval_protect("def my_func ; ObjectSpace.each_object(Klass)…
Sisyphe
  • 146
  • 1
  • 13
-3
votes
1 answer

debugging simple LISP functions.

I am very new to lisp, and am having a hard time even getting my feet wet. I'm sure once, I have a few functions working, I'll be able to build upon them and work on higher order functions, and more complex problems. Can someone point out my errors…
Ryan Miles
  • 307
  • 4
  • 11