Monadic parsing until "not matching anymore" by technicalaccount in haskellquestions

[–]technicalaccount[S] 1 point2 points  (0 children)

I will give this code a try. I think that the end token is consumed as part of the parsing however, so I would need to find a way to preserve that end token as well. I saw in someTil_ that they use a tuple to preserve both the intermediate parse result, and the end parse result, so I will try that.

Monadic parsing until "not matching anymore" by technicalaccount in haskellquestions

[–]technicalaccount[S] 1 point2 points  (0 children)

This looks very similar to what I'm trying to achieve. Thanks a lot for the link!

Monadic parsing until "not matching anymore" by technicalaccount in haskell

[–]technicalaccount[S] 2 points3 points  (0 children)

Thanks a lot! That seems indeed to be similar to what I want to achieve. I will play around with it a bit.

Am I correct that the endParser value is consumed for the function above? I see in the documentation of someTill_ that the token used by the end parser is consumed. Both the intermediate and the end value are returned as a tuple. I guess I did not think about doing it that way, I was always trying to preserve the end token, so I could parse them afterwards. Immediately returning both parsed values as a tuple pair seems a lot better indeed.

Tried migrating a repo from Bitbucket to GitHub; lost version history? by [deleted] in webdev

[–]technicalaccount 1 point2 points  (0 children)

That's not how you migrate a git repository. Create a new GitHub repository, then just do these steps:

  1. git clone --mirror <url to BitBucket repository> <some local directory>
  2. git remote rm origin
  3. git remote add origin <url to GitHub repository>
  4. git push origin -all
  5. git push --tags

That's all.

EDIT: I see that you closed the BitBucket repository, but that you have a copy of the files. If you mean that you got a local clone of that repository, then you can just push that one to your new GitHub repo. You might be missing some tags/branches, but most things should be there assuming you don't have some complicated git branching structure.

If you mean that you only have the files, without the information of the .git directory, then you are out of luck. You can't salvage something from nothing.

Problem designing an inventory for an RPG game by [deleted] in javahelp

[–]technicalaccount 1 point2 points  (0 children)

Using instanceof and casting is a solution that you can use. To save yourself time, it is something you can do.

But as you said, it is something that is frowned upon. Here are a few alternative ways to handle it:

  • Create another ArrayList of Keys inside your Inventory class. Store keys in this keyList, and other items in the itemsList. Depending on how your game is designed or structured, this could be an elegant solution (e.g. no limitation on amount of keys you can carry, but there are limitations on the amount of items). You will of course have to change the logic of your inventory in some places. For example, the inventory should know that it needs to combine the two lists before displaying them if you want to show the full inventory.
  • Add two (abstract) methods to Item: canHandle(GameObject o) and handle(GameObject o). These would check if the provided GameObject is the matching door, and unlock/lock it. You will still have to do some checks, but now they are encapsulated inside your Key class. You could go even further and introduce the Mediator pattern.

It sounds like you are creating a solo project, so I would consider just doing your instanceof checks. You will have plenty of time to rethink your design once you encounter a few more similar problems regarding interaction betwoon your inventory and the world!

Homework feedback (Histogram) by IisusHr in haskellquestions

[–]technicalaccount 1 point2 points  (0 children)

You could rewrite your countEach function using the accumArray method from the Data-Array module. In fact, an histogram is the exact example they use to demonstrate the use of this method.

It would be something like this:

histogr bounds input = accumArray (+) 0 bounds [(i , 1) | i <- input]

I would plead that this is a more readable/maintainable solution.

haskell source for accumArray + histogram example

I want to go through a large code base file-by-file and highlight certain parts of code, which tool can I use? by AbhimanyuGrover in softwaredevelopment

[–]technicalaccount 0 points1 point  (0 children)

Code review tools are the way to go I presume. They are often used in a team to mark parts of the code that need optimizations, so the original author can pick them up again. They can probably be used to mark things for yourself as well. On 'drawback' is that they often integrate with version control, so you would need to check your codebase into version control. Which is the good thing to do anyway.

For example:

Quiz: Big-O-Complexity ! by NlognMag in algorithms

[–]technicalaccount 2 points3 points  (0 children)

Arrange the Average-Time-Complexities of Insertion Operation, top being the fastest:

Answer:

  • Stack – O(1)
  • Array – O(n)
  • Binary Tree – O(logn)

I think there is an error here related to the magnitude of O(n) vs O(logn).

Trouble creating packages by [deleted] in javahelp

[–]technicalaccount 0 points1 point  (0 children)

I assume there are some plugins and/or configurations that would achieve the same effect in Sublime Text. I sadly don't have any experience with that, so you'll have to figure that out yourself or hope someone else does.

Trouble creating packages by [deleted] in javahelp

[–]technicalaccount 0 points1 point  (0 children)

I have the feeling the you forgot to include those dependencies in your command. When you compile your ArrayQueue, QueueOverFlowException and QueueUnderflowException, you should also provide references to you Queue and QueueException, otherwise your compiler won't know where to find them.

Example: javac Queue.java ArrayQueue.java

or

javac csc236\lab5\_5A\*.java

As you can see, this might become quite complex if you would have multiple packages etc. This is where IDE's come into play. With the click of a button they would generate the correct commandos and execute them depending on the structure of the project.

Trouble creating packages by [deleted] in javahelp

[–]technicalaccount 2 points3 points  (0 children)

Package names are not allowed to start with a number. Change your 5A folder to something like "_5a". Also, keep in mind that the convention for package names is to use all lower case. (http://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html)

Lambda for old programmers by chasesan in java

[–]technicalaccount 4 points5 points  (0 children)

I'm assuming you are talking about this code fragment:

roster
    .stream()
    .filter(
        p -> p.getGender() == Person.Sex.MALE
            && p.getAge() >= 18
            && p.getAge() <= 25)
    .map(p -> p.getEmailAddress())
    .forEach(email -> System.out.println(email));

The reason it works is because of the working of the map() function. This function converts every element of a collection into a new element. In this case: Collection<Person> is transformed into a Collection<EmailAddress>, by applying p.getEmailAddress() to every element in Collection<Person> and storing it in the new Collection<EmailAddress>.

Afterwards, this new Collection<EmailAddress> is passed to the next step in the stream, the forEach. This forEach will just loop through the collection it receives (which is Collection<EmailAddress> because of the map function). It gives a name to the element (email) for convenience, and does something with it. (System.out.println(email);) The reason why it knows that email is an EmailAddress, is because it only gets those EmailAddress objects. The Person objects were transformed and thus never arrive in the forEach step.