gdb prints weird completions - autocomplete

For instance when I go to tab complete after file.c for matching .cpp, I get things like the following. I have built with -g -ggdb -03
fileName.calloc fileName.calloc#got.plt
fileName.calloc#plt fileName.ceil
fileName.ceil#got.plt fileName.ceil#plt
fileName.clock_gettime fileName.clock_gettime#got.plt
fileName.clock_gettime#plt fileName.close
fileName.close#got.plt fileName.close#plt
fileName.coeff_ab(double*, double*, double, double, double, double, double)
fileName.coerceAngle0to2PI(double*) fileName.coerceAngle0to2PI(float*)
...

Related

How can I overload a constructor in Scala with a function as a parameter

I am making a file searching program. This is contained in a "ParallelSearch" class. The signature is:
class ParallelSearch(condition: (Path, Int, String) => Boolean)
This is great and works. The user supplies a condition, that goes from a file path, a line number, and a string containing line content, to a Boolean. However, I would like to overload the constructor to allow the user to not specify file path or line number, and just search based on line contents. Like so:
def this(condition: String => Boolean) =
{
this((???): (Path, Int, String) => Boolean)
}
What I'm not sure about is what to put where I have the ??? right now. I can answer any other questions that will make understanding easier. Any help is appreciated! Thanks!

Is there a way to remove parameters during run-time?

I am creating a population of agents using around 40 mapped parameters. These parameters are just used in the initialisation of the population. However, the problem is that when creating a new agent these many parameters will be required in the arguments without an actual need for them. Just to give you an idea how ugly it looks like.
add_households(int, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, boolean)
Therefore, I was wondering if there is a way to remove/hide these parameters after no longer needed. It would be great to be looking like this :
add_households(int, boolean)
If not possible, the other solutions that I will be looking for are:
Maybe there is something similar to parameters mapping for variables. (as variables will not show as arguments.
Moving the whole population after being initialised to a new Agent class with the wanted parameters only. (The main thing here is to keep the created connections with other agent classes)
I appreciate any other suggestions for this problem.
Thank you in advance;
A Possible Solution
Amy's suggestion is elegant in my opinion. However, it did not work exactly as suggested. When typing: objHousehold.initRuntimeParamters( set_age(5), set_p_HH_willing_to_change(true));
It throws an error stating:
The method set_age(int) is undefined for the type Main.
The method set_p_HH_willing_to_change(boolen) is undefined for the type Main.
However, with a littel change I managed to access the wanted parameters only by typing:
Household objHousehold = add_households();
households(objHousehold.getIndex()).set_age(5);
households(objHousehold.getIndex()).set_p_HH_willing_to_change(true);
You could always do add_households(), which would take the default parameters. You could then call a function to set only the 2 you are interested in.
Household objHousehold = add_households();
objHousehold.initRuntimeParamters( int, boolean );
within initRuntimeParameters, use set_parameterName( value ) to set the parameter value.

Retaining type information in List[Any]

I'm using certain external library that has a method which is overloaded several times with different arguments, something like:
insertInto(index: Int, int: Int)
insertInto(index: Int, lng: Long)
insertInto(index: Int, dbl: Double)
insertInto(index: Int, str: String)
And a certain case class I'm using whose data I want to pass onto said methods, say:
case class C(str: String, lng: Long, dbl: Double, int: Int /* more values */)
val c = C("asd", 1, 1.1, 1)
Right now I'm using the library method like:
insertInto(1, c.int)
insertInto(2, c.lng)
insertInto(3, c.dbl)
insertInto(4, c.str)
//more insertions...
But since I'm always using the index of the value in the case classes I figured that maybe I could could save up on some lines of code (around 10) with something like the following:
c.productIterator.zipWithIndex.toList.foreach {
case (idx, value) => insertInto(idx, value)
}
But this doesn't work because I'd be iterating a List[Any] and therefore the compiler complains that I'm not passing the correct argument type to insertInto since Any is not String, Int, Long, Double, etc..
What would be the correct way of handling this? Thanks in advance
case class A[T](t:T)(implicit tag: ClassManifest[T]){
val newTag = tag
override def toString= t+" "+tag.toString
}
case class C(xs:List[Any])
val c=C(List(A("a"),A[Long](1), A[Double](1.1), A[Int](1)))
c.xs.foreach(println)
Try this. I am using Scala 2.9.3. In newer versions, you can use TypeTag and ClassTag. Check here
So now you have the class type information. You can devise some mechanism to map class type value as string to .class instance and then use asinstanceof to cast it.

IntelliJ Idea: Align on Colon for Scala Case Class Members?

Is there a way to prevent Idea from reformatting multiline case class members?
Intended result
(position of the colon is not so important, but the alignment of the type annotations would be great)
case class ApiError(
timestamp : LocalDateTime,
status : Int,
code : Option[String],
message : String
)
I've spent some time in the Code Styling settings for Scala and am stuck with code styling like this:
case class ApiError(
timestamp: LocalDateTime,
status: Int,
code: Option[String],
message: String
)
I am okay with cluttering the code with #formatter:off, but it would be awesome if there was a better way.
Just like Madoc commented, those kind of formats may lead to huge changes when adding a new line. Also, while pretty in small cases, it doesn't scale, and it seems we are programming in tables...
my IntelliJ IDEA version is ultimate 2019.3
step 1. Prefrences -> Editor -> Code Style -> Scala
step 2. Wrapping and Braces -> Method declaration parameters, then
check "Align paramenter types in multiline declarations"
I tried the example in question, it was
case class ApiError(
timestamp: LocalDateTime,
status : Int,
code : Option[String],
message : String
)
if you uncheck "Align when multiline", it is consistent with intended result.
case class ApiError(
timestamp: LocalDateTime,
status : Int,
code : Option[String],
message : String
)

Syntax for accepting tuple in a function in Scala

I would like a function to consume tuple of 7 but compiler won't let me with the shown message. I failed to find a proper way how to do it. Is it even possible without explicitely typing all the type parameters like Tuple7[String,String...,String] and is it even a good idea to use Scala like this ?
def store(record:Tuple7): Unit = {
}
Error:(25, 20) class Tuple7 takes type parameters
def store(record: Tuple7): Unit = {
^
As stated by Luis you have to define what Type goes on which position for every position in the Tuple.
I`d like to add some approaches to express the same behaviour in different ways:
Tuple Syntax
For that you have two choices, what syntax to use to do so:
Tuple3[String, Int, Double]
(String, Int, Double)
Approach using Case Classes for better readability
Long tuples are hard to handle, especially when types are repeated. Scala offers a different approach for handling this. Instead of a Tuple7 you can use a case class with seven fields. The gain in this approach would be that you now can attach speaking names to each field and also the typing of each position makes more sense if a name is attached to it.
And the chance of putting values in wrong positions is reduced
(String, Int, String, Int)
// vs
case class(name: String, age: Int, taxNumber: String, numberOfChildren: Int)
using Seq with pattern matching
If your intention was to have a sequence of data seq in combination with pattern matching could also be a nice fit:
List("name", 24, "", 5 ) match {
case name:String :: age:Int ::_ :: _ :: Nil => doSomething(name, age)
}
This only works nice in a quite reduced scope. Normally you would lose a lot of type information as the List is of type Any.
You could do the following :
def store(record: (String, String, String, String, String, String, String)):Unit = {
}
which is the equivalent of :
def store(record: Tuple7[String, String, String, String, String, String, String]):Unit = {
}
You can read more about it in Programming in Scala, 2nd Edition, chapter "Next Steps in Scala", sub-chapter "Step 9. use Tuples".