* Is it possible to "nest" functions
- BillH
- Megastar
- Posts: 2245
- Joined: 31 May 2010 03:40
- Family Historian: V7
- Location: Washington State, USA
Is it possible to "nest" functions
Is it possible to "nest" one function inside of another? For example:
<bound for =TextPart({=GetLabelledText(%FACT.NOTE2%,"To: "}), 1, 0, TIDY)>
I can't get this to work and haven't been able to find anything on "nesting" in the help or KB.
Thanks,
<bound for =TextPart({=GetLabelledText(%FACT.NOTE2%,"To: "}), 1, 0, TIDY)>
I can't get this to work and haven't been able to find anything on "nesting" in the help or KB.
Thanks,
Re: Is it possible to "nest" functions
Bill,
I don't know the answer, as I'm not proficient in LUA, but don't see why not, most languages do. However, I do see your brackets are 'unbalanced', and have become mxed!
You have ( { ( on left but } ) ) on right!
Have a rethink, and re-position them.
I don't know the answer, as I'm not proficient in LUA, but don't see why not, most languages do. However, I do see your brackets are 'unbalanced', and have become mxed!
You have ( { ( on left but } ) ) on right!
Have a rethink, and re-position them.
Mike Loney
Website http://www.loney.tribalpages.com
http://www.mickloney.tribalpages.com
Website http://www.loney.tribalpages.com
http://www.mickloney.tribalpages.com
- Jane
- Site Admin
- Posts: 8508
- Joined: 01 Nov 2002 15:00
- Family Historian: V7
- Location: Somerset, England
- Contact:
Re: Is it possible to "nest" functions
You need to wrap the complete function in the {} brackets not leave them in the middle.
Jane
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."
Re: Is it possible to "nest" functions
Jane,
To clarify, do you mean the order of the brackets should be { ( ( on left and ) ) } on right?
To clarify, do you mean the order of the brackets should be { ( ( on left and ) ) } on right?
Mike Loney
Website http://www.loney.tribalpages.com
http://www.mickloney.tribalpages.com
Website http://www.loney.tribalpages.com
http://www.mickloney.tribalpages.com
- Jane
- Site Admin
- Posts: 8508
- Joined: 01 Nov 2002 15:00
- Family Historian: V7
- Location: Somerset, England
- Contact:
Re: Is it possible to "nest" functions
Yes, as per the Advanced Help accessed from the Fact Type Fact Definition all functions and data references are wrapped in curly brackets, the function enclosed is exactly the same as what are valid in a query with the exception of the extended data references.
Jane
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."
Re: Is it possible to "nest" functions
Jane,Jane wrote:Yes, as per the Advanced Help accessed from the Fact Type Fact Definition.
I'm a bit slow this morning, but how exactly do we access the above? I've searched help using keywords, but can't find what you are referring to!
Mike Loney
Website http://www.loney.tribalpages.com
http://www.mickloney.tribalpages.com
Website http://www.loney.tribalpages.com
http://www.mickloney.tribalpages.com
- Jane
- Site Admin
- Posts: 8508
- Joined: 01 Nov 2002 15:00
- Family Historian: V7
- Location: Somerset, England
- Contact:
Re: Is it possible to "nest" functions
Jane
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."
- SimonOrde
- Program Designer
- Posts: 352
- Joined: 18 Nov 2002 10:20
- Family Historian: V7
- Location: Calico Pie
Re: Is it possible to "nest" functions
Hi Bill
the short answer is Yes - functions can be nested within one another. There is no limit to the number of levels that you can nest them either. When you call one function as a 'parameter' to another function, you must make sure that the type of value returned by the first function matches the parameter type required by the second.
In general, in a context in which you can use a function, the presence of a function is signalled by an equal sign (=) as in MS Excel. So, for example, in a Query, you put an = in front of a call to a function. Do not put an equal sign in front of any nested functions though.
Functions can be used in sentence templates for narrative reports (as in your example). But when you use a function in these contexts, you must wrap the whole expression in a pair of curly brackets (and then have an '=' sign immediately after the first curly bracket). For example:
In this example, the outer bit
signals a function being used in a sentence template. Within that, the outermost function is RecordId(), which calls another function GetRecord(), which takes the data reference %FACT% as its sole parameter.
Remember you only need or use curly brackets round functions (or function expressions perhaps I should say), in sentence templates. You don't use the curly brackets elsewhere.
Here's another example of a nested call to a function without curly brackets (e.g. for use in a query):
This expression will calculate the difference in age between a person and their spouse. The outermost function is 'Diff' which takes two parameters. There are two nested calls to the 'Year' function (each of which is passed a data reference referring to a date, as parameter).
Incidentally, as well as calling nested functions, you can also combine them using operators. These can be logical operators (such as 'and', 'or', 'not'), or they can be numeric operators (such as '+', '-', etc). Operators are explained in the Help in the Advanced Topics area. Here's an example of a function call that uses the minus sign (the subtraction operator):
This is very similar to the previous example. The only difference between the two is that 'Diff' always returns a positive value, whereas 'Calc' will also return negative values.
You can only use operators in the context of a function expression. So if you have two functions and you simply want to put an operator between them, you may need a function like 'Calc' to provide a context for the operator to 'sit' in. The function 'IsTrue' provides a similar role for logical operators.
The only thing with using functions and operators is that it's very easy to make a mistake and fail to match up parameter types and return types etc. They're not very forgiving. If you are trying to put together a very complex expression, I recommend building it up in stages and testing each part if you can.
Hope that makes sense.
Simon
the short answer is Yes - functions can be nested within one another. There is no limit to the number of levels that you can nest them either. When you call one function as a 'parameter' to another function, you must make sure that the type of value returned by the first function matches the parameter type required by the second.
In general, in a context in which you can use a function, the presence of a function is signalled by an equal sign (=) as in MS Excel. So, for example, in a Query, you put an = in front of a call to a function. Do not put an equal sign in front of any nested functions though.
Functions can be used in sentence templates for narrative reports (as in your example). But when you use a function in these contexts, you must wrap the whole expression in a pair of curly brackets (and then have an '=' sign immediately after the first curly bracket). For example:
Code: Select all
{=RecordId(GetRecord(%FACT%))}
Code: Select all
{= ... }
signals a function being used in a sentence template. Within that, the outermost function is RecordId(), which calls another function GetRecord(), which takes the data reference %FACT% as its sole parameter.
Remember you only need or use curly brackets round functions (or function expressions perhaps I should say), in sentence templates. You don't use the curly brackets elsewhere.
Here's another example of a nested call to a function without curly brackets (e.g. for use in a query):
Code: Select all
=Diff(Year(%INDI.BIRT.DATE%),Year(%INDI.~SPOU>BIRT.DATE%))
Incidentally, as well as calling nested functions, you can also combine them using operators. These can be logical operators (such as 'and', 'or', 'not'), or they can be numeric operators (such as '+', '-', etc). Operators are explained in the Help in the Advanced Topics area. Here's an example of a function call that uses the minus sign (the subtraction operator):
Code: Select all
=Calc(Year(%INDI.BIRT.DATE%) - Year(%IND.~SPOU.BIRT.DATE%))
You can only use operators in the context of a function expression. So if you have two functions and you simply want to put an operator between them, you may need a function like 'Calc' to provide a context for the operator to 'sit' in. The function 'IsTrue' provides a similar role for logical operators.
The only thing with using functions and operators is that it's very easy to make a mistake and fail to match up parameter types and return types etc. They're not very forgiving. If you are trying to put together a very complex expression, I recommend building it up in stages and testing each part if you can.
Hope that makes sense.
Simon
Re: Is it possible to "nest" functions
Jane,
Many Thanks.
I was nearly there, I went to Fact Types, but then went to new..., rather than selecting a type then clicking Edit...
Many Thanks.
I was nearly there, I went to Fact Types, but then went to new..., rather than selecting a type then clicking Edit...
Mike Loney
Website http://www.loney.tribalpages.com
http://www.mickloney.tribalpages.com
Website http://www.loney.tribalpages.com
http://www.mickloney.tribalpages.com
- tatewise
- Megastar
- Posts: 28342
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Is it possible to "nest" functions
That is all covered with examples in how_to:understanding_expressions|> Understanding Expressions where it says:
Functions that begin with an = sign (except when used within another Function) and lots of nested examples.
Functions that begin with an = sign (except when used within another Function) and lots of nested examples.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
- BillH
- Megastar
- Posts: 2245
- Joined: 31 May 2010 03:40
- Family Historian: V7
- Location: Washington State, USA
Re: Is it possible to "nest" functions
Mike, Jane, Simon, and Mike,
Thanks to all for your replies. They were all very helpful.
This was for use in a sentence template, so I did need the curly brackets, but I see as Mike pointed out that I do have mis-matched brackets. Last night I did try at least 20 other combinations and couldn't get it to work. I guess it was getting late last night and I was trying anything.
This morning after reading the messages, I matched up the brackets and put the curly brackets on the outside of the whole thing, but it still didn't work. Then I figured it out. I had too many = symbols.
<bound for {=TextPart(=GetLabelledText(%FACT.NOTE2%,"To: "), 1, 0, TIDY)}>
removing the = in front of GetLabelledText did the trick.
<bound for {=TextPart(GetLabelledText(%FACT.NOTE2%,"To: "), 1, 0, TIDY)}>
I figured the info was in the help or knowledge base somewhere, but I swear I looked for at least a 1/2 hour and couldn't find it by searching.
Thanks everyone for their help!
Thanks to all for your replies. They were all very helpful.
This was for use in a sentence template, so I did need the curly brackets, but I see as Mike pointed out that I do have mis-matched brackets. Last night I did try at least 20 other combinations and couldn't get it to work. I guess it was getting late last night and I was trying anything.
This morning after reading the messages, I matched up the brackets and put the curly brackets on the outside of the whole thing, but it still didn't work. Then I figured it out. I had too many = symbols.
<bound for {=TextPart(=GetLabelledText(%FACT.NOTE2%,"To: "), 1, 0, TIDY)}>
removing the = in front of GetLabelledText did the trick.
<bound for {=TextPart(GetLabelledText(%FACT.NOTE2%,"To: "), 1, 0, TIDY)}>
I figured the info was in the help or knowledge base somewhere, but I swear I looked for at least a 1/2 hour and couldn't find it by searching.
Thanks everyone for their help!
-
- Silver
- Posts: 6
- Joined: 26 Jan 2017 09:12
- Family Historian: V6
Re: Is it possible to "nest" functions
To everyone who asked and answered above,
Thank you all. I now have a query that shows the individuals who appear in the 1881 census, and their ages at the time. Just what I wanted, and I was able to find the ages thanks to the advice given here.
Thank you all. I now have a query that shows the individuals who appear in the 1881 census, and their ages at the time. Just what I wanted, and I was able to find the ages thanks to the advice given here.