[GAP] New feature: Multiple argument lambda functions

Max Horn Max.Horn at math.uni-giessen.de
Mon Jan 16 09:39:48 GMT 2017


Dear all,

some of us have been discussing about extending GAP's support for lambda functions. Right now, we allow

  x -> x + 1

as a shorthand for

  function(x) return x + 1; end

Some of us think that it would be very convenient to have a similar shorthand for lambdas with multiple arguments, which leads to the initial feature request two years ago at <https://github.com/gap-system/gap/issues/37>.

Subsequently, Chris Jefferson implemented it (code and further discussion at  <https://github.com/gap-system/gap/pull/490>), and we plan to merge it soon. With this email, I wanted to make sure everybody knows about it before the merge, and also to give a last chance to everybody to comment (but please first read the extensive discussion on the issue and the pull request I linked to). The new syntax is planned to be like this:

  {x,y} -> x + y + 1

as a shorthand for

  function(x,y) return x + y + 1; end

Note that we cannot use (x,y)->x+y+1 (at least not without serious complications), as this clashes with the syntax for permutations (again, see the discussion on the issue & PR). The current syntax was selected based on an informal poll at <http://doodle.com/poll/8tty9qg68tz9stc7>.

The old syntax for lambda will of course stay, but you can also use the new syntax for function with 1 and 0 arguments, i.e.:

  {x} -> x + 1
  {} -> 42          # constant function

This also mans that the informal and undocumented syntax extension in HPC-GAP for zero-arg lambdas, which is

    -> 42

could be removed again, using the new multi-arg lambda syntax instead. I'd be strongly in favor for it (I don't think much code uses it, and adapting such code to the new syntax should be straight forward).

Cheers,
Max
-- 
Prof. Dr. Max Horn
AG Algebra
Mathematisches Institut
Justus-Liebig-Universität Gießen
Arndtstraße 2
D-35392 Gießen
Tel: (+49) 641 99-32044
Fax: (+49) 641 99-32049
E-Mail: max.horn at math.uni-giessen.de




More information about the Gap mailing list