Tag Info

New answers tagged

1

What inconsistency? In the first case, you have a function. In the second case, you have a lambda expression, that is a function which has no name. Python could have chosen one of those three approaches: Returning None, Returning an arbitrary string, such as <lambda>, Raising an exception. All three options are valid, given that the third one ...


0

The most literal and direct answer to the asked question is "you don't." More helpful but still not quite sufficient as an answer is "as function results." Neither is completely enough when just starting out looking at things from a functional viewpoint though so let me share some things that helped me. Functions are not methods — Functions operate on ...


4

The caller doesn't so much need to know the implementation details of repeat(f, n) as he needs to know its return value. In this case, the return value is a little more complicated than most, because it returns a function. In a static language like Haskell, this is easily documented in the function signature like: repeat :: (a -> a) -> Int -> (a ...


14

Wrt abstraction, I see that repeat(square, 2) returns implementation detail in the form of apply_n_times(n - 1)(f(x)) multiple times before providing the actual result. The function returned by repeat(square, 2) is not an implementation detail; it's the whole point of calling repeat. An implementation detail is something that the caller doesn't need to ...


6

The benefit of abstraction is that the caller doesn't have to know about implementation details. If I understand correctly, you're questioning this python construct because the caller can find about about implementation details. That's not the same thing. Not having to know about how a method does its job is useful. It aids the software developer in their ...


0

I'd say no, this definitely isn't pure functional programming -- the computeSequence function is not functional (it mutates a list), and setting the count and sequence variables is also not functional. Also, it's going to run into Python's max recursion depth (100) pretty quickly. I don't think trying to program in purely functional style works very well ...


0

Local mutation that's never visible outside the function is totally fine, no problems there. However, approaching problems in a functional style usually means you don't actually do the recursion yourself in a vast majority of cases: you make use of a large number of built in general helpers for handling recursive logic for you. A good example is fold, also ...


0

I think @JustGage pretty much nailed it, but I'd like to add that in general, functional programs, especially recursive ones, often store partially computed objects on the stack, in all those stack frames. Using a passed list just keeps the data in a different place. If you prefer, you could pass an immutable list as a parameter and return a revised copy of ...


1

I would say it is functional! The only half way iffy thing would be the fact that computeSequence actually mutates the array passed into it, however you only use it as a local function and thus it really doesn't matter because it still never changes anything outside of it's local scope and thus always yields the same results. to answer your second question ...


2

The most common pattern I see in these types of situations is to use a CompletableFuture, which most FP languages just call a plain Future. It allows you to execute something long-running like a query, then specify actions to take later. If the query succeeds, the result is passed to the next action in the chain. If it fails, all the subsequent actions ...


5

You already said in your question how you can tell whether your program is referentially transparent or not: if you can replace a expression with its value, without changing the meaning of the program, it is referentially transparent. If you cannot do that, it is not. So, let's just try and replace some expressions with their values! in your summation ...


0

This is a blog about the death of OOP and the conclusion at the end is that ECS are not OOP: http://loup-vaillant.fr/articles/deaths-of-oop


0

Is it possible to implement, for example, locking with unique types? I followed the link that Robert Harvey provided and I did a quick read-up. I cannot say that I understood everything or that I have a high level of confidence that I really understood what I think I understood, but it appears to me that the whole point of external uniqueness and ...


1

It sounds like the crux of the problem is: For a lot of functions in the dispatch table, they obviously know best how to calculate and return the appropriate value. However, for a few items, it is the caller of the function who best knows the value. What solution you should use depends entirely on why the caller knows best, which you haven't ...



Top 50 recent answers are included