Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give a list as arguments to a function in elisp?

Tags:

emacs

elisp

I'm trying to learn elisp and emacs customization. I setq'ed a list of arguments to a variable. How do I go about passing this list to a function instead of just giving the arguments directly.

Thanks in advance.

like image 265
BobLoblaw Avatar asked Nov 13 '12 13:11

BobLoblaw


People also ask

What is the syntax for a function with arguments?

When one piece of code invokes or calls a function, it is done by the following syntax: variable = function_name ( args, ...); The function name must match exactly the name of the function in the function prototype. The args are a list of values (or variables containing values) that are "passed" into the function.

How many arguments can a function accept?

Except for functions with variable-length argument lists, the number of arguments in a function call must be the same as the number of parameters in the function definition. This number can be zero. The maximum number of arguments (and corresponding parameters) is 253 for a single function.

What is apply in Lisp?

In Common Lisp apply is a function that applies a function to a list of arguments (note here that "+" is a variadic function that takes any number of arguments): (apply #'+ (list 1 2)) Similarly in Scheme: (apply + (list 1 2))

How to pass a list as an argument to a function?

Python Passing a List as an Argument ❮ Python Glossary Passing a List as an Argument You can send any data types of argument to a function (string, number, list, dictionary etc.), and it will be treated as the same data type inside the function. E.g. if you send a List as an argument, it will still be a List when it reaches the function:

How many arguments can a function take in Python?

In Python, functions can take either no arguments, a single argument, or more than one argument. We can pass a string, integers, lists, tuples, a dictionary etc. as function arguments during a function call.

What can be passed as function arguments in C++?

We can pass a string, integers, lists, tuples, a dictionary etc. as function arguments during a function call. The function accepts them in the same format and returns the desired output.


1 Answers

Use the apply function:

(apply 'function arglist)

For example:

(apply '+ '(1 2 3 4))
==> 10
like image 140
user4815162342 Avatar answered Nov 15 '22 10:11

user4815162342