functional-programming

Where's the code for a lambda located in a java class file?

别等时光非礼了梦想. 提交于 2020-02-16 08:14:16
问题 I've this java source file: import java.util.function.*; public class t { public static void main(String[] args) { Function<Integer,Integer> r = (a) -> a*a+2*a+1; System.out.println(r.apply(2)); } } I compile it and it works as expected. Here's the output of javap -c -v t , and I can't find the location of lambda in it. Where's the bytecode which tells the jvm to compute the expression with the input Integer whenever the lambda is envoked? 回答1: If you want to see the code of your lambda body

One line declare, compare and return in c#

六月ゝ 毕业季﹏ 提交于 2020-02-08 10:06:30
问题 I am wondering if is possible to do something like the following code: _ = name.Split(' ') => names.Count() > 1 ? new Tuple<string, string>(string.Join(" ", names.Take(names.Count() - 1)), names.Last()) : new Tuple<string, string>(name, string.Empty)) ; where names is the result of name.Split(' ') . Im not getting how to acces to this result without declaring it in a separated line like: var names = name.Split(' '); This line is what I want to avoid but also I dont want to call every time the

One line declare, compare and return in c#

做~自己de王妃 提交于 2020-02-08 10:05:20
问题 I am wondering if is possible to do something like the following code: _ = name.Split(' ') => names.Count() > 1 ? new Tuple<string, string>(string.Join(" ", names.Take(names.Count() - 1)), names.Last()) : new Tuple<string, string>(name, string.Empty)) ; where names is the result of name.Split(' ') . Im not getting how to acces to this result without declaring it in a separated line like: var names = name.Split(' '); This line is what I want to avoid but also I dont want to call every time the

One line declare, compare and return in c#

断了今生、忘了曾经 提交于 2020-02-08 10:04:26
问题 I am wondering if is possible to do something like the following code: _ = name.Split(' ') => names.Count() > 1 ? new Tuple<string, string>(string.Join(" ", names.Take(names.Count() - 1)), names.Last()) : new Tuple<string, string>(name, string.Empty)) ; where names is the result of name.Split(' ') . Im not getting how to acces to this result without declaring it in a separated line like: var names = name.Split(' '); This line is what I want to avoid but also I dont want to call every time the

Build generic reusable iteration module from higher order function

百般思念 提交于 2020-02-06 04:29:10
问题 How can I create a reusable module for iteration which allows me to: choose whether it iterates in parallel lets me specify a higher-order function of which tasks need to be performed Here are some dummy functions. They for itself pose the second part of the question: Should I have an interface here that each of these functions at least implements the parameter inputDay:String ? or is it better to have a generic function with a configuration class, where the configuration implements a minimal

Coq: Prove equality of two factorial functions using induction

徘徊边缘 提交于 2020-02-04 11:47:49
问题 I want to prove that two factorial functions are equivalent in Coq using induction. The base case n = 0 is easy, however, the induction case is more complicated. I see, that if I could rewrite (visit_fac_v2 n' (n * a)) to n * (visit_fac_v2 n' a) , I would be done. However, translating this idea into Coq causes me troubles. How would one go about proving this in Coq? Fixpoint fac_v1 (n : nat) : nat := match n with | 0 => 1 | S n' => n * (fac_v1 n') end. Fixpoint visit_fac_v2 (n a : nat) : nat

Coq: Prove equality of two factorial functions using induction

可紊 提交于 2020-02-04 11:47:15
问题 I want to prove that two factorial functions are equivalent in Coq using induction. The base case n = 0 is easy, however, the induction case is more complicated. I see, that if I could rewrite (visit_fac_v2 n' (n * a)) to n * (visit_fac_v2 n' a) , I would be done. However, translating this idea into Coq causes me troubles. How would one go about proving this in Coq? Fixpoint fac_v1 (n : nat) : nat := match n with | 0 => 1 | S n' => n * (fac_v1 n') end. Fixpoint visit_fac_v2 (n a : nat) : nat

Coq: Prove equality of two factorial functions using induction

▼魔方 西西 提交于 2020-02-04 11:47:14
问题 I want to prove that two factorial functions are equivalent in Coq using induction. The base case n = 0 is easy, however, the induction case is more complicated. I see, that if I could rewrite (visit_fac_v2 n' (n * a)) to n * (visit_fac_v2 n' a) , I would be done. However, translating this idea into Coq causes me troubles. How would one go about proving this in Coq? Fixpoint fac_v1 (n : nat) : nat := match n with | 0 => 1 | S n' => n * (fac_v1 n') end. Fixpoint visit_fac_v2 (n a : nat) : nat

Tracking number of function calls + closures (à la SICP) in Python

三世轮回 提交于 2020-02-03 21:50:59
问题 This is a question about scope and closures in Python , motivated by an exercise in SICP. Much thanks for your time if you read this! A question (3.2) in SICP asks one to create a procedure "make-monitored", that takes in a function f (of one parameter) as input and returns a procedure that keeps track of how many times f has been called. (If the input to this new procedure is "num-calls" it returns the number of times f has been called, if it is "reset" it resets counter to 0 and anything

Tracking number of function calls + closures (à la SICP) in Python

爷,独闯天下 提交于 2020-02-03 21:48:06
问题 This is a question about scope and closures in Python , motivated by an exercise in SICP. Much thanks for your time if you read this! A question (3.2) in SICP asks one to create a procedure "make-monitored", that takes in a function f (of one parameter) as input and returns a procedure that keeps track of how many times f has been called. (If the input to this new procedure is "num-calls" it returns the number of times f has been called, if it is "reset" it resets counter to 0 and anything