exercism | Exercism - FP languages Exercises | Functional Programming library
kandi X-RAY | exercism Summary
kandi X-RAY | exercism Summary
Exercism exercises in functional programming languages like Clojure, Elixir, Elm, Haskell Scala, Lisp, Erlang, Purescript, F# or Scheme.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Run the help .
- Recursive comparison function .
- Execute the next step
- Rewrites two nodes with a random slot .
- Set up incoming port
- Determines whether two objects are equal .
- Set up the subscribers
- Appends two nodes .
- appends two nodes
- Compares two values .
exercism Key Features
exercism Examples and Code Snippets
Community Discussions
Trending Discussions on exercism
QUESTION
I'm going through the x86-64 tutorial on exercism.org. I'm using NASM on Linux, producing an ELF binary. There is just a bit of C code that invokes my assembly code in a test harness. Their build system specifies -pie
in the LDFLAGS and -fPIE
in the CFLAGS (among others, but those are the most relevant here I think). Therefore, I need (and would like to understand) a solution that uses PIC, which requires RIP-relative addressing.
I have an index (in rdi
) into an array of 8-byte (qword) values called values
. I just want to get the address at the offset in order to mov
the value it points to into a register. Or I would accept mov
ing the value directly.
I tried this:
...ANSWER
Answered 2022-Apr-17 at 21:49There is no such instruction as lea rbx, [rel values + rdi * 8]
, or in other words lea rbx, [values + rip + rdi * 8]
. The rip
-relative addressing mode cannot be combined with an index register (with or without scaling). See Referencing the contents of a memory location. (x86 addressing modes)
Unfortunately, it looks like nasm handles this by just ignoring the rel
and assembling lea rbx, [values + rdi * 8]
, which would require the problematic relocation. The address of values
would have to go in the 32-bit displacement field of the instruction's memory operand, but that is impossible since values
need not be located in the lowest or highest 2 GB of memory; hence the confusing error message.
But the correct solution is that you just have to write more instructions. You can get the desired effect in two instructions with
QUESTION
I'm doing the Clock exercise from Exercism, which is about implementing a clock that handles times without dates.
In it I need to write a method add_minutes
, which is simply adding minutes to a clock.
I come from Java so took it the Java way, making add_minutess
a method with ()
return type.
However, the exercise designs the method with Self
return type.
I'm not sure why is it designed this way and what benefits it has over my ()
method?
ANSWER
Answered 2022-Apr-10 at 13:45Whether the method should return ()
or Self
depends on whether you want the method to mutate the value it is called on (like +=
) or leave that value alone and return a new value (like +
).
Since this is a shallow type (it's a single i32
with no heap-allocated data) it makes more sense to have such a method return a new value and leave the original alone, in which case you can take &self
instead of &mut self
.
In fact, I'd suggest adding Copy
and Clone
to the derive macro for Clock
and then this method can become a consuming method (taking self
as a value instead of a reference):
QUESTION
I am trying to solve the 'strain' exercise on exercism. The function is supposed to accept a predicate function as a parameter.
...ANSWER
Answered 2022-Mar-20 at 22:42To answer the specific question - how to use the predicate in the body - let's say that we want to do something much simpler. We want to write a function that takes a predicate pred
and a value v
and it just returns "OK" if the predicate holds for the given value and "Nope" if it does not.
To do this, you would write:
QUESTION
I've coded the "classical" bank account kata with F# MailboxProcessor
to be thread safe. But when I try to parallelize adding a transaction to an account, it's very slow very quick: 10 parallel calls are responsive (2ms), 20 not (9 seconds)! (See last test Account can be updated from multiple threads
beneath)
Since MailboxProcessor
supports 30 million messages per second (see theburningmonk's article), where the problem comes from?
ANSWER
Answered 2022-Jan-15 at 13:55Your problem is that your code don't uses Async all the way up.
Your Account class has the method Open
, Close
, Balance
and Transaction
and you use a AsyncReplyChannel
but
you use PostAndReply
to send the message. This means: You send a message to the MailboxProcessor with a channel to reply. But, at this point, the method waits Synchronously to finish.
Even with Async.Parallel
and multiple threads it can mean a lot of threads lock themsels. If you change
all your Methods to use PostAndAsyncReply
then your problem goes away.
There are two other performance optimization that can speed up performance, but are not critical in your example.
Calling the Length of a list is bad. To calculate the length of a list, you must go through the whole list. You only use this in Transaction to print the length, but consider if the transaction list becomes longer. You alway must go through the whole list, whenever you add a transaction. This will be O(N) of your transaction list.
The same goes for calling (List.sum). You have to calculate the current Balance whenever you call Balance. Also O(N).
As you have a MailboxProcessor, you also could calculate those two values instead of completly recalculating those values again and again.Thus, they become O(1) operations.
On top, i would change the Open
, Close
and Transaction
messages to return nothing, as in my Opinion, it doesn't make sense that they return anything. Your examples even makes me confused of what the bool
return
values even mean.
In the Close
message you return state.Opened
before you set it to false. Why?
In the Open
message you return the negated state.Opened
. How you use it later it just looks wrong.
If there is more meaning behind the bool
please make a distinct Discriminated Union out of it, that describes the purpose of what it returns.
You used an option
throughout your code, i removed it, as i don't see any purpose of it.
Anyway, here is a full example, of how i would write your code that don't have the speed problems.
QUESTION
I'm trying to solve a very simple rust exercise involving PrimitiveDateTime
. I'm trying to run this basic example in my own machine
ANSWER
Answered 2022-Jan-10 at 15:00Quite a few things in the time
crate are feature flag gated, meaning you need to manually specify some feature to enable a certain feature. In your case the macros are missing, taking a look at time
's crates.io page shows us you need to add the feature macros
to enable this. You can do this by specifying your dependency like so:
QUESTION
I'm trying to solve the RPN calculator exercise at exercism but stumbled upon this temporary value dropped while borrowed
error that I can't seem to work out.
Here's my code:
...ANSWER
Answered 2022-Jan-04 at 14:00You have the same behavior with this simple exemple
QUESTION
ANSWER
Answered 2021-Dec-13 at 18:38Something looks broken by something installed. These reg entries should be reg_expand_sz. You should not see %VARS% when viewing the path from the commandline.
QUESTION
As a Rust beginner working on one of the first problems on Exercism/Rust (https://exercism.org/tracks/rust/exercises/assembly-line)
I would like to know if it is possible to constrain integer input to a range at compile-time
to be able to have a clean set of match expression
cases.
Below is my current implementation of production_rate_per_hour
:
ANSWER
Answered 2021-Dec-13 at 19:15There is currently no way to express this in the type system.
I assume you mean min instead of max. The typical approach would be:
QUESTION
export function twoFer( arg : string ): string
{
if( arg !== "")
{
return "One for " + arg + ", one for me.";
}
return "One for you, one for me." ;
}
...ANSWER
Answered 2021-Oct-19 at 14:49A string parameter not specified doesn't contain an empty string; it contains undefined
. You would want something like this:
QUESTION
I am learning clojure with Exercism and I'm having a bit of trouble finishing the last section of the lasagna problem.
Heres the instruction - Define the total-time function that takes two arguments: the first argument is the number of layers you added to the lasagna, and the second argument is the number of minutes the lasagna has been in the oven. The function should return how many minutes in total you've worked on cooking the lasagna, which is the sum of the preparation time in minutes, and the time in minutes the lasagna has spent in the oven at the moment.
here's my code thats giving me trouble:
...ANSWER
Answered 2021-Sep-29 at 15:01Don't use def
inside defn
. If you really need some variables, you can use let
, but this exercise can be completed without it:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install exercism
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page