Questions tagged [arity]

The arity of a function or operation is the number of arguments or operands that the function takes.

The arity of a function or operation is the number of arguments or operands that the function takes.

The term "arity" is rarely employed in everyday usage. For example, rather than saying "the arity of the addition operation is 2" or "addition is an operation of arity 2" one usually says "addition is a binary operation". In general, the naming of functions or operators with a given arity follows a convention similar to the one used for n-based numeral systems such as binary and hexadecimal. One combines a Latin prefix with the -ary ending; for example:

  • A nullary function takes no arguments.
  • A unary function takes one argument.
  • A binary function takes two arguments.
  • A ternary function takes three arguments.
  • An n-ary function takes n arguments.
108 questions
6
votes
2 answers

Specializing function template based on lambda arity

I am trying to specialize a templated function based on the arity of the lambda that I pass to it as an argument. This is what I have come up with for a solution: template struct helper; template struct…
lightxbulb
  • 1,251
  • 12
  • 29
6
votes
1 answer

Arity-generic programming in Agda

How to write arity-generic functions in Agda? Is it possible to write fully dependent and universe polymorphic arity-generic functions?
effectfully
  • 12,325
  • 2
  • 17
  • 40
6
votes
1 answer

Overriding multi-arity methods in proxy in clojure

I have a java class that has 2 methods with same but different arities (one take no arguments, other takes 1 argument). I create a proxy that overrides both this methods. The problem is that if no-arg method is called from this java class - base…
Mikita Belahlazau
  • 15,326
  • 2
  • 38
  • 43
5
votes
1 answer

Can clojure evaluate a chain of mixed arity functions and return a partial function if needed?

Suppose you have three functions of arity 1, 2 and 3 as below: (defn I [x] x) (defn K [x y] x) (defn S [x y z] (x z (y z))) Does clojure have an evaluation function or idiom for evaluating: (I K S I I) as (I (K (S (I (I))))) returning a parital…
dansalmo
  • 11,506
  • 5
  • 58
  • 53
4
votes
2 answers

How can I splattify an anonymous object so I can use &method on it?

I'm wanting to use the &method(:method_name) idiom when there's more than one object required by method_name. Can I do this under Ruby 1.9? For example, if I've got def move_file(old_filename, new_filename) STDERR.puts "Moving…
Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
4
votes
1 answer

Why is the variable arity record component not inferred with custom constructor?

Trying out some code with record and record components. I was making use of the variable rarity components and was struck with a compile-time error over a custom constructor. public record Break(R record, String... notifications)…
Naman
  • 27,789
  • 26
  • 218
  • 353
4
votes
1 answer

Understanding the arity parameter of the method Proc.curry in Ruby

In the documentation of Ruby's Proc.curry method at https://ruby-doc.org/core-2.5.3/Proc.html#method-i-curry, it says: curry -> a_proc curry(arity) -> a_proc Returns a curried proc. If the optional arity argument is given, it determines the number…
Just a learner
  • 26,690
  • 50
  • 155
  • 234
4
votes
1 answer

c++ How to get arity of a constructor?

Given a template parameter class T that has a single constructor (no copy or move constructor either) and zero default arguments, is there some way to find the arity of T(...)? My attempts so far #include #include #include…
Brian Rodriguez
  • 4,250
  • 1
  • 16
  • 37
4
votes
3 answers

Clojure function throws a null pointer exception

I've just begun to teach myself clojure and I'm having fun. However trouble began when I began to exec this function I wrote! It's a simple function that accepts multiple number of arguments & returns the difference between the last and the first…
4
votes
2 answers

Arity of a function

Is there a way in clojurescript to check what the available arity implementations of a given cljs function are?
Ferdy
  • 497
  • 2
  • 4
  • 13
4
votes
2 answers

Arity of method delegated with method_missing

When I delegate methods on instances of class A to $delegation_target as below: $delegation_target = "" class A def method_missing *args, ≺ $delegation_target.send(*args, &pr) end def respond_to_missing? *args;…
sawa
  • 165,429
  • 45
  • 277
  • 381
3
votes
1 answer

Why does the result of a mapping transducer include greater-than-2 arities?

The question is in the title. Below I copy the transducer-part of the source of map: ([f] (fn [rf] (fn ([] (rf)) ([result] (rf result)) ([result input] (rf result (f input))) ([result input & inputs] ;why? …
peter pun
  • 384
  • 1
  • 8
3
votes
1 answer

is there a way to return a fun that can have more than one arity?

Erlang functions can share the same name but have different arity. For example: name(X) -> X. name(X,Y) -> X * Y. I would like to be able to return a fun from a function that behaves in the same way. In this example I want a way to return fun/1…
Rashid
  • 41
  • 2
3
votes
2 answers

How to get the amount of arguments of a function

I'm looking for a way to get the amount of arguments of a function, a function like the imaginary length-args function below: (defun func1 (arg1 arg2) ()) (defun get-count-args-func (func) (length-args func)) (get-count-args-func #'func1) ;;…
PerduGames
  • 1,108
  • 8
  • 19
3
votes
4 answers

Number of elements in the varargs

I am quite confused as to how Java calculates the length of the varargs: static void hello(Integer... x){ System.out.println(x.length); } public static void hi(){ hello(); } This prints a 0. When I pass : static void hello(Integer...…
Raj
  • 203
  • 1
  • 2
  • 8