Re: Function naming: Problems and proposed solution

> (A simpler baby step, while I think about it, is to allow
> sort(//employee, , function($e){$e/salary}) - that is, leaving out an
argument is the same
> as supplying an empty sequence. We made this change for the content of
curly braces, so it's not a big deal.)

This could work, but we can soon end up with:

my:myFn(arg1,,,,,,,,,,arg10)

or even worse:

my:myFn(arg1,,,,, arg5 ,,,,,arg10)

Thanks,
Dimitre

On Sat, Nov 28, 2020 at 3:52 PM Michael Kay <mike@saxonica.com> wrote:

>
> But this is ugly and may break existing code that was supplying e.g. a
> sequence of arrays & sometimes only one array in the sequence.
>
>
> So, we could add fn:without() designed to work that way, and deprecate
> remove(), maybe?
>
>
> If we allow unqualified function names to be used for multiple namespaces
> (like fn, array, and map), then we could certainly try to solve the
> conflicts like put() and remove() by renaming some of the functions, but
> this doesn't really solve the underlying problem.
>
> Basically, unless we can find some way of binding functions based on the
> type of the arguments, we're going to end up with qualified names of some
> kind, and whether it's map:remove(), map.remove(), or remove-from-map(), we
> can't just call it remove() if there are other functions using that name.
> Using an artful synonym doesn't help the user recognise what the function
> does from its name (which is how we started this thread, with Dimitre
> observing that the two names "replace" and "replace-with" give you no hints
> as to how the functions differ.).
>
> Which actually suggests another way forward, namely keyword-based calls:
>
> sort(//employee, by: function($e){$e/salary})
>
> where "by" is the name of the third argument, somehow causing this to be
> interpreted as a call on sort#3 with () as the value of the second
> argument. This would then allow the approach of providing replace-with as
> replace#5, invoked say as replace($str, $regex, apply: upper-case#1).
>
> and similarly calls on map:remove and fn:remove could be resolved by use
> of different keywords.
>
> But the details to make this work are likely to be very tricky, and it's a
> potential source of a lot more complexity.
>
> (A simpler baby step, while I think about it, is to allow sort(//employee,
> , function($e){$e/salary}) - that is, leaving out an argument is the same
> as supplying an empty sequence. We made this change for the content of
> curly braces, so it's not a big deal.)
>
> Michael Kay
> Saxonica
>
>

-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they write
all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.

Received on Sunday, 29 November 2020 00:06:04 UTC