Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the idiomatic way of calling a function with many arguments?

In Lisp (any lisp dialect will do) what's the idiomatic way of calling a function with many args?

By many I mean exceeding the 80 character limit.

Say we have an example function called foo-func that takes a variable number of arguments

(foo-func 'foo 'bar 'baz 'qux 'foo-bar 'foo-baz 'foo-qux 'bar-foo 'bar-baz 'you-get-the-idea)

How would one normally arrange the args if not on a long incomprehensible line?

NOTE this is not a question about personal preference, it's about how it's recommended it's done

like image 601
Electric Coffee Avatar asked Mar 18 '23 08:03

Electric Coffee


1 Answers

Usually, it would be aligned like this:

(foo-func 'foo
          'bar
          'baz
          'qux
          'foo-bar
          'foo-baz
          'foo-qux
          'bar-foo
          'bar-baz
          'you-get-the-idea)

In some cases, you might put several arguments that belong together on one line:

(foo-func 'foo
          'bar
          'baz
          'qux
          'foo-bar 'foo-baz 'foo-qux
          'bar-foo 'bar-baz
          'you-get-the-idea)

However, any function that has more than a few arguments would often make heavy use of keyword parameters:

(foo-func 'foo
          'bar
          'baz
          'qux
          :barista 'foo-bar
          :bazaar 'foo-baz
          :quxfrog 'foo-qux
          :baroofa 'bar-foo
          :barazza 'bar-baz
          :say-what 'you-get-the-idea)

Here, you could perhaps put the required parameters on one line:

(foo-func 'foo 'bar 'baz 'qux
          :barista 'foo-bar
          :bazaar 'foo-baz
          :quxfrog 'foo-qux
          :baroofa 'bar-foo
          :barazza 'bar-baz
          :say-what 'you-get-the-idea)
like image 87
Svante Avatar answered Apr 25 '23 14:04

Svante