There are several confusion in your example. You tried to use the "metrics syntax" (if I can called it this way) in a wrong way. When defining a "metric" function the input should be some attributes of a LAS object. It is hard to me to evaluate which part of the documentation you misunderstood so below a workable example. Do not hesitate to ask for more details.
Also you noticed that lasmetrics
can be used in catalog_apply
. This is a special case actually. To give you a full anwseranswer you could have used the following syntax (you were actually close)