Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to apply a two-arg function to a sequence?

Tags:

clojure

I have a sequence:

[a b c ...]

And a function (f x y). I want to get this:

(f c (f b (f a 1)))

Etc.. How to do this?

like image 522
yegor256 Avatar asked Feb 11 '13 20:02

yegor256


People also ask

Is it possible to pass multiple arguments to a function?

We pass arguments in a function, we can pass no arguments at all, single arguments or multiple arguments to a function and can call the function multiple times.

How do you pass two parameters on a Python map?

Passing two lists and 'sum' function to map() Define a function sum, which returns sum of two numbers. Declaring and initializing lst1 and lst2. Passing sum function, list1 and list2 to map(). The element at index 0 from both the list will pass on as argument to sum function and their sum will be returned.

Which function accepts two arguments in Javascript?

Let's start by creating a function called add that can accept 2 arguments and that returns their sum. We can use Node. js to run the code node add_2_numbers.

How do you declare two functions in Python?

There are two basic types of functions: built-in functions and user defined functions. The built-in functions are part of the Python language; for instance dir , len , or abs . The user defined functions are functions created with the def keyword.


1 Answers

Reduce, with a small adaptation:

(reduce #(f %2 %1) 1 [a b c])
like image 180
Rafał Dowgird Avatar answered Nov 15 '22 09:11

Rafał Dowgird