I tried to convert my OptaPlanner code from Java to Grails. Everything else is fine except I'm stuck when I changed the Planning Entity class into a Groovy file. Then Error message with this would show:
startup failed: F:\Users\Administrator\Documents\workspace-ggts-3.2.0.RELEASE\spa\src\groovy\optaplanner\domain\AllocationEntity.groovy: 15: Annotation list attributes must use Groovy notation [el1, el2] in #org.optaplanner.core.api.domain.variable.PlanningVariable # line 15, column 48. able(valueRangeProviderRefs = {"projects ^ 1 error
And my Intellij IDEA also would prompt an error message when I hover over the line #PlanningVariable(valueRangeProviderRefs = {"projectsRange"}) with red warning highlight under {"projectsRange"}, and the error message is this:
Cannot assign 'Class' to 'String[]'
I wish to use Groovy instead of Java for the GORM feature to query database. But how can I fix this error so I can use the Planning Entity as a Groovy class?
Most Java code is valid Groovy code, but there are a few exceptions, mostly when dealing with curly braces. Closures are defined in Groovy as a code block inside of curly braces, e.g.
def foo = {
...
}
so other uses of curly braces will confuse the Groovy parser. In most cases you just use regular braces instead. In this case your annotation list should be
#PlanningVariable(valueRangeProviderRefs = ["projectsRange"])
Related
I want to modify the definition of a Nix derivation (emacs macport). I wish to change the configureFlag value and "--with-mac-metal" to it.
I have tried the following with no luck:
emacsMacport.overrideDerivation
(old: {
configureFlags = [
"LDFLAGS=-L${ncurses.out}/lib"
"--with-xml2=yes"
"--with-gnutls=yes"
"--with-mac"
"--with-modules"
"--enable-mac-app=$$out/Applications"
"--with-mac-metal"
];
})
I am using home-manager and nix-darwin, and I get the following exception:
error: A definition for option `home-manager.users.ashk.home.packages.[definition 16-entry 3]' is not of type `package'. Definition values:
- In `/nix/store/mkcwa9i9brbxf81a01whhy53yzk87c9d-source/modules/hosts/zebra/home.nix': <function>
(use '--show-trace' to show detailed location information)
You need to parenthesize function applications when they're in a list literal.
It's weird.
You'll probably never get used to this, judging from my own experience using Nix extensively for years.
In Bazel, is it possible to use simple functions and variables as input to a load statement?
For example:
my_workspace = "a" + "b"
load(my_workspace, "foo")
load(my_workspace, "bar")
WARNING: Target pattern parsing failed.
ERROR: error loading package 'loadtest/simple': malformed load statements
The exact error message might have changed with version, I'd see:
syntax error at 'my_workspace': expected string literal
but no, you cannot use anything but string literal as per docs:
Use the load statement to import a symbol from an extension.
...
Arguments must be string literals (no variable)...
I am new to F#/.NET and I am trying to run the F# example provided in the accepted answer of How to translate the intro ML.Net demo to F#? with the ML.NET library, using F# on Visual Studio, using Microsoft.ML (0.2.0).
When building it I get the error error FS0039: The type 'TextLoader' is not defined.
To avoid this, I added the line
open Microsoft.ML.Data
to the source.
Then, however, the line
pipeline.Add(new TextLoader<IrisData>(dataPath,separator = ","))
triggers:
error FS0033: The non-generic type 'Microsoft.ML.Data.TextLoader' does not expect any type arguments, but here is given 1 type argument(s)
Changing to:
pipeline.Add(new TextLoader(dataPath,separator = ","))
yields:
error FS0495: The object constructor 'TextLoader' has no argument or settable return property 'separator'. The required signature is TextLoader(filePath: string) : TextLoader.
Changing to:
pipeline.Add(new TextLoader(dataPath))
makes the build successful, but the code fails when running with
ArgumentOutOfRangeException: Column #1 not found in the dataset (it only has 1 columns), I assume because the comma separator is not correctly picked up (incidentally, you can find and inspect the iris dataset at https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data).
Also
pipeline.Add(new TextLoader(dataPath).CreateFrom<IrisData>(separator: ','))
won't work.
I understand that there have been changes in TextLoader recently (see e.g. https://github.com/dotnet/machinelearning/issues/332), can somebody point me to what I am doing wrong?
F# just has a bit of a different syntax that can take some getting used to. It doesn't use the new keyword to instantiate a new class and to use named parameters it uses the = instead of : that you would in C#.
So for this line in C#:
pipeline.Add(new TextLoader(dataPath).CreateFrom<IrisData>(separator: ','))
It would be this in F#:
pipeline.Add(TextLoader(dataPath).CreateFrom<IrisData>(separator=','))
In a GSP file I write something like this:
${tgs.singleGameSheets.find{it.matchnumber==1}.awayPlayer.fullname()}
But I receive the following error:
org.codehaus.groovy.control.MultipleCompilationErrorsException:
startup failed:
C__STS_Projekte_TischtennisManager_grails_app_views_league__showGameSheet_gsp:
49:expecting '}', found ')' # line 49, column 134.
heets.find{it.matchnumber==1 })
The problem seems to be the double closure as I've found a bug report here.
Unfortunately the solution from the bugreport with the %= and % at the beginning and the end of the tag is not working for me.
Are there any other workarounds or solutions for this double closure problem?
I'm using Grails 1.3.7.
You may have to split this up in to two lines.
Try assigning the find results to a separate var first
<% def r = tgs.singleGameSheets.find{it.matchnumber==1} %>
${r*.awayPlayer.fullname()}
I would recommend firstly to do this sort of data processing in the controller and hand data that is as well prepared as possible down to the view.
If you are unable to do that, I would recommend trying to use parenthesis:
${tgs.singleGameSheets.find{it.matchnumber==1}.awayPlayer.fullname()}
becomes
${(tgs.singleGameSheets.find{it.matchnumber==1}.awayPlayer.fullname())}
That has worked for me on past occasions where I had to do ${(someCollection.findAll { someClause })}
I am using Apache commons cli (1.2) for command line parsing.
I have the following in my code:
import org.apache.commons.cli.OptionBuilder
OptionBuilder.withLongOpt("db-host").hasArg.
withDescription("Name of the database host").create('h')
I get the error hasArg is not a member of org.apache.commons.cli.OptionBuilder. It makes no difference if I change .hasArg to .hasArg().
Why?
BTW, Java parses this fine.
import org.apache.commons.cli.OptionBuilder
OptionBuilder.withLongOpt("db-host").hasArg.
withDescription("Name of the database host").create('h')
I get the error hasArg is not a member of org.apache.commons.cli.OptionBuilder. It makes no difference if I change .hasArg to .hasArg().
Why?
Because there is no instance method hasArg in OptionBuilder, only a static method. Since hasArg is a static method, you obviously need to call it on the class, not on an instance of the class.
BTW, Java parses this fine.
I don't understand what this has to do with parsing. Scala parses this just fine, too. Plus, what some completely different programming does or doesn't do with this code is utterly irrelevant, since this is Scala code, not some other language.
You need to do something like this:
import org.apache.commons.cli.OptionBuilder
OptionBuilder.withLongOpt("db-host")
OptionBuilder.hasArg
OptionBuilder.withDescription("Name of the database host")
val optionParser = OptionBuilder.create('h')