Why can't I call Nim proc without braces? - nim-lang

Nim support proc calling expression without braces, but when I use named arguments it complains, why?
proc doc(text: string) {.discardable.} = echo text
doc "doc1"
doc(text = "doc1")
doc text = "doc1" # <== Error here

The complain is Error: undeclared identifier: 'text', because you're calling the doc proc with a value that is undeclared. This works:
proc doc(text: string) = echo text
let text = "doc1"
doc text
The line doc text = "doc1" tells the program to 1) call the procedure doc with the variable text as first argument and 2) assign "doc1" to whatever that procedure returned. And so you'll find the error Error: 'doc text' cannot be assigned to.

Related

Syntax Error Assigning Function Output To Postgres Variable

I'm trying to write a migration that generate a 'sort name' for each name in a table, where the sort name is identical to the regular name except that ' is replaced with a single space, the name is converted to lowercase and the last word in the name is moved to the front. E.g "John L'Mann" becomes "Mann John L". I have written a temporary function in order to do this:
CREATE FUNCTION generate_sort_name(name text) RETURNS text AS $$
DECLARE
without_quotes text;
split_name text[];
all_but_surname text;
BEGIN
without_quotes := (regexp_replace(name, '\''', 'g'));
split_name := (regexp_split_to_array(lower(without_quotes), '\s+'));
CASE WHEN (length(split_name) = 1) THEN RETURN split_name[1];
ELSE
all_but_surname := (array_to_string(split_name[1:length(split_name)-1], ' '));
return split_name[length(split_name)] || ' ' || all_but_surname;
END
END
$$ LANGUAGE plpgsql;
EDIT: Thank you for the information, I have corrected the lack of semicolons and the double quotes. Now getting syntax error at or near 'END' - I've tried with semicolons following either or both and with and without one at the end of the last 'return' line.

Mongodb text search not working with string Flask

I am trying to make text search with Flask.
For one word it works, but when I pass a string with multiple words it doesn't work.
But when I pass that string as hardcoded it works:
Suppose that string is this:
str = "SOME TEXT HERE"
if I pass it as variable like this:
newText= ' '.join(r'\"'+word+r'\"' for word in str.split())
result = app.data.driver.db[endpoint].find({"$text":{"$search":newText }}, {"score": {"$meta":"textScore"}}).sort([("score", {"$meta": "textScore"})])
it doesn't work.
But if I pass it as hardcoded like this:
result = app.data.driver.db[endpoint].find({"$text":{"$search":" \"SOME\" \"TEXT\" \"HERE\" " }}, {"score": {"$meta":"textScore"}}).sort([("score", {"$meta": "textScore"})])
It works.
The contents of variable newText are different from the contents in your hardcoded string.
Try removing 'r' during creation of newText to generate a string similar to the hardcoded string, as follows:
newText= ' '.join('\"'+word+'\"' for word in str.split())

error with string variable

I'm trying to use a string variable as input to an xml function. When I use this command:
name2_node(i).setTextContent('truck');
there is no error. But when I replace it with:
name2_node(i).setTextContent(type(i,1));
an error occurs like this:
No method 'setTextContent' with matching signature found for class
'org.apache.xerces.dom.ElementImpl'.
The variable type is a string array. In fact when I type type(i,1) in command window the result is:
ans =
string
"truck"
What part am I doing wrong?
Two things:
use a different variable name, type is a built in function which tells you the variable type, hence why it shows "string" in the output.
Then access the cell array of strings with curly braces
vehicletypes = {'car'; 'truck'; 'van'};
name2_node(i).setTextContent(vehicletypes{i,1}); % For i=2, this passes 'truck'

Register Excel UDF without arguments

I has many user define function with arguments and without. I use CUdfHelper from this article http://www.jkp-ads.com/articles/RegisterUDF00.asp for register function.
Registered function ask arguments for arguments, even if they are not.
Example my fuction without arguments:
Public Function getProjects()
getProjects = Utils.execute("getProjects", "getWSEntitiesData")
End Function
On MyFunction.c
#include <windows.h>
#define DLL_EXPORT __declspec(dllexport)
DLL_EXPORT void getProjects() {
return;
}
compile on MyFunction.dll
I register the function with these parameters.
SetGlobalName = Application.ExecuteExcel4Macro("MyFunction.dll", "getProjets", "P", "getProjects", "", 1, "MyFunctionCategory", "", "", "Return list projects")
If I register as
SetGlobalName = Application.ExecuteExcel4Macro("MyFunction.dll", "getProjets", "P", "getProjects",, 1, "MyFunctionCategory", "", "", "Return list projects")
Function argument dialog is displayed all the same.
If I register as
SetGlobalName = Application.ExecuteExcel4Macro("MyFunction.dll", "getProjets", "P", "getProjects",, 1, "MyFunctionCategory")
Function argument dialog isn't displayed, but the description is no longer available.
REGISTER() Arguments
Path and name of the dll
Name of the function you wish to call
Type string
The name you want to use in Excel cells
A list of arguments to use in the function wizard
The Macro type (2 for a function, 2 for a command)
Which function wizard category to add the function to
Short cut text if the function being registered is a command
Path to help file
Function help to show in the function wizard
11-30 onwards help text for each argument in the function wizard.
I think the problem is in the arguments, as by default it is set to an empty string, and I can not figure out how to change the parameters to the function.
On CUdfHelper
' structure definition
Private Type REGARG
sDllName As String
sDllProc As String
sArgType As String
sFunText As String
**sArgText As String**
iMacType As Integer
vCatName As Variant
sKeyText As String
sHlpPath As String
**sFunHelp As String**
aArgHelp(1 To 20) As String
End Type
How to correctly set the parameters so that the window does not appear, and stores the description?
If register function with ExecuteExcel4Macro and set Function Description. In an XLL add-in, however, you may run into a bug in the Excel API. The bug shows itself if a parameterless function is mentioned in an ADXExcelFunctionDescriptor that has a non-empty string in the Description property. If this is the case, you'll get another version of the Function Arguments dialog.
That is, to bypass that issue, you need to leave the ADXExcelFunctionDescriptor.Description property empty.
Find on https://www.add-in-express.com/docs/net-excel-udf-tips.php

Convert String type value to a object type VBS

I need to pass an object type value to a procedures, which read from a text file (String fromat).
'param node- Object type
'param txtvalue - String
Function setTexttoElement(nodename, txtvalue)
nodename.Text = txtvalue
End Function
Method is finely works when passing following values
setTexttoElement myElement, abc
But when reading a file it's take String format. So I need to convert first value as Object
"myElement", "abc"
How to solve this?
You will need to create a reference dictionary to convert the text string to an object effectively, as there is no way for vbscript to know what type of object you are passing to the function. For more information: click here.

Resources