isSubstring method in ML - sml

fun appear(x:string,y:string)=
if String.isSubstring x y then print("APPEAR ") else print("NOT APPEAR ");
appear("abc","asabcbc");
I wrote this function and compiled in Moskow ML.But there is an error like this:
! Unbound value component: String.isSubstring

You are probably using an outdated version of Moscow ML. Try version 2.10 or later, which has String.isSubstring.

Related

All thinkscript Stock Fundamentals API returning NaN?

I'm working on a simple label overlay for thinkorswim's charting software using thinkscript.
I'm noticing that all of the "Fundamental" API calls I make return NaN. Those "stock fundamental" API calls are documented here: https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Stock-Fundamentals
Here's my usage for the API call 'OperatingProfitMargin':
def opm = if IsNaN(OperatingProfitMargin()) then 123 else OperatingProfitMargin();
AddLabel(yes, "Op PM: " + opm, Color.White);
My label is rendered with '123', which suggests to me that the API is returning something that is NaN.
I've been unsuccessful finding example usages of these functions on the official documentation, you tube, or on stack overflow.
I assume I'm misusing the API, in that it's returning some sort of object or tuple with which I should be post-processing/de-structuring in some way.
Has anyone had success using these "Stock Fundamentals" API calls?
Try it this way:
def opm = if IsNaN(OperatingProfitMargin()) then opm[1] else OperatingProfitMargin();
AddLabel(yes, "Op PM: " + opm, Color.WHITE);

I would like to get 1.68 instead of 1.679999999 as I data-import from access db in MFC, C++

Hello :) I would like to import the data I marked as red.
after connecting my program to DB,
I executed this line
m_strE37 = m_command.GetString(37);
but unfortunately, m_strE37 stores "1.6799999999999"
their class is as follows
CString m_strE37;
typedef CCommand<CDynamicsStringAccessorW,CRowset> DbCommand;
DbCommand m_command;'
I Selected that record(row) and tried to get the value by using GetString(37) since it is 37th column.
I was quite new to this DB Process.
Can anyone help me to correctly get 1.68 ??
Thank you a lot in advance!
Try this snippet:
float f = atof(m_strE37);
m_strE37.Format("%3.2f",f);
For unicode :
float f = atof(CStringA(m_strE370.GetString()));
m_strE37.Format(L"%3.2f",f);

How can i use asterisk(*) in command line arguments in groovy?

Helo!
I've a groovy script with one argument. The argument has to be a regex pattern. I want to use an * in the argument, but always got: The syntax of the command is incorrect.
This is an example (opt.p is the pattern getting from the arg):
def map1 = [e:'pine___apple', f:'pineapple']
map1.each { entry ->
entry.value.find(~/$opt.p/) { match -> println entry.value}
}
I want to use the script from the command line in this way:
groovy test -p pine_*a
And I expect that the result will be:
pine___apple
pineapple
I tried these solutions and more, but nothing works:
pine_*a
"pine_*a"
'pine_*a'
pine_\*a
'pine_\*a'
"pine_\*a"
pine_'\*'a
pine_"\*"a
pine_'\\*'a
pine_"\\*"a
Somebody knows how to solve this problem?
Thanks a lot!
EDIT:
I use:
Groovy Version: 2.4.6 JVM: 1.7.0_45 Vendor: Oracle Corporation OS: Windows 7 And I also use CliBuilder:
def cli = new CliBuilder()
cli.with
{
p('pattern', args: 1, required: false)
}
def opt = cli.parse(args)
The following groovy script:
def map = [e:'pine___apple', f:'pineapple']
map.each { k, v ->
v.find(~/${args[0]}/) { println "key: $k, value: $v -> ${v.find(args[0])}" }
}
prints the following on invocation:
$ groovy test.groovy pine_*a
Checking key: e, value: pine___apple -> pine___a
Checking key: f, value: pineapple -> pinea
or to exclude one of the map entries:
$ groovy test.groovy "pine_{1,9}a"
key: e, value: pine___apple -> pine___a
Not sure what the issue with your script is. Maybe the handling of opts.p like one of the comments suggests.
edit 1:
an alternative CliBuilder syntax to the one mentioned by Tim Yates in his answer:
def opt = new CliBuilder().with {
p longOpt: 'pattern', args: 1
parse(args)
}
edit 2: solution
as this is marked as the accepted answer, I will add what ended up being the solution here (I have a comment on this below, but comments are not immediately obvious when browsing for the solution).
This issue was caused by a bug in the windows groovy distribution startgroovy.bat file (see separate stackoverflow thread) which is used to launch groovy. The problem is with windows execution and parameter handling and it occurs before the groovy program even starts executing. There is a fair chance this has been fixed in later versions of groovy so it might be worth a try to upgrade to the latest version. If not, the answer in the above thread should make it possible to fix startgroovy.bat.
Think it's the way you're capturing your opt
I assume you're using the CliBuilder
And I suspect you've missed the args: 1 from the definition of the p parameter
def opt = new CliBuilder().with {
it.p('pattern', args: 1)
parse(args)
}
def map1 = [e:'pine___apple', f:'pineapple']
map1.each { entry ->
entry.value.find(~/$opt.p/) { match -> println entry.value}
}
Works as you describe it should for me...

Generating template with some logic via HStringTemplate

Here is some invalid HStringTemplate syntax:
option_a = $options.a$
option_b = $options.b$
$if options.option_c_is_needed$
option_c = $option.c$
$end$
In other words, part of template file should be created only if specific predicate is true. How can it be achieved via HStringTemplate? If there is no way to do that in it, what libraries could be helpful here?
May be there is some analog of erubis mechanism with ability to use haskell code inside template files?
Hammar's comment is correct. See below:
*Main Text.StringTemplate> render $ setAttribute "optSet" False $ (newSTMP "OptSet: $if(optSet)$Option Is Set$else$Option Isn't Set$endif$" :: StringTemplate String)
"OptSet: Option Isn't Set"
*Main Text.StringTemplate> render $ setAttribute "optSet" True $ (newSTMP "OptSet: $if(optSet)$Option Is Set$else$Option Isn't Set$endif$" :: StringTemplate String)
"OptSet: Option Is Set"

Suppress "val it" output in Standard ML

I'm writing a "script" in Standard ML (SML/NJ) that sets up the interactive environment to my liking. The last thing the script does is print out a message indicating everything went smoothly. Essentially, the last line is this:
print "SML is ready.\n";
When I run the script, all goes well but the SML interpreter displays the return value from the print function.
SML is ready.
val it = () : unit
-
Since I'm merely printing something to the screen, how can I suppress the "val it = () : unit" output so that all I see is the "SML is ready" message followed by the interpreter prompt?
To surpress the SML-NJ prompt and response, use the following assignment.
Compiler.Control.Print.out := {say=fn _=>(), flush=fn()=>()};
print "I don't show my type";
I don't show my type
although I don't see why the print function returning the type is bad.
The say function controls what is printed out.
There is a larger example in the following SML/NJ notes http://www.cs.cornell.edu/riccardo/prog-smlnj/notes-011001.pdf
The useSilently function can be used to load a file but without displaying any output
associated with the loading
fun useSilently (s) = let
val saved = !Compiler.Control.Print.out
fun done () = Compiler.Control.Print.out := saved
in
Compiler.Control.Print.out := {say = fn _ => (), flush = fn () => ()}
(use (s); done ()) handle _ => done ()
end
This is essentially changing the say function to do nothing and then setting it back at the end.
Use this:
val _ = print "I don't show my type";
In Moscow ML you can run the REPL without declaration output with
mosml -quietdec file.sml